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

SEA-SQL: Semantic-Enhanced Text-to-SQL with Adaptive Refinement

Chaofan Li, Yingxia Shao, Zheng LiuFrontiers of Computer Science 2024 · DOI

TL;DR

This paper introduces SEA-SQL, a cost-effective framework for text-to-SQL generation using LLMs. It tackles the challenges of inherent LLM biases and unexecutable SQL queries by employing a semantic-enhanced schema, an adaptive bias eliminator, and a dynamic execution adjustment mechanism, achieving competitive performance with significantly reduced costs.

What Problem Does This Paper Address?

The task of converting natural language questions into SQL queries (Text-to-SQL) is crucial for making databases accessible. While Large Language Models (LLMs) have shown promise, current approaches face several limitations:

  • Inherent Model Bias: LLMs can exhibit biases learned from training data, leading to incorrect SQL syntax or logic (e.g., preferring "LEFT JOIN" over "JOIN").
  • Unexecutable SQL: Generated SQL queries may contain errors that prevent them from running, requiring manual correction or further validation.
  • Expensive Inference Costs: Many state-of-the-art methods rely on powerful but costly LLMs like GPT-4 and often use few-shot prompting, which further increases computational expenses.

SEA-SQL aims to address these issues by providing a more efficient and reliable Text-to-SQL solution.

Methods

SEA-SQL employs a three-pronged approach:

  1. Semantic-Enhanced Schema: Instead of just using table and column names, this method augments the schema with relevant column values extracted from the database. This helps the LLM better understand the database's semantics, especially when questions are ambiguous or column names are not explicit. It uses a combination of BM25 and a "bridging" method for efficient retrieval of relevant values.
  2. Adaptive Bias Elimination: This module uses a smaller, fine-tuned LLM (Mistral-7B) to identify and correct biases introduced by the main SQL generation LLM (GPT-3.5). The bias eliminator receives the generated SQL and its execution results, learning to correct errors without needing to fully understand SQL syntax itself. This is trained on pairs of (question, schema, pre-SQL, execution result, bias-eliminated SQL).
  3. Dynamic Execution Adjustment: This is an iterative process that ensures the final SQL query is executable. It involves:
  4. Execute: Running the generated SQL query.
  5. Reflect: If an error occurs, the LLM analyzes the error message to understand the cause.
  6. Correct: The LLM regenerates the SQL query based on the reflection, and this cycle repeats until the query executes successfully. This process is inspired by Chain-of-Thought and REACT.

Datasets

The paper evaluates SEA-SQL on the following datasets:

  • Spider: A comprehensive semantic parsing and Text-to-SQL dataset with 10,181 questions and 5,693 complex SQL queries across 138 domains.
  • BIRD: A benchmark for large-scale Text-to-SQL tasks, focusing on efficiency with massive and noisy database contents, comprising 12,751 Text-to-SQL pairs across 37 domains.
  • Spider-Realistic: A variant of the Spider dataset designed to emulate real-world scenarios by omitting explicitly mentioned column names in questions.

Key Insights and Ideas

  • Value-Augmented Schemas are Crucial: Simply providing table and column names isn't enough for LLMs to fully grasp database semantics. Including actual data values significantly improves understanding and query generation.
  • Smaller LLMs as Bias Correctors: A dedicated, smaller LLM can effectively act as a "bias eliminator" for larger LLMs, correcting errors without needing the full complexity of SQL generation. This is more efficient than trying to build complex prompt rules.
  • Iterative Execution is Key to Robustness: Ensuring SQL executability through an "execute-reflect-correct" loop is vital for practical Text-to-SQL systems, as it handles runtime errors and syntax issues that might not be directly related to semantic bias.
  • Cost-Effectiveness is Achievable: By leveraging GPT-3.5 and a fine-tuned smaller LLM, SEA-SQL achieves performance comparable to GPT-4-based methods but at a fraction of the cost.

Key Results

  • Spider Dataset: SEA-SQL achieves 83.6% accuracy on the development set, outperforming GPT-3.5-based methods and being competitive with GPT-4.
  • BIRD Dataset: SEA-SQL achieves 56.13% execution accuracy, outperforming other GPT-3.5 methods and matching GPT-4 methods with only 0.9%-5.3% of the generation cost.
  • Cost Savings: SEA-SQL offers significant cost reductions, with generation costs being 9%-58% of other GPT-3.5 methods and 0.9%-5.3% of GPT-4 methods.
  • Ablation Studies: Both Adaptive Bias Elimination (ABE) and Dynamic Execution Adjustment (DEA) are crucial components, with their removal significantly degrading performance, especially on more complex SQL queries.

Limitations and Future Work

  • Schema Linking Errors: The paper notes that SEA-SQL still struggles with schema linking errors, particularly when faced with a large amount of irrelevant information, suggesting it might select incorrect tables or columns.
  • Complex SQL Queries: The framework also shows limitations in handling very complex SQL queries.
  • Dataset Size Impact on Cost: For smaller datasets, the cost of SEA-SQL might appear higher, but it becomes significantly more cost-effective when extrapolated to larger scales.
  • Few-Shot Prompts for Higher Accuracy: While the paper focuses on zero-shot prompts for cost-efficiency, it acknowledges that few-shot prompts can yield even higher accuracy, though at a greater computational cost. Future work could explore optimal trade-offs.

Summary updated

BibTeX
@article{li2024sea,
  author = {Chaofan Li and Yingxia Shao and Zheng Liu},
  title = {{SEA-SQL: Semantic-Enhanced Text-to-SQL with Adaptive Refinement}},
  journal = {Frontiers of Computer Science},
  year = {2024},
  doi = {10.1007/s11704-025-41136-3},
}
Figure