SWE-SQL: Illuminating LLM Pathways to Solve User SQL Issues in Real-World Applications

Jinyang Li, Xiaolong Li, Ge Qu, Per Jacobsson, Bowen Qin, Binyuan Hui, Shuzheng Si, Nan Huo, Xiaohan Xu, Yue Zhang, Ziwei Tang, Yuanshuai Li, Florensia Widjaja, Xintong Zhu, Feige Zhou, Yongfeng Huang, Yannis Papakonstantinou, Fatma Ozcan, Chenhao Ma, Reynold Cheng

Introduction

While Large Language Models (LLMs) have demonstrated remarkable proficiency in Text-to-SQL tasks—generating SQL queries from natural language descriptions—their performance falters when faced with the more nuanced task of debugging and repairing existing, faulty SQL code. In real-world software engineering, developers rarely start from a blank slate; they spend significant time diagnosing why a query failed or why it returned incorrect results. This "SQL debugging" requires a deep synthesis of user intent, database schema constraints, and dialect-specific syntax.

This paper introduces BIRD-CRITIC, a rigorous benchmark designed to evaluate LLMs on authentic SQL debugging tasks, and BIRD-FIXER, an open-source 14B-parameter agent. By leveraging a novel synthetic training environment and a specialized inference strategy, BIRD-FIXER demonstrates that smaller, specialized models can outperform massive proprietary models like GPT-4.1 and Claude 3.7 Sonnet in complex database reasoning.

The BIRD-CRITIC Benchmark

To move beyond simple syntax checking, the authors developed BIRD-CRITIC, a benchmark consisting of 1,100 tasks derived from real-world SQL bugs found on StackOverflow. These bugs were reproduced in isolated Docker sandboxes to ensure a consistent execution environment.

The benchmark is divided into two primary subsets:

  • BIRD-CRITIC-PG: 530 tasks focused on PostgreSQL.
  • BIRD-CRITIC-MULTI: 570 tasks spanning PostgreSQL, MySQL, SQL Server, and Oracle.

Unlike traditional benchmarks that rely on exact string matching, BIRD-CRITIC evaluates success using custom test cases. This approach accommodates the reality that multiple valid SQL queries can solve the same problem, focusing on functional correctness rather than stylistic adherence.

Methodology: SIX-GYM and f-Plan Boosting

Training models for debugging is difficult due to the scarcity of high-quality, step-by-step debugging trajectories. The authors address this through SIX-GYM, a synthetic training environment utilizing a "SQL-Rewind" strategy. This process takes verified, correct SQL queries and uses an LLM to systematically inject plausible errors, effectively reverse-engineering realistic debugging scenarios.

To improve the quality of the training data, the authors introduced f-Plan Boosting. Standard teacher LLMs often fail to solve complex debugging environments on their own. By first extracting a high-level "functional plan" (f-Plan) from the known solution, the teacher LLM is guided through the environment step-by-step. This technique increased the generation of successful training trajectories by 73.7%, resulting in a high-quality dataset of approximately 3,301 trajectories.

The BIRD-FIXER Agent Architecture

BIRD-FIXER is built upon the Qwen-2.5-Coder-14B base and utilizes two key architectural innovations:

  1. SQL-ACT Agent Scaffold: Rather than being restricted to a fixed set of tools, the agent is empowered to execute arbitrary SQL commands as actions. This provides a rich toolkit for inspecting schemas, checking data distributions, and testing intermediate query results.
  2. Generative Thought Mode (GTM): To prevent the model from overfitting to specific SQL patterns during fine-tuning, the authors decoupled reasoning from execution. During inference, the fine-tuned model generates the debugging "thought" (the strategy), while the base model generates the actual SQL action. This allows the agent to maintain the broad dialect knowledge of the base model while benefiting from the specialized reasoning of the fine-tuned version.

Key Results and Insights

BIRD-FIXER achieves state-of-the-art performance among open-source models and rivals the most advanced proprietary systems. On the BIRD-CRITIC-PG benchmark, BIRD-FIXER achieved a 38.11% success rate, surpassing GPT-4.1 (37.36%) and Claude-3.7-Sonnet (32.08%). While OpenAI’s o3-mini remains the leader at 38.87%, the proximity of a 14B model to these giants is significant.

Critical Observations:

  • The SELECT Bottleneck: Data management tasks (INSERT, UPDATE, DELETE) proved easier for models to fix. Complex SELECT queries involving joins and aggregations remain the most difficult due to the diversity of business logic they represent.
  • Cross-Dialect Generalization: Despite being fine-tuned primarily on PostgreSQL, the GTM inference technique allowed BIRD-FIXER to generalize to MySQL, SQL Server, and Oracle, achieving 29.65% on the MULTI subset.
  • The Chain of Errors: Error analysis revealed that models often fall into a trap of fixing superficial syntax errors reported by the engine while missing deeper logical issues, such as failing to update associated sequences after a primary key fix.

Conclusion

BIRD-FIXER demonstrates that specialized scaffolding and high-quality synthetic data can enable relatively small models to solve complex software engineering tasks. By focusing on the reasoning bottleneck of SQL debugging, this research provides a pathway for deploying capable, privacy-sensitive database agents locally within enterprise environments. Future work will expand BIRD-CRITIC to include multi-turn interactions, better simulating the iterative nature of real-world troubleshooting.

Summary updated

BibTeX
@inproceedings{li2025swe,
  author = {Jinyang Li and Xiaolong Li and Ge Qu and Per Jacobsson and Bowen Qin and Binyuan Hui and Shuzheng Si and Nan Huo and Xiaohan Xu and Yue Zhang and Ziwei Tang and Yuanshuai Li and Florensia Widjaja and Xintong Zhu and Feige Zhou and Yongfeng Huang and Yannis Papakonstantinou and Fatma Ozcan and Chenhao Ma and Reynold Cheng},
  title = {{SWE-SQL: Illuminating LLM Pathways to Solve User SQL Issues in Real-World Applications}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=yRxXTdElLv},
}
Figure