Node-Level Uncertainty Estimation in LLM-Generated SQL

Hilaf Hasson, Ruocheng Guo


Abstract
We present a practical framework for detecting errors in LLM-generated SQL by estimating uncertainty at the level of individual nodes in the query’s abstract syntax tree (AST). Our approach proceeds in two stages. First, we introduce a semantically aware labeling algorithm that, given a generated SQL and a gold reference, assigns node-level correctness without over-penalizing structural containers or alias variation. Second, we represent each node with a rich set of schema-aware and lexical features - capturing identifier validity, alias resolution, type compatibility, ambiguity in scope, and typo signals - and train a supervised classifier to predict per-node error probabilities. We interpret these probabilities as calibrated uncertainty, enabling fine-grained diagnostics that pinpoint exactly where a query is likely to be wrong. Across multiple databases and datasets, our method substantially outperforms token log-probabilities: average AUC improves by +27.44% while maintaining robustness under cross-database evaluation. Beyond serving as an accuracy signal, node-level uncertainty supports targeted repair, human-in-the-loop review, and downstream selective execution. Together, these results establish node-centric, semantically grounded uncertainty estimation as a strong and interpretable alternative to aggregate sequence-level confidence measures.
Anthology ID:
2026.lrec-1.168
Volume:
Proceedings of the Fifteenth Language Resources and Evaluation Conference
Month:
May
Year:
2026
Address:
Palma de Mallorca, Spain
Editors:
Stelios Piperidis, Núria Bel, Henk van den Heuvel, Nancy Ide, Simon Krek, Antonio Toral
Venue:
LREC
SIG:
Publisher:
ELRA Language Resource Association
Note:
Pages:
2145–2153
Language:
External URL:
https://lrec.elra.info/lrec2026-main-168
DOI:
10.63317/3i2i8xy5e7hs
Bibkey:
Cite (ACL):
Hilaf Hasson and Ruocheng Guo. 2026. Node-Level Uncertainty Estimation in LLM-Generated SQL. In Proceedings of the Fifteenth Language Resources and Evaluation Conference, pages 2145–2153, Palma de Mallorca, Spain. ELRA Language Resource Association.
Cite (Informal):
Node-Level Uncertainty Estimation in LLM-Generated SQL (Hasson & Guo, LREC 2026)
Copy Citation: