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

Exploring Chain of Thought Style Prompting for Text-to-SQL

Chang-Yu Tai, Ziru Chen, Tianshu Zhang, Xiang Deng, Huan Sun

Abstract

While Chain-of-Thought (CoT) reasoning has significantly improved Large Language Model (LLM) performance on complex tasks, its application to Text-to-SQL generation presents unique challenges. This research explores various prompting strategies, identifying that standard CoT can inadvertently lead to error propagation in SQL generation. We propose QDecomp, a single-pass question decomposition method, and InterCOL, which integrates intermediate schema hints. Our findings demonstrate that these methods achieve substantial accuracy gains on the Spider benchmark while reducing computational overhead compared to traditional iterative prompting.

The Challenge of Text-to-SQL Parsing

Text-to-SQL parsing—converting natural language questions into valid SQL queries—is essential for creating intuitive database interfaces. Despite the capabilities of LLMs, complex queries requiring multi-table joins or nested subqueries often result in failure. The authors identify two primary hurdles:

  1. Schema Grounding: Correctly mapping natural language terms to specific database tables and columns.
  2. Reasoning Errors: Standard CoT methods often produce overly detailed natural language steps. If a model makes a minor error in an early reasoning step (e.g., hallucinating a column name), that error propagates, leading to a broken final query.

Prompting Strategies for SQL Generation

The study systematically evaluates several prompting styles to determine the most effective approach for SQL generation:

  • Standard CoT: The model explains the logic of SQL clauses (FROM, WHERE, SELECT) before writing the code.
  • Least-to-Most (LtM): An iterative approach where the model breaks a question into sub-questions and solves them sequentially, feeding previous answers into subsequent prompts.
  • QDecomp (Proposed): A single-pass method that decomposes complex questions into simpler sub-questions. This reduces "API tax" and maintains global context.
  • QDecomp + InterCOL (Proposed): This method prompts the model to explicitly list Intermediate COLumns and tables for every sub-question. This forces accurate schema linking before the SQL syntax is generated.
Comparison of Single-Pass (CoT, QDecomp) vs. Iterative (Least-to-Most) prompting methods.

Experimental Results and Insights

The methods were evaluated on the Spider benchmark and its more difficult variant, Spider Realistic, which removes explicit column names to test true semantic understanding.

Key Findings

  • Detail vs. Accuracy: Surprisingly, standard CoT performed worse than standard prompting. Detailed natural language steps proved error-prone; if the model hallucinated a column name in its explanation, it felt compelled to use that incorrect name in the final SQL.
  • Efficiency of Single-Pass Prompting: While iterative prompting (LtM) is effective for mathematics, it is often unnecessary for SQL. QDecomp outperformed LtM by 2.4 points while being faster and more cost-effective.
  • The Importance of Schema Hints: The InterCOL variant demonstrated that explicitly identifying the "bridge" between the question and the schema is the most critical reasoning step for LLMs in this domain.
Performance comparison of different prompting methods across Spider Dev and Spider Realistic benchmarks.

Performance Summary

Using the code-davinci-002 (Codex) model, the researchers reported significant improvements:

  • Spider Dev Set: QDecomp + InterCOL achieved 68.4% test-suite accuracy, a 5.2-point absolute gain over standard prompting.
  • Spider Realistic: The method saw an even larger jump of 6.5 points over the baseline.
  • Competitive with Fine-tuning: When utilizing "extra-hard" examples for in-context learning, the method reached 78.2% accuracy, rivaling specialized fine-tuned models like RASAT+PICARD.

Future Directions

While successful, the authors note that future work should validate these findings on newer models (e.g., GPT-4) and incorporate actual database content (cell values) to further disambiguate queries. Additionally, the natural language sub-questions generated by QDecomp could enable human-in-the-loop systems where users correct intermediate steps to ensure final query accuracy.

Summary updated

BibTeX
@inproceedings{tai2023exploring,
  author = {Chang-Yu Tai and Ziru Chen and Tianshu Zhang and Xiang Deng and Huan Sun},
  title = {{Exploring Chain of Thought Style Prompting for Text-to-SQL}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  doi = {10.18653/v1/2023.emnlp-main.327},
}
Figure