arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2511.13984cs.LGcs.AI
收藏

节点层面的LLM生成SQL不确定性估计

Node-Level Uncertainty Estimation in LLM-Generated SQL

Hilaf Hasson, Ruocheng Guo

AI总结:

本文提出了一种基于节点层面的LLM生成SQL不确定性估计方法,通过语义感知标记和特征提取提升查询错误检测与修复的准确性。

摘要:

我们提出了一种实用框架,用于通过估计查询抽象语法树(AST)中各个节点的不确定性来检测LLM生成的SQL中的错误。我们的方法分为两个阶段。首先,我们引入了一种语义感知的标记算法,给定生成的SQL和黄金参考,可以分配节点层面的正确性,而不会过度惩罚结构容器或别名变化。其次,我们为每个节点表示一组丰富的模式感知和词法特征,捕捉标识符的有效性、别名解析、类型兼容性、作用域的模糊性和拼写错误信号,并训练一个监督分类器来预测每个节点的错误概率。我们将这些概率解释为校准的不确定性,从而实现细粒度的诊断,精确指出查询可能出错的地点。在多个数据库和数据集上,我们的方法在多个方面显著优于token对数概率:平均AUC提高了+27.44%,同时在跨数据库评估中保持稳健。除了作为准确性信号之外,节点层面的不确定性支持有针对性的修复、人机协作审查和下游选择性执行。这些结果共同确立了以节点为中心、语义基础的不确定性估计作为强且可解释的替代方案,替代整体序列级别置信度度量。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