Learning When to Reason for Text-to-SQL via SFT and DPO

Soohyuk Jang, Jiheum Yeom, Nohil Park, Sang Hun Kim, Yoonyoung Choi, Kiwook Bae, Sungroh YoonarXiv 2026

TL;DR

AutoThinkSQL introduces an adaptive "auto-thinking" framework for Text-to-SQL tasks, enabling large language models (LLMs) to dynamically choose whether to invoke deep Chain-of-Thought (CoT) reasoning or bypass it for simple queries. By combining rollout-based Supervised Fine-Tuning (SFT) and Direct Preference Optimization (DPO), the method matches or exceeds the accuracy of heavy reasoning baselines while slashing average output tokens by up to 24.6% and latency by up to 17.1%.

What Problem Does This Paper Address?

State-of-the-art Text-to-SQL systems heavily rely on reasoning paradigms like Chain-of-Thought (CoT) to bridge the semantic gap between natural language questions and complex database schemas. While CoT yields massive accuracy gains on difficult benchmarks, it introduces a major inference-time bottleneck.

In real-world applications, a large portion of user queries are simple lookups or single-table aggregations that do not require multi-step deduction. Forcing an LLM to generate verbose reasoning traces for these trivial tasks wastes computational budgets, increases latency, and can even introduce syntactic noise or hallucinations. To date, fine-tuning approaches have forced a "one-size-fits-all" reasoning strategy regardless of query difficulty. This paper addresses the challenge of teaching an LLM when to think, reserving deep reasoning strictly for complex queries.

Methods

The authors propose AutoThinkSQL, a two-stage training pipeline consisting of Auto-thinking SFT and Auto-thinking DPO.

  1. Auto-thinking SFT: For each training instance, the framework executes 16 independent rollouts under a No-CoT prompt and 16 under a CoT prompt. If the No-CoT mode answers correctly all 16 times, the query is deemed "easy" and labeled for No-CoT generation. If No-CoT fails but CoT succeeds, it is labeled for CoT. The model is then fine-tuned using a unified "auto-thinking" prompt that instructs the model to first evaluate query complexity before generating the final SQL.
Figure 5: Auto-thinking format instruction.
  1. Auto-thinking DPO: To further refine this behavior, preference pairs are constructed from new rollouts generated by the SFT model. Crucially, if a query is trivially solvable ($N_{NC} = 16$), the No-CoT response is explicitly preferred over the CoT response. This penalizes the model for over-thinking and wasting tokens on easy tasks.

Datasets

  • Training: The SFT and DPO datasets were constructed using the BIRD training set (9,428 samples).
  • Evaluation: The framework was evaluated on the development sets of Spider (1,034 samples, cross-domain with balanced difficulty) and BIRD (1,534 samples, featuring realistic queries, external knowledge requirements, and heavy difficulty skew).

Key Insights and Ideas

  • Empirical Difficulty Mapping: Instead of relying on human-annotated difficulty levels, AutoThinkSQL determines query complexity empirically based on how reliably the model solves the query without reasoning during multiple rollouts.
  • The Pitfalls of Single-Mode Training: Forcing a model to always use CoT or always skip it introduces decoding-dependent flaws. No-CoT models lack the token diversity needed to benefit from majority voting (Maj@8), while CoT-only models can become unstable under greedy decoding after preference alignment.
  • Emergent Monotonic Routing: Without explicit difficulty tokens, the fine-tuned model naturally learns a monotonic routing behavior: as the objective difficulty of the benchmark queries increases, the model's self-selected No-CoT rate decreases, and its CoT rate rises.
Figure 1: Comparison of Chain-of-Thought (CoT) and No-CoT trigger rates on the Spider (Yu et al., 2018) benchmark across different difficulty levels. The rates were calculated by generating 8 independent responses for each question.

Key Results

Evaluated on the Qwen3-Coder-30B-A3B backbone, AutoThinkSQL achieved strong performance across both benchmarks and decoding regimes:

  • Efficiency Gains: Compared to the CoT-only baseline, AutoThinkSQL SFT+DPO reduced average output tokens by 24.6% on Spider and 18.3% on BIRD, translating to a latency reduction of 17.1% and 11.5%, respectively.
  • Execution Accuracy: AutoThinkSQL achieved the highest execution accuracy in three out of four evaluation settings, notably outperforming the CoT-only baseline in greedy decoding on Spider (86.20 vs 69.14) and BIRD (58.23 vs 54.02).
Table 1: Performance comparison of different models on the Spider and BIRD development sets. Both Greedy and Maj@8 decoding results are reported (mean±std over 3 runs). The best and second-best results per col- umn are shown in bold and underlined, respectively.

Limitations and Future Work

The authors note several limitations and areas for future exploration:

  • Dialect and Benchmark Scope: The evaluation was limited to Spider and BIRD; future work should explore newer enterprise-level benchmarks like Spider 2.0 or BIRD-CRITIC.
  • Compute-Heavy Data Prep: Generating 16 rollouts per instance for data labeling is computationally expensive. Developing lightweight heuristics to determine query complexity at scale remains an open challenge.
  • Model Generalization: The current study focused exclusively on the Qwen3-Coder family, leaving cross-family generalization to other code-LLMs (like DeepSeek-Coder) untested.
  • Risk of Under-thinking: If the model incorrectly classifies a hard query as simple, it will bypass CoT, reducing the interpretability of the output and making errors harder for humans to diagnose.

Summary updated

BibTeX
@misc{jang2026learning,
  author = {Soohyuk Jang and Jiheum Yeom and Nohil Park and Sang Hun Kim and Yoonyoung Choi and Kiwook Bae and Sungroh Yoon},
  title = {{Learning When to Reason for Text-to-SQL via SFT and DPO}},
  year = {2026},
  eprint = {2607.22622},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2607.22622},
}
Figure