Calibrating LLMs for Text-to-SQL Parsing by Leveraging Sub-clause Frequencies

Terrance Liu, Shuyi Wang, Daniel Preotiuc-Pietro, Yash Chandarana, Chirag Gupta

TL;DR

Large language models (LLMs) can be confidently wrong when translating natural language to SQL. This paper introduces "sub-clause frequency" (SCF) scores and a multivariate Platt scaling (MPS) method to provide more reliable confidence scores for text-to-SQL queries, significantly improving calibration and error detection.

What Problem Does This Paper Address?

Text-to-SQL systems, powered by LLMs, are crucial for accessing structured data. However, these models often produce outputs with high confidence, even when incorrect. This lack of reliable uncertainty estimation hinders their trustworthiness in real-world applications. Existing methods for calibrating model confidence scores are often applied to the entire output, ignoring the structured nature of SQL queries. This paper aims to bridge this gap by developing a calibrated confidence score specifically for text-to-SQL parsing, leveraging the internal structure of SQL queries.

Methods

The authors propose Multivariate Platt Scaling (MPS), an extension of the traditional Platt scaling method. While Platt scaling uses a single score (like the model's output probability) and maps it through a logistic regression to produce a calibrated score, MPS uses multiple signals. The key innovation here is the use of sub-clause frequencies (SCF) as these signals.

SCF scores are derived by:

  1. Generating multiple candidate SQL queries for a given natural language prompt using techniques like nucleus sampling and beam search.
  2. Parsing each candidate SQL query into its constituent sub-clauses (e.g., SELECT, FROM, WHERE, GROUP BY).
  3. Calculating the frequency of each sub-clause across the generated candidate queries. This frequency represents how consistently a particular sub-clause appears.
  4. Using these SCFs, along with the original model probabilities, as input features to a multivariate logistic regression model (MPS) to produce a final, calibrated confidence score.

This approach exploits the structured nature of SQL, assuming that the consistency of generating specific sub-clauses is indicative of correctness.

Datasets

The authors evaluate their methods on two popular text-to-SQL benchmarks:

  • SPIDER: A large, complex, cross-domain dataset with 10,181 questions and 5,693 unique SQL queries across 200 databases.
  • BIRD: A dataset focusing on handling dirty and noisy data, with 12,751 question-SQL pairs across 37 domains, also incorporating external knowledge.

Key Insights and Ideas

  • SQL structure is a valuable signal: The internal structure of SQL queries (sub-clauses) provides granular information about correctness that is missed by treating the entire query as a single output.
  • Consistency implies correctness: The frequency with which specific sub-clauses appear across multiple generated outputs is a strong indicator of their likelihood of being correct.
  • Post-hoc calibration is effective: Traditional methods like Platt scaling significantly improve LLM calibration for text-to-SQL, but MPS with SCFs offers further gains.
  • Calibration matters for error detection: Improved calibration directly translates to better performance on the related task of identifying erroneous SQL queries.

Key Results

  • Significant calibration improvement: MPS consistently outperforms baseline Platt scaling (PS) across both datasets and models in terms of calibration error (ECE, ACE) and Brier score. For example, MPS reduced calibration error by over 50% in some cases.
  • Enhanced error detection: MPS achieved higher AUC scores for error detection compared to PS, indicating better trade-offs between true and false positive rates.
  • Model performance comparison: Uncalibrated LLMs show varying degrees of miscalibration. While fine-tuned models like T5-3B might be better calibrated out-of-the-box than zero-shot LLMs like Llama 3.1, post-hoc calibration (especially MPS) significantly narrows this gap.
  • Sub-clause importance: Analysis shows that aggregate sub-clause scores are the most significant features for MPS, and removing specific clauses has varying impacts, suggesting that a combination of signals is most effective.

Limitations and Future Work

  • English-centric: The current work is limited to English text-to-SQL. Future work aims to extend these methods to multilingual settings.
  • Inference time: Generating multiple samples for SCF calculation increases inference time, though parallelization can mitigate this.
  • Zero-shot vs. Fine-tuned: Experiments with Llama 3.1 were primarily zero-shot. The authors suggest that their approach can be easily adopted for fine-tuned models.
  • Dataset limitations: The authors acknowledge that while their approach is general, specific performance might vary with dataset characteristics.

The authors hope their work inspires further research into leveraging structured output for uncertainty quantification in NLP and beyond.

Summary updated

BibTeX
@inproceedings{liu2025calibrating,
  author = {Terrance Liu and Shuyi Wang and Daniel Preotiuc-Pietro and Yash Chandarana and Chirag Gupta},
  title = {{Calibrating LLMs for Text-to-SQL Parsing by Leveraging Sub-clause Frequencies}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2025},
}
Figure