Back to blog

Monday, June 15, 2026

Gemini-SQL2: Inside Google's State-of-the-Art Text-to-SQL System

cover

The Headline

On June 12, 2026, Google Research announced Gemini-SQL2 — a text-to-SQL system built on Gemini 3.1 Pro that scored 80.04% execution accuracy on the BIRD benchmark. That's 7 percentage points ahead of OpenAI's best effort (GPT-5.5-xhigh at ~72.8%) and 9 ahead of Anthropic's Claude Opus 4.6 at ~70.9%. It's the first system to clear 80% on this leaderboard.

This isn't incremental. The gap between 72% and 80% on BIRD represents crossing a threshold where the system becomes genuinely useful for real-world analytics rather than a demo that works on textbook schemas. This article breaks down how it works, what the benchmark actually measures, and what it means for developers building natural-language database interfaces.

Architecture: Three Stages of Query Generation

While Google hasn't published a formal research paper, the architecture described in their announcement and technical reporting reveals a three-stage pipeline that treats text-to-SQL as a reasoning problem rather than a generation problem.

Stage 1: Schema Linking and Context Assembly

The first stage maps natural language to database structure. This is harder than it sounds. Real-world schemas have ambiguous column names (customer_id vs customer_ref), domain-specific terminology (gross vs net revenue), and business logic that lives outside the schema entirely (what counts as an "active user"?). The system performs schema linking on multiple levels:

  • Structural matching: Maps noun phrases to table and column names, handling synonyms and abbreviations
  • Contextual disambiguation: Resolves ambiguous references by analyzing the query's intent against known column relationships
  • External knowledge injection: Incorporates business context not present in the schema — definitional knowledge that a human analyst would know but isn't encoded in foreign keys or column comments

This stage produces a "schema context packet" that constrains the search space for query generation. The result is a focused representation of which tables, columns, joins, and business rules are relevant.

Stage 2: Multi-Turn Candidate Generation

Rather than generating a single SQL query, Gemini-SQL2 produces 3-5 candidate queries for each natural-language request using an ensemble approach. This is a deliberate architectural choice:

  • Reduces brittleness: Single-shot generation fails when the first interpretation is wrong. Multiple candidates capture different possible interpretations of ambiguous language.
  • Explores join paths: Different queries may use different join strategies, table subsets, or aggregation approaches to reach the same intent.
  • Reasons over domain terminology: The system decodes vague business terms ("monthly churn," "high-value customer") into specific SQL predicates by reasoning over the schema context from Stage 1.

The candidate generator uses Gemini 3.1 Pro's reasoning capabilities to evaluate multiple interpretations before committing to SQL syntax. This isn't a beam search over token probabilities — it's a structured reasoning pass that produces semantically distinct query alternatives.

Stage 3: Repair, Execution, and Selection

This is where Gemini-SQL2 differs most sharply from earlier systems. Each candidate query is:

  1. Executed against a sandbox database with sample data
  2. Validated for execution — the query must actually run without errors
  3. Checked for semantic correctness — row counts, value distributions, and result shapes are compared against expectations
  4. Self-corrected — if results don't match, the system iterates: diagnose the error, adjust the query, re-execute

The repair module handles both syntactic errors (wrong column names, missing joins) and silent semantic errors — queries that run successfully but return incorrect results. Silent errors are the hardest class of failure in text-to-SQL because they look correct to an automated checker but produce wrong answers. Common cases include:

  • Aggregating before joining (correct syntax, wrong numbers)
  • Filtering on the wrong timestamp range
  • Using COUNT when the question implies DISTINCT COUNT

The selection module then picks the best candidate based on execution results and confidence scoring. The output is a single query that has been verified against actual data.

What the BIRD Benchmark Actually Measures

BIRD stands for "BIg Bench for laRge-scale Database" and was designed specifically to address the limitations of earlier text-to-SQL benchmarks like Spider.

Spider's limitation: Measures query execution against perfectly normalized schemas with clean data. Models can benchmaxx — learn to write syntactically valid SQL that looks like the golden query but fails on real-world complexity.

BIRD's methodology: Measures execution accuracy across 95+ real-world databases with dirty values, messy schemas, and questions that require external business knowledge. The metric is execution-verified accuracy: a generated SQL query must not only parse and execute successfully, but must also return results that match the golden query's output. If the query runs without errors but returns different row counts or values, it's counted as wrong.

A score of 80.04% means that roughly 4 out of 5 queries return the correct, executable SQL on the first pass through the system. That remaining ~20% failure rate matters — and we'll get to it in the Pitfalls section.

