SQLConsensus: Confidence Estimation in Text-to-SQL from Structural and Execution Agreement

Jaeyun Park, Yongbin Choi, Donghee Choi, Mujeen SungarXiv 2026

TL;DR

When large language models (LLMs) translate plain English into SQL, a wrong query often still runs cleanly and returns plausible-looking data—making silent errors dangerously easy to miss. SQLConsensus solves this by estimating a query's confidence using both its execution results and its SQL clause structure, crucially comparing clauses only among queries that return the same answer. Across four LLMs and four benchmarks, it beats the strongest existing confidence estimators by an average of 7.0 AUROC points, helping systems reliably flag shaky queries for human review.

What Problem Does This Paper Address?

Natural language interfaces let non-experts—like clinicians querying hospital records or analysts pulling quarterly sales—ask questions of databases without knowing SQL. The catch is that LLMs don't reliably know when they're wrong. Unlike syntax errors that crash loudly, a semantically wrong SQL query (say, missing a pair of parentheses in a WHERE clause) often executes without a hitch and hands the user a neat table of completely wrong numbers.

To deploy these systems safely, we need confidence estimation: a score that ranks correct predictions higher than incorrect ones so uncertain queries can be routed to a human expert. Existing methods typically sample several candidate queries from the LLM and measure agreement on one side only:

  • Execution-only methods (like Code-MUE) group queries by their output rows. They can be fooled when sampled queries agree on a different result than the main prediction, or when two different queries happen to return the same rows on a single database by coincidence.
  • Structure-only methods (like MPS) check how often the prediction's SQL clauses recur across samples. But if a faulty clause keeps showing up in queries that return different, wrong answers, it can still falsely inflate confidence.
Example from BIRD where Code-MUE and MPS assign high confidence to an incorrect prediction while SQLConsensus assigns 0.00

Methods

SQLConsensus takes a primary SQL prediction (generated via greedy decoding) alongside $N=5$ sampled queries from the same LLM, and combines two complementary signals:

  1. Execution Agreement (Agree): Every query is executed on the target SQLite database. Agree is simply the fraction of sampled queries that return the exact same non-empty set of rows as the primary prediction.
  2. Structural Score (Struct): This averages two checks:
  3. Clause Consistency (Consist): Using an abstract syntax tree parser (sqlglot), the method normalizes each query's clauses (resolving table aliases, standardizing formatting, and sorting commutative Boolean terms). It then measures how consistently the execution-agreeing queries form each clause. Any sampled query that returned a different result is treated as a distinct, disagreeing form for every clause.
  4. Validation Score (Verify): Because even agreeing queries can be wrong in the exact same way, the LLM is prompted to inspect the primary prediction clause-by-clause against the original question and schema, outputting a normalized Yes/No probability.

The final confidence score is a weighted blend: 0.60 * Agree + 0.40 * Struct.

Datasets

The authors evaluated four LLMs—GPT-6-Luna, Llama-3.1-8B-Instruct, Qwen2.5-Coder-7B-Instruct, and Phi-4 (14B)—across two general-domain benchmarks and one clinical-domain benchmark:

  • BIRD and Spider (general-domain Text-to-SQL).
  • EHRSQL, evaluated on all test questions from two hospital-record databases: MIMIC-III and eICU.

No new benchmarks were introduced; all three use SQLite databases.

Key Insights and Ideas

  • Don't count clauses from disagreeing queries: Counting how often a prediction's clauses appear in queries that return different results actually correlates with incorrect predictions (yielding an AUROC of just 45.14%). Restricting clause comparison to execution-agreeing queries is what makes structure a reliable tie-breaker.
  • Both signals pull their weight: Removing execution agreement (Agree) drops mean AUROC by 8.35 points, while removing the structural score (Struct) drops it by 2.28 points.
  • Small budgets work: Even with just $N=5$ sampled queries, SQLConsensus generally outperforms baseline methods that use $N=30$ samples.
  • Ready for online use: In a live system receiving one question at a time, replacing the structural scores with online mid-ranks changes AUROC by at most 0.57 points, meaning the method works without pre-computing dataset-wide scaling.

Key Results

  • Discrimination (AUROC): SQLConsensus achieved the highest AUROC in all 16 settings (4 models × 4 datasets), outperforming the strongest baseline in each setting by 7.0 points on average (and beating the best execution-only and structure-only baselines by 8.6 and 11.5 points, respectively).
  • Selective Prediction: When systems only auto-return their top 10% most confident predictions, SQLConsensus achieved the lowest error rate in 14 of 16 settings (for example, 7.14% error for Llama-3.1 on BIRD vs. 19.58% for Execution Consistency).
  • Latency: SQLConsensus averages 7.14 seconds per question—about 3 seconds slower than execution-only baselines, but much faster than Semantic Entropy (10.66s), DINCO (22.91s), or SAC (28.52–31.74s).

Limitations and Future Work

  • Database access required: Because it relies on executing sampled queries, SQLConsensus cannot be used in full where privacy rules or server load forbid running model-generated SQL on the live database—leaving only the LLM validation score.
  • Shared blind spots: If all sampled queries make the exact same mistake in both structure and execution result, agreement-based signals cannot catch it.
  • Scope and calibration: The study only tests English questions on SQLite databases; other SQL dialects (like PostgreSQL or Snowflake) and massive enterprise schemas remain untested. Additionally, the output is a ranking score rather than a calibrated probability, so setting a strict pass/fail threshold requires a separate calibration step.

Summary updated

BibTeX
@misc{park2026sqlconsensus,
  author = {Jaeyun Park and Yongbin Choi and Donghee Choi and Mujeen Sung},
  title = {{SQLConsensus: Confidence Estimation in Text-to-SQL from Structural and Execution Agreement}},
  year = {2026},
  eprint = {2612.05176},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2612.05176},
}
Figure