Abstract
Converting natural language questions into executable SQL queries is a critical task for democratizing data access. Despite the advancements in Large Language Models (LLMs), current Text-to-SQL pipelines often produce queries with subtle logical or data-related flaws. We introduce MGEI (Multi-grained Error Identification), a modular framework designed to diagnose errors at three granularities: system syntax, structural "skeletons," and data values. By acting as a diagnostic plugin, MGEI provides LLMs with specific feedback, significantly enhancing their self-correction capabilities. Evaluation on the Spider benchmark demonstrates that MGEI consistently improves execution accuracy for both fine-tuned and in-context learning models.
Introduction
The "Generate-Identify-Correct" loop has become a standard paradigm in Text-to-SQL. However, the "Identify" phase remains a bottleneck. Existing approaches typically rely on LLM self-correction, which often misses subtle logic, or execution-based feedback, which only catches syntax-level "System Errors." Logical mismatches (Skeleton Errors) and data-specific typos (Value Errors) often go undetected, leading to incorrect results even when the SQL is syntactically valid.
Methodology: Multi-grained Error Identification
MGEI addresses these gaps through a hierarchical identification process. The framework consists of three specialized modules:
- System Error Identification: Utilizes a standard SQL executor to catch syntax errors, invalid keywords, or table alias issues.
- Skeleton Error Identification: The core novelty of MGEI. It employs a Skeleton Matching Model trained via contrastive learning. By stripping queries and questions to their structural "skeletons," it evaluates whether the logical intent of the question matches the structure of the generated SQL.
- Value Error Identification: Performs a "sanity check" against the database to ensure that literal values in
WHEREclauses (e.g., 'New York' vs 'NYC') actually exist in the target columns, preventing empty result sets due to minor discrepancies.
Experimental Evaluation
The framework was evaluated using the Spider dataset, a complex cross-domain Text-to-SQL benchmark. To train the identification and correction components, the authors curated a specific error dataset using fine-tuned CodeLlama-13b models.
Performance Results
MGEI demonstrates superior error detection capabilities, achieving an F1-score of 64.8%, outperforming both general-purpose models like ChatGPT (58.6%) and specialized pipelines like DIN-SQL (63.2%).
When integrated into existing state-of-the-art pipelines, MGEI provides a substantial boost in Execution Accuracy (EX). As summarized in the table below, the framework improves the performance of both fine-tuned models (e.g., CodeLlama-13b) and in-context learning models (e.g., GPT-4 via DIN-SQL).
Discussion and Insights
The success of MGEI highlights the "Plugin Philosophy": rather than building a new end-to-end model, modular diagnostic tools can enhance existing LLMs. The study confirms that LLMs are significantly more effective at fixing code when provided with a specific "diagnostic report" (e.g., identifying a missing JOIN logic) rather than generic error messages. Ablation studies further reveal that while system error detection provides the most immediate gains, skeleton and value identification are crucial for solving "Hard" and "Extra Hard" queries.
Conclusion
MGEI offers a robust path forward for reliable Text-to-SQL systems by bridging the gap between generation and execution. Future work will focus on expanding support for more complex SQL dialects and optimizing the computational overhead of the multi-stage identification pipeline.
Summary updated