Large Language Model Enhanced Text-to-SQL Generation: A Survey

Xiaohu Zhu, Qian Li, Lizhen Cui, Yongkang LiuarXiv 2024 · OpenReview

Abstract

Text-to-SQL translates natural language queries into Structured Query Language (SQL) commands, enabling non-technical users to interact with databases intuitively. Historically, this task relied on rule-based and neural-based approaches. However, the advent of Large Language Models (LLMs) has fundamentally shifted the paradigm. This survey categorizes LLM-enhanced Text-to-SQL generations into four primary strategies: prompt engineering, fine-tuning, task-specific training, and agent-based methods. We also provide a comprehensive overview of evaluation metrics and datasets, highlighting the transition from syntactic matching to complex, real-world reasoning.

Introduction

Querying a database traditionally requires mastery of SQL, creating a significant "technical wall" for most users. Text-to-SQL aims to break this wall by allowing users to ask questions in plain language. Despite its promise, the task is deceptively difficult. A model must not only understand human language—which is often ambiguous—but also perform "schema linking": mapping words like "highest paid" to specific columns like Salary and operations like ORDER BY ... DESC LIMIT 1.

While earlier models like LSTMs struggled with complex joins and cross-domain generalization, LLMs have demonstrated remarkable capabilities in overcoming these hurdles. The general workflow involves taking a user query and a database schema, constructing a prompt, and leveraging an LLM to generate the corresponding SQL code, often incorporating fine-tuning or iterative refinement.

Workflow of LLM-enhanced Text-to-SQL generation, showing the path from user query to SQL output.

Taxonomy of Text-to-SQL Methodologies

Modern Text-to-SQL research can be categorized based on how models are adapted and executed for the task. The shift from traditional neural methods to LLM-based approaches has introduced several distinct strategies.

Comprehensive taxonomy of Text-to-SQL methods, datasets, and evaluation metrics.

1. Prompt Engineering

This approach utilizes "frozen" LLMs (e.g., GPT-4) without additional weight updates. Strategies include:

  • Zero-shot Prompting: Providing only the question and the schema.
  • Few-shot Prompting: Including example question-SQL pairs to guide the model.
  • Chain-of-Thought (CoT): Encouraging the model to "think step-by-step" to decompose the problem into intermediate reasoning stages.

2. Fine-Tuning

Fine-tuning involves adapting pre-trained models to the specific nuances of SQL generation. This includes Full-Parameter Fine-Tuning and Parameter-Efficient Fine-Tuning (PEFT) techniques like LoRA, which allow for efficient adaptation with significantly lower hardware requirements.

3. Task-Specific Training

Building models specifically designed for code and SQL generation, such as CodeS or RESDSQL. These models often utilize specialized architectures like Mixture of Experts (MoE) to handle diverse query patterns more effectively than general-purpose models.

4. LLM Agent Methods

The most advanced approach involves multi-agent systems where specialized "agents" (e.g., a Decomposer, a Selector, and a Refiner) collaborate. For instance, if a generated query fails execution, a "Fixer" agent can analyze the error message to iteratively debug and correct the code.

Datasets and Evaluation

The evolution of Text-to-SQL is mirrored in its benchmarks, moving from simple, single-domain datasets to complex, cross-domain challenges.

  • Single-Domain: Early benchmarks like ATIS (airline information) and GeoQuery (US geography).
  • Cross-Domain: Current gold standards like Spider (complex queries across 200+ databases) and BIRD (focusing on large-scale, "dirty" real-world data and execution efficiency).
  • Robustness and Conversational: Datasets like Spider-DK test model resilience to synonyms, while CoSQL and SParC evaluate multi-turn conversational context.

Evaluation metrics have also shifted. While Exact Matching (EM) was once standard, it often penalized semantically correct but syntactically different queries. Modern research prioritizes Execution Accuracy (EX) and the Valid Efficiency Score (VES), which measure if the query returns correct data and how fast it runs—a critical factor for enterprise-scale databases.

Key Insights and Results

Research indicates that decomposition is king; the most successful models (like DIN-SQL) break the problem into sub-tasks rather than writing the whole query at once. However, schema linking remains the primary bottleneck, as identifying relevant parts of a massive database schema from a vague user question is inherently difficult.

Currently, GPT-4 serves as the performance benchmark, particularly when paired with specialized prompting. However, smaller, open-source models like CodeLlama or DeepSeek-Coder can match or exceed massive general-purpose models when fine-tuned specifically for SQL tasks.

Challenges and Future Directions

Despite progress, several hurdles remain:

  • Context Window Limits: Enterprise databases with thousands of tables often exceed the "memory" of current LLMs.
  • Hallucinations: Models still occasionally "invent" columns or tables that do not exist in the provided schema.
  • Privacy and Security: Sending sensitive database structures to cloud-based LLMs is a major barrier for many industries.

Future research is pointing toward more robust multi-agent systems and "self-correcting" models that can handle the complexities of real-world production environments.

Conclusion

LLMs have revolutionized Text-to-SQL, moving the field toward more robust, agentic, and intuitive systems. By bridging the gap between natural language and structured data, these technologies are making data-driven insights accessible to a broader audience than ever before.

Summary updated

BibTeX
@misc{zhu2024large,
  author = {Xiaohu Zhu and Qian Li and Lizhen Cui and Yongkang Liu},
  title = {{Large Language Model Enhanced Text-to-SQL Generation: A Survey}},
  year = {2024},
  eprint = {2410.06011},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.06011},
}
Figure