Abstract
Calibration is crucial as large language models (LLMs) are increasingly deployed to convert natural language queries into SQL for commercial databases. In this work, we investigate calibration techniques for assigning confidence to generated SQL queries. We show that a straightforward baseline -- deriving confidence from the model's full-sequence probability -- outperforms recent methods that rely on follow-up prompts for self-checking and confidence verbalization. Our comprehensive evaluation, conducted across two widely-used Text-to-SQL benchmarks and multiple LLM architectures, provides valuable insights into the effectiveness of various calibration strategies.
Introduction
As enterprises integrate Large Language Models (LLMs) into data workflows via Text-to-SQL, the "calibration gap" becomes a critical hurdle. Ideally, a model's stated confidence should reflect its actual accuracy—a 90% confidence score should correspond to a 90% success rate. However, modern LLMs, particularly those fine-tuned with Reinforcement Learning from Human Feedback (RLHF), are often poorly calibrated, exhibiting significant overconfidence. In SQL generation, where errors can lead to flawed business decisions or database failures, reliable confidence estimation is paramount. This study challenges the recent trend of "self-reflection" prompts, investigating whether simpler token-level probability metrics offer a more robust solution.
Methodology
The study evaluates two primary approaches for generating confidence scores:
- Pooled Token-level Probabilities: Scores are derived from the raw probabilities assigned to each token in the SQL string. Methods include Prod (product of all token probabilities/joint likelihood), Min (minimum token probability), and Geo/Avg (geometric/arithmetic means).
- LLM Self-checks: The model is prompted post-generation to evaluate its own output. This includes [Bool] (binary "Yes/No" probability) and [Probs] (verbalized numerical confidence).
A key component of the methodology is Post-hoc Rescaling. Raw scores are adjusted using Platt Scaling or Isotonic Regression on a small validation set to align predicted probabilities with observed accuracy.
Datasets and Models
Evaluation was conducted on two benchmarks: Spider (complex cross-domain SQL) and BIRD (large-scale, real-world data). The model suite included Llama-3 (8B & 70B), CodeS, Codestral, and GPT-4.
Results and Analysis
The experimental results consistently favor simple likelihood metrics over complex prompting strategies.
The Dominance of Raw Likelihood
The Prod method (full sequence likelihood) emerged as the most effective metric, consistently outperforming the "Min" probability method and self-checking techniques. As shown in the calibration plots, the "Prod" method aligns more closely with the ideal diagonal after rescaling compared to self-check methods, especially in smaller models.
The Generative-Reasoning Gap
A significant finding is the widening gap between generative ability and reasoning ability in smaller models. For Llama 8B, raw probabilities are substantially more reliable than asking the model to "think" about its answer. While larger models like Llama 70B close this gap somewhat, the simple Prod baseline remains highly competitive.
As detailed in the results table, the Prod method achieves the lowest Brier Scores (BS-I) and highest Area Under the Curve (AUC) across nearly all configurations. For instance, on Spider with Llama 8B, Prod achieved an AUC of 78.5, whereas Self-check Bool lagged at 48.9.
Discussion and Conclusion
This research demonstrates that for the structured task of SQL generation, "asking" the model for its confidence is often counterproductive. The "secret sauce" for effective calibration is not complex prompting, but rather the intelligent aggregation of raw token probabilities followed by rigorous post-hoc rescaling.
Limitations
The findings are specific to the structured nature of SQL. In tasks with shorter, less structured outputs (e.g., open-ended Q&A), self-checking might perform differently. Additionally, the lack of access to raw probabilities in closed-source models like GPT-4 remains a constraint, forcing a reliance on sub-optimal verbalized confidence. Future work will explore these dynamics in broader programming contexts.
Summary updated