Keywords: Text-to-SQL, Error Detection, Large Language Models
Abstract: Text-to-SQL systems translate natural language (NL) questions into SQL queries, allowing non-technical users to perform complex data analytics. Large language models (LLMs) have shown promising results on the text-to-SQL task. However, these LLM-based text-to-SQL solutions often generate syntactically correct but semantically incorrect SQL queries, which yield undesired execution results. Additionally, most text-to-SQL solutions generate SQL queries without providing information on the quality or confidence in their correctness. Systematically detecting semantic errors in LLM-generated SQL queries in a fine-grained manner with explanations remains unexplored. In this paper, we propose SQLens, a framework that leverages the given NL question as well as information from the LLM and database to diagnose the LLM-generated SQL query at the clause level. SQLens can link problematic clauses to error causes, and predict the semantic correctness of the query. SQLens effectively detects issues related to incorrect data and metadata usage such as incorrect column selection, wrong value usage, erroneous join paths, and errors in the LLM's reasoning process. SQLens achieves an average improvement of 25.78\% in F1 score over the best-performing LLM self-evaluation method in identifying semantically incorrect SQL queries on two public benchmarks. We also present a case study to demonstrate that SQLens can localize and explain errors for subsequent automatic error correction.
Primary Area: generative models
Code Of Ethics: I acknowledge that I and all co-authors of this work have read and commit to adhering to the ICLR Code of Ethics.
Submission Guidelines: I certify that this submission complies with the submission instructions as described on https://iclr.cc/Conferences/2025/AuthorGuide.
Reciprocal Reviewing: I understand the reciprocal reviewing requirement as described on https://iclr.cc/Conferences/2025/CallForPapers. If none of the authors are registered as a reviewer, it may result in a desk rejection at the discretion of the program chairs. To request an exception, please complete this form at https://forms.gle/Huojr6VjkFxiQsUp6.
Resubmission: No
Anonymous Url: I certify that there is no URL (e.g., github page) that could be used to find authors’ identity.
No Acknowledgement Section: I certify that there is no acknowledgement section in this submission for double blind review.
Submission Number: 1365
Loading