NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

SQLfuse: Enhancing Text-to-SQL Performance through Comprehensive LLM Synergy

Tingkai Zhang, Chaoyu Chen, Cong Liao, Jun Wang, Xudong Zhao, Hang Yu, Jianchao Wang, Jianguo Li, Wenhui ShiarXiv 2024 · DOI

Introduction

Translating natural language into SQL (Text-to-SQL) is a fundamental challenge in democratizing data access. While large language models (LLMs) like GPT-4 have advanced the field, they often struggle with the "last mile" of database complexity, specifically regarding intricate schema relationships and iterative error correction.

SQLfuse is a modular framework designed to bridge these gaps by synergizing open-source LLMs with specialized database-mining tools. By decomposing the Text-to-SQL task into four distinct phases—schema mining, linking, generation, and a "critic" phase—SQLfuse achieved a top-tier 85.6% execution accuracy on the Spider leaderboard. This performance demonstrates that well-architected open-source systems can rival, and sometimes exceed, closed-source models like GPT-4.

Methodology

SQLfuse employs a four-stage modular architecture that guides the LLM through the complexities of a database environment. This structured approach ensures that the model has a clear "map" of the data before attempting to generate code.

The four-stage modular architecture of SQLfuse, encompassing Schema Mining, Schema Linking, SQL Generation, and the SQL Critic.

1. Schema Mining

This module acts as a database detective, extracting primary and foreign keys while identifying one-to-many (1:N) relationships and enumeration values (e.g., mapping a status code '0' to 'active'). This metadata is injected into the prompt to provide the LLM with essential context often missing in standard DDL.

2. Schema Linking

Powered by a fine-tuned Llama2-70B, this stage filters the database to identify only the tables and columns relevant to the user's specific query. This reduction of "noise" prevents the generation model from becoming overwhelmed by massive, irrelevant schemas.

3. SQL Generation (SQLgen)

Using CodeFuse-DeepSeek-33B, this module utilizes a custom "SQLfuse style" prompt that blends code-like structures with natural language. It incorporates a self-correction loop: if the generated SQL fails execution, the resulting error message is fed back to the model for an automated second attempt.

4. SQL Critic and Hindsight Feedback

The final stage uses a "generate-then-rank" strategy to evaluate multiple candidate queries. It employs a few-shot approach with hindsight feedback, learning from both successful and failed examples to select the most accurate final query.

Detailed workflow of the SQL Critic module, utilizing a GitHub-sourced knowledge base for few-shot learning and hindsight feedback.

Evaluation and Results

The framework was primarily evaluated on the Spider benchmark, a large-scale, cross-domain dataset known for complex multi-table queries. To support the Critic module, the authors curated a robust knowledge base of SQL pairs from open-source GitHub repositories.

Key results include:

  • Leaderboard Performance: SQLfuse achieved 85.6% execution accuracy, ranking as the top open-source LLM system at the time of publication.
  • Ablation Studies: Every module proved critical. Removing Schema Linking caused a >2% drop in accuracy, while omitting foreign key insights from Schema Mining led to a 3.3% decrease.
  • Real-World Utility: The system has been successfully deployed within Ant Group, supporting seven different business contexts across OLAP and OLTP frameworks.

Key Insights

  • The Power of the Critic: The introduction of the SQL Critic module alone provided a 1.8% accuracy boost by effectively ranking candidate queries.
  • Prompt Engineering: The "SQLfuse style" prompt, which organizes schema information more clearly than standard DDL, improved accuracy by 0.6%.
  • Open-Source Parity: A 33B-parameter open-source model, when supported by a domain-aware framework, can outperform much larger closed-source models that lack specialized architectural support.

Limitations and Future Work

Despite its success, SQLfuse faces challenges with extremely nested or rare SQL structures. Future research will focus on "Question/SQL Skeleton Generation" to synthesize complex training data and exploring Reinforcement Learning from Human Feedback (RLHF) to align generated SQL with expert DBA standards. Additionally, the team aims to reduce latency by distilling the multi-step modular process into a single, high-speed model.

Summary updated

BibTeX
@misc{zhang2024sqlfuse,
  author = {Tingkai Zhang and Chaoyu Chen and Cong Liao and Jun Wang and Xudong Zhao and Hang Yu and Jianchao Wang and Jianguo Li and Wenhui Shi},
  title = {{SQLfuse: Enhancing Text-to-SQL Performance through Comprehensive LLM Synergy}},
  year = {2024},
  eprint = {2407.14568},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.14568},
}
Figure