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

Open-SQL Framework: Enhancing Text-to-SQL on Open-source Large Language Models

Min Yang (杨敏), Xiaojun Chen, Tianle Wang, Tianhao Qiu, Jianbin Qin, Min YangarXiv 2024 · DOI

Abstract

The Open-SQL Framework introduces a systematic methodology to bridge the performance gap between open-source Large Language Models (LLMs) and proprietary models like GPT-4 in Text-to-SQL tasks. By integrating structured "Open Prompts," token-efficient schema truncation, and a novel skeleton-based Chain-of-Thought (CoT) strategy, the framework significantly enhances model performance. Experimental results on the BIRD benchmark demonstrate that a fine-tuned Code Llama-7B can achieve an execution accuracy of 48.24%, surpassing GPT-4's 46.35%.

Introduction

Text-to-SQL—the automated translation of natural language questions into executable database queries—is a critical component for data accessibility. However, it remains a significant challenge for open-source LLMs. Models like Llama 2 frequently struggle with "schema linking" (mapping user intent to specific database entities) and maintaining structural coherence in complex queries. Furthermore, the massive scale of real-world databases often exceeds the context window of these models, leading to performance degradation due to information overload or memory constraints.

The Open-SQL Framework

To address these challenges, the researchers developed Open-SQL, a multi-stage optimization framework designed for the LLM pipeline:

  1. Open Prompt Strategy: Information is organized into a structured template that clearly separates database schemas, table definitions, external knowledge, and the target question.
  2. Token Efficiency via Truncation: To manage large-scale databases, the framework employs Target Column and Example Column Truncation. These techniques use similarity metrics to retain only the most relevant columns, ensuring the prompt fits within a 2048-token limit.
  3. Skeleton-based Chain-of-Thought (COT-SK): Unlike standard CoT, Open-SQL introduces a "skeleton" phase. The model first generates a structural query template (e.g., SELECT _ FROM _ WHERE _) before populating specific values. This focuses the model on logic before syntax.
  4. Open Example Curation: For few-shot learning, examples are selected based on a triple-similarity score encompassing the question, schema, and SQL structure.

Experimental Evaluation

The framework was primarily evaluated using the BIRD (Big Bench for Large-Scale Database Grounded Text-to-SQL) dataset, which features databases up to 100GB and requires external knowledge. The classic Spider dataset was also used to validate generalizability.

Results and Error Analysis

Initial error analysis revealed that "Wrong Schema Linking" was the primary bottleneck for open-source models, accounting for nearly half of all failures in baseline tests.

Error analysis of Llama 2 showing that schema linking is the primary failure mode.

Baseline performance for open-source models was significantly lower than proprietary counterparts. For instance, Code Llama-7B initially achieved only 13.1% to 14.54% execution accuracy on BIRD-Dev, while Llama 2-7B struggled below 3%.

Baseline execution accuracy comparison across GPT-3.5, Llama 2, and Code Llama.

However, with the application of the Open-SQL framework and fine-tuning, the results improved dramatically:

  • Code Llama-7B (Fine-tuned): Execution accuracy rose to 48.24%, outperforming GPT-4 (46.35%) and Claude-2 (42.70%) on the BIRD-Dev leaderboard.
  • Llama2-7B (Fine-tuned): Performance increased from 2.54% to 41.04%.
  • Spider Benchmark: The framework achieved 84.1% accuracy, placing it among the top-tier solutions.

Conclusion and Future Work

Open-SQL demonstrates that with structured prompting and specialized CoT strategies, open-source models can rival or exceed proprietary giants. Key insights include the "Skeleton" advantage in reducing syntax errors and the trade-off between fine-tuning and In-Context Learning (ICL) flexibility. Future work will focus on "ICL-preserving" fine-tuning methods and more robust schema-linking techniques to handle increasingly complex database operations like multi-way joins and intricate filtering logic.

Summary updated

BibTeX
@misc{2024open,
  author = {Min Yang (杨敏) and Xiaojun Chen and Tianle Wang and Tianhao Qiu and Jianbin Qin and Min Yang},
  title = {{Open-SQL Framework: Enhancing Text-to-SQL on Open-source Large Language Models}},
  year = {2024},
  eprint = {2405.06674},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2405.06674},
}
Figure