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

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

Chang-You Tai, Ziru Chen, Tianshu Zhang, Xiang Deng, Huan Sun · DOI

Abstract

Text-to-SQL parsing is a critical component for natural language database interfaces. While Large Language Models (LLMs) have shown promise in this area, complex queries often lead to reasoning errors and schema misalignment. This paper explores various prompting strategies, identifying a "detailed reasoning trap" in traditional Chain-of-Thought (CoT) methods. We propose Question Decomposition (QDecomp) with Intermediate Column (InterCOL) linking—a single-pass approach that improves accuracy by reducing error propagation and enhancing schema grounding. Our method achieves significant gains on the Spider and Spider Realistic benchmarks while maintaining computational efficiency.

Introduction

Converting natural language questions into functional SQL queries requires a model to perform multi-step reasoning, understand complex database schemas, and adhere to strict syntax. While techniques like Chain-of-Thought (CoT) and Least-to-Most (LtM) prompting have revolutionized LLM performance in math and logic, their application to SQL is non-trivial. Researchers from The Ohio State University have identified that for SQL tasks, "less is often more." Providing excessive detail in reasoning steps can lead to error propagation, where a minor hallucination in a natural language explanation results in a completely broken SQL query.

Methodological Comparison

The study systematically evaluates several prompting styles using the Codex (code-davinci-002) model. The goal was to determine which approach best balances reasoning depth with execution accuracy.

  1. Standard Prompting: The baseline approach where the model is directly asked to generate SQL from a question.
  2. Chain-of-Thought (CoT): A single-pass method where the model explains the logical execution order (e.g., FROM, then WHERE, then SELECT) before writing the code.
  3. Least-to-Most (LtM): An iterative, multi-stage process. The model first reduces a complex problem into simpler sub-questions and then solves them sequentially across multiple API calls.
  4. Question Decomposition (QDecomp): Our proposed single-pass method. The model decomposes the question into sub-questions and generates the final SQL in one go, avoiding the overhead of iterative calls.
  5. QDecomp + InterCOL: An enhanced version of QDecomp that requires the model to explicitly list the specific tables and columns (Intermediate Columns) involved in each sub-question before generating the final query.
Comparison of Single-Pass Prompting (CoT, QDecomp) versus Iterative Prompting (Least-to-Most).

The "Detailed Reasoning" Trap

A key finding of this research is that traditional CoT prompting can actually degrade performance compared to standard prompting. In SQL generation, if a model makes a small error in its natural language reasoning—such as misidentifying a column name—it tends to follow that error "faithfully" into the final code. This creates a bottleneck where the explanation becomes a source of failure rather than a guide.

In contrast, QDecomp focuses on structural decomposition. By breaking the question into simpler parts without over-explaining the logic, the model maintains a better "global view" of the task. The addition of InterCOL serves as a grounding mechanism, forcing the model to map natural language components directly to the database schema, which is often the most difficult part of the Text-to-SQL task.

Experimental Results

The proposed methods were tested on the Spider benchmark and Spider Realistic, which removes explicit column hints to better simulate real-world usage.

Performance of various prompting methods across different difficulty levels on the Spider Dev and Spider Realistic datasets.

As shown in the results table, QDecomp + InterCOL emerged as the superior strategy:

  • Accuracy: It achieved a 5.2 point absolute gain in Test Suite (TS) accuracy on the Spider development set and a 5.5 to 6.5 point gain on Spider Realistic compared to standard prompting.
  • Efficiency: It outperformed the iterative Least-to-Most method while being significantly faster and cheaper, as it requires only a single model pass instead of multiple sequential calls.
  • Complexity Handling: The gains were most pronounced on "Hard" and "Extra Hard" queries, where structural decomposition is most necessary.

Conclusion

This research demonstrates that for Text-to-SQL, effective prompting relies on structural decomposition and explicit schema linking rather than verbose logical explanations. By using a single-pass QDecomp + InterCOL approach, developers can achieve higher accuracy and better grounding in real-world database environments. Future work may involve exploring these techniques on more recent models like GPT-4 and incorporating actual database content to further refine schema linking.

Summary updated

BibTeX
@misc{tai2023exploring,
  author = {Chang-You Tai and Ziru Chen and Tianshu Zhang and Xiang Deng and Huan Sun},
  title = {{Exploring Chain-of-Thought Style Prompting for Text-to-SQL}},
  year = {2023},
  eprint = {2305.14215},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2305.14215},
}
Figure