How Gemini-SQL2 Differs from the Original Gemini-SQL

Google had a previous entry on the BIRD leaderboard simply called "Gemini-SQL" that held the top spot before the new release. The jump from ~77.2% to 80.04% represents meaningful architectural improvements:

DimensionGemini-SQLGemini-SQL2
Base modelGemini 2.xGemini 3.1 Pro
Schema linkingBasic column/table matchingMulti-level (structural + contextual + business knowledge)
Candidate generationSingle queryEnsemble (3-5 candidates)
VerificationSyntax checkingExecution-based with sandbox
Self-correctionLimitedFull loop: execute → validate → repair → re-execute
BIRD score~77.2%80.04%

The 3-point improvement comes primarily from the verification loop and multi-candidate ensemble, not from a better base model alone. This is an important architectural lesson: post-training scaffolding and system-level verification matter as much as the underlying LLM.

Implications for Agent Tool-Use and NL-Database Interfaces

This release has direct consequences for anyone building agents that interact with databases.

The Verification-First Pattern

The architecture validates an approach we've been advocating for agent design: treat the LLM as a proposer, not a decider. Gemini-SQL2's three-stage pipeline follows this pattern:

  1. Propose (generate candidates)
  2. Verify (execute against sandbox)
  3. Select (pick best verified result)

Any agent that generates SQL should follow the same pattern. Without execution verification, you're flying blind — your agent will confidently present wrong numbers.

The Sandbox Requirement

You cannot run verification against production data safely. Gemini-SQL2's approach requires a sandbox with representative sample data. For developers building their own text-to-SQL agents, this means:

  • Maintain a read-only replica or sampled dataset for verification
  • Use EXPLAIN ANALYZE and row-count comparisons as cheap verification signals
  • Never grant write access — not even for correction queries

Schema Context is the New Prompt Engineering

For earlier text-to-SQL systems, the bottleneck was the model's SQL knowledge. For Gemini-SQL2, the bottleneck has shifted to schema context quality. If you're integrating a similar system into your stack, invest in:

  • Rich column comments and descriptions in your database
  • Explicit foreign key documentation
  • Business logic documentation that defines domain terms
  • Testing your schema context against edge-case queries

Future Integration Path

Google has indicated Gemini-SQL2 will ship inside BigQuery Studio and Looker. For most developers, the practical impact won't be a standalone API — it will be improved natural-language analytics inside Google's data tools. If you're on BigQuery, you'll likely get this as a feature upgrade. If you're on another platform, the architecture provides a template for building your own.

Pitfalls

1 in 5 Queries Still Fails

At 80.04%, roughly 20% of queries require human correction. In a production analytics workflow, this means every fourth or fifth question generates a wrong answer. For dashboards and decision-support use cases, this failure rate is too high for unsupervised deployment. Plan for human-in-the-loop verification.

No Public API or Model Weights

Gemini-SQL2 is a research capability, not a product. There's no API endpoint, no model card, and no published paper. The only route to access is through Google's data products on their timeline. If you're building a text-to-SQL product today, this announcement doesn't change your immediate options.

BIRD Has Its Own Weaknesses

While BIRD is harder than Spider, it still tests against a fixed set of databases and question types. The 95 databases are diverse, but they don't cover every domain, every schema pattern, or every SQL dialect. Performance on BIRD is a strong signal, not a guarantee. Your production schema will surface edge cases the benchmark didn't.

Execution Accuracy vs. Business Correctness

The benchmark checks whether the SQL returns the same results as the gold query. But what if the gold query itself encodes incorrect business logic? This is a known limitation of execution-accuracy metrics. The system can be perfectly accurate at producing queries that match a flawed reference. Always validate the business logic independently.

Schema Drift is Undefined

Gemini-SQL2's schema linking is optimized for the schemas it encounters during evaluation. In production, schemas change — columns are added, tables are deprecated, naming conventions shift. The system has no defined behavior for schema drift. Any production deployment needs a mechanism for detecting when the schema context has become stale and triggering a rebuild.

Summary

Gemini-SQL2 represents a genuine advance in text-to-SQL, driven by architectural decisions — multi-turn candidate generation, execution-based verification, and explicit schema reasoning — rather than raw model scaling. The three-stage pipeline is a template worth studying, even if you never use Google's implementation.

The key takeaway for agent developers: verification loops beat single-shot generation. Your SQL agent isn't done when it generates a query. It's done when it executes that query against a sandbox, validates the results, and can prove the output is correct.