SQLens: Fine-grained and Explainable Error Detection in Text-to-SQL

Authors: Yue Gong, Chuan Lei, Xiao Qin, Kapil Vaidya, Balakrishnan Murali Narayanaswamy
Primary area: generative models
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.

Decision: reject

Reviews and discussion:

Metareview: