TL;DR
While Large Language Models (LLMs) excel at translating natural language into SQL queries, deploying them in high-stakes enterprise environments is risky because users cannot easily verify if a generated query is correct. This paper presents the first systematic evaluation of confidence estimation strategies for text-to-SQL tasks and introduces SQL-Aware Confidence (SAC), a novel white-box method that leverages SQL syntax rules to significantly improve model calibration and reliability.
What Problem Does This Paper Address?
Text-to-SQL systems allow non-technical users to query complex databases using everyday language. However, LLMs frequently suffer from hallucinations or subtle logical errors. If an LLM generates an incorrect SQL query, it can lead to silent data retrieval errors or misinformed business decisions.
To mitigate this, we need a reliable way to estimate the model's confidence in its own output without having access to the ground-truth "gold" answers. If the confidence score is low, the system can choose to reject the query or ask for human intervention. While confidence estimation has been widely studied for general text generation, it remains poorly understood for code and structured query generation, where syntax rules and execution feedback introduce unique constraints and opportunities.
Methods
The authors categorize and evaluate confidence estimation into two main paradigms:
- Black-box Approaches: These rely solely on the model's text outputs. They include verbalized confidence (prompting the LLM to state its confidence from 0-100%), Chain-of-Thought (CoT) verbalization, and consistency-based methods (generating multiple queries at a high temperature and clustering them based on text similarity, schema links, or database execution results).
- White-box Approaches: These leverage internal model states, specifically token-level probabilities (logits).
The Novelty: SQL-Aware Confidence (SAC)
The core contribution of the paper is SAC, a white-box method tailored to the unique structure of SQL. Instead of treating all tokens equally, SAC refines token probabilities using domain-specific rules:
- Token Exclusion: It ignores non-informative tokens like extra whitespaces, redundant parentheses, or optional keywords (e.g.,
INNERinINNER JOIN). - Case and Order Folding: It combines the probabilities of case variants (e.g.,
selectvsSELECT) and accounts for the fact that the order of elements in clauses (likeSELECT a, bvsSELECT b, a) does not affect correctness. - Synonym Folding: It treats equivalent operators (e.g.,
!=and<>) as interchangeable, summing their probabilities.
SAC aggregates these refined token probabilities using either a product method (highly sensitive to any single low-probability token) or an average method (more robust for longer queries).
Datasets
The methods were evaluated on the development sets of two prominent cross-domain text-to-SQL benchmarks:
- Spider: A dataset featuring 1,034 examples across 20 databases, characterized by shorter, simpler, pattern-style queries.
- BIRD: A more challenging dataset containing 1,533 complex question-SQL pairs across 11 databases, featuring heavy schema-linking, multi-table joins, and nested clauses.
Evaluations were conducted across both proprietary and open-source LLMs, including GPT-3.5-turbo, GPT-4o-mini, DeepSeek-6.7B, and Qwen2.5-Coder.
Key Insights and Ideas
- White-Box Beats Black-Box: Accessing internal token logits consistently provides a more accurate reflection of true model certainty than asking the model to verbalize its confidence. Verbalized approaches frequently suffer from extreme overconfidence.
- SQL Syntax Awareness is Essential: Standard logit aggregation treats boilerplate tokens (like commas and parentheses) with the same weight as critical schema links (table and column names). By filtering out the noise and applying syntax folding, SAC prevents minor formatting uncertainties from tanking the overall confidence score.
- Aggregation Strategy Depends on Query Length: Product aggregation works best for short, schema-heavy queries (like those in Spider) because every token is critical. However, for long, complex queries (like those in BIRD), product aggregation exponentially penalizes minor uncertainties, making average aggregation far more stable and reliable.
Key Results
The main evaluation metrics used were AUC-ROC (how well the score discriminates between correct and incorrect queries) and Expected Calibration Error (ECE) (how closely the confidence score matches empirical accuracy).
- State-of-the-Art Calibration: SAC consistently outperformed all baselines. On the complex BIRD dataset, SAC using average aggregation (SAC-Avg) delivered up to a 12% improvement in AUC-ROC and reduced ECE by as much as 16% compared to the best black-box competitor.
- Ablation Impact: An ablation study confirmed that removing token exclusion caused the largest performance drop (-5.7% AUC, +4.2% ECE), proving that filtering out non-critical tokens is vital for accurate confidence mapping.
- Robustness to Difficulty: As query complexity increased, baseline methods showed a steep drop-off in predictive reliability, whereas SAC maintained a much more gradual and stable performance decline.
Limitations and Future Work
While execution-based consistency proved to be the strongest black-box alternative when logits are unavailable, it introduces significant latency and computational cost because it requires generating and executing multiple query samples per question. This makes it less practical for large-scale enterprise databases.
For future work, the authors suggest exploring hybrid methods that combine the strengths of white-box logit analysis with black-box execution feedback, alongside evaluating these strategies on real-world, noisy databases.
Summary updated