SQLCritic: Correcting Text-to-SQL Generation via Clause-wise Critic

Leilei Gan, Jikai ChenarXiv 2025 · DOI

Abstract

While Large Language Models (LLMs) have significantly advanced Text-to-SQL tasks, they often produce queries with subtle logical or syntactic errors. Existing self-correction methods typically provide coarse, response-level feedback, which can lead to "hallucinated corrections" or failure to identify specific semantic issues. This paper introduces SQLCritic, a framework that employs a fine-grained, clause-wise approach to error identification and correction. By breaking queries into constituent clauses and utilizing a novel adaptive preference optimization technique (CriticDPO), SQLCritic achieves superior diagnostic capabilities and execution accuracy on major benchmarks like Spider and BIRD.

Introduction

Large Language Models (LLMs) have become remarkably proficient at translating natural language questions into database queries. However, they are not infallible. When an LLM makes a mistake, current self-correction methods often struggle because they provide feedback at the response level (e.g., "This SQL is wrong, try again"). This lack of granularity often leads to corrections that fix one part of the query while breaking another, or failing to notice subtle semantic errors where the SQL is syntactically valid but returns incorrect data. To truly improve, a model needs to identify exactly which part of the query—the SELECT, JOIN, or WHERE clause—is failing and why.

Methods

The authors propose a multi-stage framework to transform a standard LLM into a specialized "SQL Critic."

Clause-wise Critiquing

Instead of evaluating the whole query, the model breaks the SQL into its constituent clauses. It generates a specific critique for each component, identifying exactly where the logic diverges from the user's intent. This "surgical" approach reduces the chance of collateral damage during the correction phase.

Example of clause-wise critique identifying specific errors in an LLM-generated SQL query.

CriticDPO (Adaptive Preference Optimization)

The authors utilize Direct Preference Optimization (DPO) to train the model with a novel twist: an adaptive $\beta$ hyperparameter. Standard DPO uses a fixed $\beta$ to control deviation from the base model. SQLCritic introduces a dynamic coefficient that adjusts based on "clause-level inconsistencies." If a preferred critique and a dispreferred one are vastly different, the model adjusts its learning step to account for that conflict, leading to more stable and precise training.

Automated Data Curation

To train this critic, the researchers built a pipeline using high-performing models (like CodeS) and general-purpose models (like Qwen2.5) to generate a wide spectrum of SQL errors. They then used GPT-4 to generate initial critiques and validated them by checking if a correction based solely on that critique resulted in the correct answer.

The SQLCritic framework overview, showing the data generation, benchmark construction, and training pipeline.

Datasets and Evaluation

The researchers evaluated SQLCritic on two industry-standard benchmarks:

  • Spider: A complex, cross-domain Text-to-SQL benchmark.
  • BIRD: A large-scale benchmark focusing on real-world database values and complex reasoning.
  • SQLCriticBench: A new specialized benchmark introduced by the authors containing over 3,000 samples. It includes human-verified, clause-wise critiques, allowing researchers to measure how well a model can actually explain an error rather than just fixing it by chance.

Key Results

SQLCritic demonstrated a clear performance edge across the board:

  • Accuracy Boost: On the BIRD benchmark, SQLCritic improved the execution accuracy (EX) of various base models (including GPT-3.5 and GPT-4o) by 2% to 8% absolute.
  • Superior Diagnostics: On the new SQLCriticBench, SQLCritic achieved a Critique Performance Score (CPS) of 48.4, significantly outperforming GPT-4 (16.8) and o1-mini (12.3).
  • Lower Error Rates: It recorded significantly fewer "Critique Flaws" (256) compared to GPT-3.5 (278) and GPT-4o (273), despite being a much smaller, specialized model.

Limitations and Future Work

The authors identify several remaining challenges. The clause-wise approach can struggle with nested complexity, such as deeply nested subqueries where breaking them down might lose overarching semantic context. Additionally, cross-clause dependencies—where an error lies in the relationship between two clauses (like a mismatch between GROUP BY and HAVING)—are occasionally missed. Future research will focus on integrating cross-clause analysis and diversifying training data to include more unconventional SQL patterns.

Summary updated

BibTeX
@misc{gan2025sqlcritic,
  author = {Leilei Gan and Jikai Chen},
  title = {{SQLCritic: Correcting Text-to-SQL Generation via Clause-wise Critic}},
  year = {2025},
  eprint = {2503.07996},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.07996},
}
Figure