STaR-SQL: Self-Taught Reasoner for Text-to-SQL

Mingqian He, Yongliang Shen, Wenqi Zhang, Qiuying Peng, Jun Wang, Weiming Lu

Abstract

Text-to-SQL generation is traditionally treated as a direct translation task, often requiring complex prompt engineering or massive context windows. STaR-SQL reframes this as a multi-step reasoning task. By iteratively fine-tuning models on self-generated "chain-of-thought" rationales and employing an outcome-supervised reward model, STaR-SQL achieves a record-breaking 86.6% execution accuracy on the Spider benchmark, significantly outperforming larger models like GPT-4.

Introduction

Translating natural language into SQL (Text-to-SQL) is a cornerstone of accessible data analysis. However, complex multi-table schemas often baffle standard models. Current state-of-the-art (SOTA) approaches typically rely on "agentic" prompt engineering, which suffers from context bloat (consuming thousands of tokens), high sensitivity in smaller models, and a lack of transparency—the "Black Box" gap.

STaR-SQL addresses these issues by treating Large Language Models (LLMs) as reasoners rather than simple instruction-followers. Instead of jumping straight to code, the model systematically breaks down the problem into logical steps.

Methodology: The STaR-SQL Framework

The STaR-SQL framework adapts the "Self-Taught Reasoner" (STaR) approach to the structured domain of SQL through three primary pillars:

  1. Iterative Self-Improvement: The model generates a step-by-step rationale (Chain-of-Thought) before the final SQL. Successful rationales (those producing correct SQL) are added to a growing fine-tuning set, allowing the model to learn from its own logic.
  2. Hint-based Bootstrapping: To solve "Extra Hard" queries where the model might initially fail, the correct SQL is provided as a "hint." The model then reasons backward to generate a valid rationale, preventing "tail narrowing" where the model only improves on easy tasks.
  3. Outcome-supervised Reward Model (ORM): A separate verifier (Llama-3.1-8B) is trained to predict the success probability of a rationale. During inference, Best-of-N sampling is used: the model generates multiple candidates, and the ORM selects the highest-scoring one.
The STaR-SQL pipeline: Iterative fine-tuning, rationale generation, and test-time verification.

Evaluation and Results

The model was evaluated on the Spider benchmark, a standard for cross-domain Text-to-SQL tasks involving 200 complex databases.

Key Performance Metrics

STaR-SQL achieved a state-of-the-art 86.6% execution accuracy on the Spider development set. This marks a 31.6% improvement over a few-shot Llama-3.1-8B baseline and a 4.9% lead over GPT-4-based DAIL-SQL.

Execution accuracy across difficulty levels, highlighting STaR-SQL's robustness in Hard and Extra Hard queries.

The Power of Reasoning

The results highlight that allocating computational budget to thinking (generating rationales) is more effective than expanding instructions (complex prompts). Performance scales remarkably with test-time compute; by generating 16 candidates and using the ORM, accuracy jumped from 75% to 86.6%. Furthermore, the generated rationales (e.g., "# Step 1: Scan the 'concert' table...") provide much-needed transparency for non-expert users.

Conclusion and Future Directions

STaR-SQL demonstrates that reasoning-driven fine-tuning can enable smaller open-source models to surpass the performance of massive, prompt-engineered closed models. Future work will explore more sophisticated schema encoding and Process-supervised Reward Models (PRMs) to grade individual reasoning steps, potentially enabling advanced search techniques like Monte Carlo Tree Search (MCTS) for even more complex database queries.

Summary updated

BibTeX
@inproceedings{he2025star,
  author = {Mingqian He and Yongliang Shen and Wenqi Zhang and Qiuying Peng and Jun Wang and Weiming Lu},
  title = {{STaR-SQL: Self-Taught Reasoner for Text-to-SQL}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure