Learning When to Reason for Text-to-SQL via SFT and DPO
Summary
Proposes AutoThinkSQL, a framework that integrates an auto-thinking mechanism into SFT and DPO for Text-to-SQL, enabling the model to dynamically skip reasoning for simple queries and invoke deep CoT for complex ones, achieving gains on Spider and BIRD benchmarks while reducing output tokens by 24.6% and latency by 17.1%.
View Cached Full Text
Cached at: 07/28/26, 06:27 AM
# Learning When to Reason for Text-to-SQL via SFT and DPO
Source: [https://arxiv.org/html/2607.22622](https://arxiv.org/html/2607.22622)
Soohyuk Jang1,Jiheum Yeom1,Nohil Park1, Sang Hun Kim2,Yoonyoung Choi2,Kiwook Bae2,Sungroh Yoon1,3
1Department of Electrical and Computer Engineering, Seoul National University 2AI Center, Samsung Electronics 3AIIS, ASRI, INMC, ISRC, and IPAI, Seoul National University \{soohyuk\.jang, quilava1234, pnoil2588, sryoon\}@snu\.ac\.kr \{phd\.kim, yy45\.choi, kiwook\.bae\}@samsung\.com
###### Abstract
Recent Text\-to\-SQL methods rely heavily on reasoning\-centric paradigms such as Chain\-of\-Thought \(CoT\), achieving substantial gains on complex benchmarks at the cost of high inference\-time overhead\. However, a large fraction of real\-world queries are simple lookups or aggregations that can be resolved without multi\-step deduction, making forced reasoning wasteful\. Thus, we proposeAutoThinkSQL, a framework that integrates an auto\-thinking mechanism into both Supervised Fine\-Tuning \(SFT\) and Direct Preference Optimization \(DPO\) on Text\-to\-SQL\. Our approach enables the model to dynamically bypass reasoning for simple queries while invoking deep CoT for complex queries\. On Qwen3\-Coder\-30B\-A3B, our method achieves consistent gains compared to the best counterpart baseline on both Spider and BIRD benchmarks while simultaneously reducing average output tokens by 24\.6% and 18\.3%, and average latency by 17\.1% and 11\.5% compared to CoT\-only generation\. Further analysis indicates that the model learns to align its reasoning decisions with query difficulty\.
Learning When to Reason for Text\-to\-SQL via SFT and DPO
Soohyuk Jang1, Jiheum Yeom1, Nohil Park1,Sang Hun Kim2,Yoonyoung Choi2,Kiwook Bae2,Sungroh Yoon1,3††thanks:Corresponding author\.1Department of Electrical and Computer Engineering, Seoul National University2AI Center, Samsung Electronics3AIIS, ASRI, INMC, ISRC, and IPAI, Seoul National University\{soohyuk\.jang, quilava1234, pnoil2588, sryoon\}@snu\.ac\.kr\{phd\.kim, yy45\.choi, kiwook\.bae\}@samsung\.com
## 1Introduction
Text\-to\-SQL translates natural language questions into executable SQL queries, providing an intuitive interface for relational databases\(Liet al\.,[2025](https://arxiv.org/html/2607.22622#bib.bib29),[2024](https://arxiv.org/html/2607.22622#bib.bib30); Pourreza and Rafiei,[2023](https://arxiv.org/html/2607.22622#bib.bib1); Liuet al\.,[2025](https://arxiv.org/html/2607.22622#bib.bib23); Huiet al\.,[2024](https://arxiv.org/html/2607.22622#bib.bib19)\)\. While Large Language Models \(LLMs\) have driven significant advancements in this field, recent state\-of\-the\-art methods heavily rely on reasoning\-centric learning paradigms, driven by Reinforcement Learning \(RL\)\(Yaoet al\.,[2025](https://arxiv.org/html/2607.22622#bib.bib24); Maet al\.,[2026](https://arxiv.org/html/2607.22622#bib.bib25); Pourrezaet al\.,[2025b](https://arxiv.org/html/2607.22622#bib.bib31)\)and Chain\-of\-Thought \(CoT\) prompting\(Pourreza and Rafiei,[2023](https://arxiv.org/html/2607.22622#bib.bib1)\)\. By explicitly generating intermediate logical steps, these approaches effectively bridge the semantic gap between complex user intents and intricate database schemas, yielding substantial accuracy gains on challenging benchmarks\(Pourrezaet al\.,[2025b](https://arxiv.org/html/2607.22622#bib.bib31); Yaoet al\.,[2025](https://arxiv.org/html/2607.22622#bib.bib24); Maet al\.,[2026](https://arxiv.org/html/2607.22622#bib.bib25)\)\.
However, this reliance on verbose reasoning traces introduces a critical inference\-time bottleneck\. This is particularly problematic given that a substantial fraction of real\-world Text\-to\-SQL queries are simple lookups or single\-table aggregations that can be resolved through straightforward schema linking\(Yuet al\.,[2018](https://arxiv.org/html/2607.22622#bib.bib20); Liet al\.,[2023](https://arxiv.org/html/2607.22622#bib.bib21)\)\. Compelling a model to produce extensive reasoning traces for such queries not only wastes inference budget but can also introduce syntactic noise and hallucinations\(Liuet al\.,[2025](https://arxiv.org/html/2607.22622#bib.bib23); Spragueet al\.,[2025](https://arxiv.org/html/2607.22622#bib.bib27)\)\. This motivates a training strategy that retains CoT’s accuracy benefits on complex queries while avoiding its inference cost on simpler ones\.
To address this, we introduceAutoThinkSQL, a novel framework that integrates an adaptive auto\-thinking\(Louet al\.,[2025](https://arxiv.org/html/2607.22622#bib.bib11); Tuet al\.,[2026](https://arxiv.org/html/2607.22622#bib.bib14)\)mechanism into the Text\-to\-SQL domain\. Our approach equips LLM with the intrinsic ability to bypass CoT for simple queries and reserve it strictly for complex reasoning tasks\. We implement this through a two\-stage training pipeline of SFT and DPO\(Rafailovet al\.,[2023](https://arxiv.org/html/2607.22622#bib.bib32)\)\. Evaluated on Qwen3\-Coder\-30B\-A3B\(Qwen Team,[2025](https://arxiv.org/html/2607.22622#bib.bib22)\), our auto\-thinking SFT consistently surpasses the execution accuracy of its CoT\-only counterpart across most settings, while significantly reducing the average number of inference tokens and latency\.
Our primary contributions are threefold:
- •Consistent gains\.AutoThinkSQL achieves strong performance across both Spider and BIRD under both decoding regimes, while single\-mode baselines each show a clear weakness in at least one setting\.
- •Inference efficiency\.AutoThinkSQL reduces average output tokens by 24\.6% on Spider and 18\.3% on BIRD, and average latency by 17\.1% on Spider and 11\.5% on BIRD, compared to the CoT\-only \(SFT\+DPO\) counterpart, substantially lowering inference\-time cost without sacrificing accuracy\.
- •Routing analysis\.We analyze the model’s reasoning activation patterns and verify that AutoThinkSQL adaptively routes queries according to difficulty, confirming that the efficiency gains reflect meaningful behavioral alignment with query complexity\.
## 2Related Work
Prior work on LLM\-based Text\-to\-SQL falls into two broad categories\. One line leverages proprietary LLMs without parameter updates through prompt engineering and inference\-time reasoning, including schema\-linking decomposition\(Pourreza and Rafiei,[2023](https://arxiv.org/html/2607.22622#bib.bib1)\), in\-context example selection\(Gaoet al\.,[2024](https://arxiv.org/html/2607.22622#bib.bib2)\), multi\-agent collaboration\(Wanget al\.,[2025](https://arxiv.org/html/2607.22622#bib.bib4); Talaeiet al\.,[2024](https://arxiv.org/html/2607.22622#bib.bib5)\), and multi\-path candidate selection\(Pourrezaet al\.,[2025a](https://arxiv.org/html/2607.22622#bib.bib6)\)\. The other fine\-tunes open\-source LLMs to close the gap with proprietary models, ranging from incremental pre\-training\(Liet al\.,[2024](https://arxiv.org/html/2607.22622#bib.bib30)\)and large\-scale synthetic SFT\(Liet al\.,[2025](https://arxiv.org/html/2607.22622#bib.bib29)\)to DPO\-based alignment\(Yanget al\.,[2024](https://arxiv.org/html/2607.22622#bib.bib7)\)and RL with reasoning traces\(Pourrezaet al\.,[2025b](https://arxiv.org/html/2607.22622#bib.bib31)\)\. Despite their effectiveness, these fine\-tuning approaches force chain\-of\-thought reasoning regardless of query difficulty, inflating the inference\-time token budget even on queries that could be resolved without multi\-step deduction\.
A parallel line of work on adaptive reasoning trains models to decide when to invoke CoT, using either SFT followed by PPO\(Louet al\.,[2025](https://arxiv.org/html/2607.22622#bib.bib11); Schulmanet al\.,[2017](https://arxiv.org/html/2607.22622#bib.bib28)\)or GRPO\-based RL\(Zhanget al\.,[2025](https://arxiv.org/html/2607.22622#bib.bib12); Fanget al\.,[2026](https://arxiv.org/html/2607.22622#bib.bib13); Tuet al\.,[2026](https://arxiv.org/html/2607.22622#bib.bib14)\)\. However, these methods usually target math and general reasoning, and to our knowledge no prior work has trained Text\-to\-SQL models to adaptively decide when to reason\. As a closest related attempt,Taiet al\.\([2023](https://arxiv.org/html/2607.22622#bib.bib15)\)observed that detailed reasoning can amplify errors on simpler SQL queries, but provided only a prompting\-level fix without addressing it during training\.
## 3Methodology
### 3\.1Problem Formulation
Given a natural language question, a database schema, and external knowledge, the Text\-to\-SQL task aims to generate a valid SQL query\.
We denote the input comprising all three asxx\(Figure[2](https://arxiv.org/html/2607.22622#A3.F2)\), and introduce mode\-specific format promptspmp\_\{m\}that govern the output structure\. Specifically,pNCp\_\{\\text\{NC\}\}instructs the model to generate SQL directly without reasoning \(Figure[4](https://arxiv.org/html/2607.22622#A5.F4)\),pCp\_\{\\text\{C\}\}requires step\-by\-step reasoning prior to the final SQL \(Figure[3](https://arxiv.org/html/2607.22622#A3.F3)\), andpAutop\_\{\\text\{Auto\}\}instructs the model to first assess query complexity and then either generate SQL directly or produce a reasoning chain before the SQL \(Figure[5](https://arxiv.org/html/2607.22622#A5.F5)\)\. Givenxxand a promptpmp\_\{m\}, the model produces a responseymy\_\{m\}, i\.e\.,\(x,pm\)→ym\(x,p\_\{m\}\)\\rightarrow y\_\{m\}\.
### 3\.2Auto\-thinking SFT
#### Data Construction\.
For each BIRD training instancexx, we execute1616independent rollouts under each mode\-specific format prompt:\(x,pNC\)\(x,p\_\{\\text\{NC\}\}\)yields\{yNC\(i\)\}i=116\\\{y\_\{\\text\{NC\}\}^\{\(i\)\}\\\}\_\{i=1\}^\{16\}and\(x,pC\)\(x,p\_\{\\text\{C\}\}\)yields\{yC\(i\)\}i=116\\\{y\_\{\\text\{C\}\}^\{\(i\)\}\\\}\_\{i=1\}^\{16\}\. LetNCN\_\{\\text\{C\}\}andNNCN\_\{\\text\{NC\}\}denote the number of correct outputs under each mode\. The training modem∗m^\{\*\}is assigned as follows:
m∗=\{NCifNNC=16CifNNC<16∧NC\>0Discardotherwisem^\{\*\}=\\begin\{cases\}\\text\{NC\}&\\text\{if \}N\_\{\\text\{NC\}\}=16\\\\ \\text\{C\}&\\text\{if \}N\_\{\\text\{NC\}\}<16\\wedge N\_\{\\text\{C\}\}\>0\\\\ \\text\{Discard\}&\\text\{otherwise\}\\end\{cases\}For each labeled instance, one correct rollout is uniformly sampled from modem∗m^\{\*\}, yieldingym∗y\_\{m^\{\*\}\}\. The pair\(\(x,pAuto\),ym∗\)\(\(x,\\,p\_\{\\text\{Auto\}\}\),\\,y\_\{m^\{\*\}\}\)is then added to𝒟SFT\\mathcal\{D\}\_\{\\text\{SFT\}\}\. Although rollouts are collected underpNCp\_\{\\text\{NC\}\}andpCp\_\{\\text\{C\}\}, the SFT input is always composed withpAutop\_\{\\text\{Auto\}\}, so the model learns to autonomously produce the appropriate output style\.
#### Training Objective\.
The model is fine\-tuned by minimizing the standard negative log\-likelihood over𝒟SFT\\mathcal\{D\}\_\{\\text\{SFT\}\}:
ℒSFT\(θ\)=\\displaystyle\\mathcal\{L\}\_\{\\text\{SFT\}\}\(\\theta\)=−𝔼\(\(x,pAuto\),y\)∼𝒟SFT\\displaystyle\-\\mathbb\{E\}\_\{\(\(x,p\_\{\\text\{Auto\}\}\),y\)\\sim\\mathcal\{D\}\_\{\\text\{SFT\}\}\}∑t=1\|y\|logpθ\(yt∣x,pAuto,y<t\)\\displaystyle\\sum\_\{t=1\}^\{\|y\|\}\\log p\_\{\\theta\}\(y\_\{t\}\\mid x,p\_\{\\text\{Auto\}\},y\_\{<t\}\)whereyyis the target output trajectory, which may include a reasoning chain followed by the SQL query\.
### 3\.3Auto\-thinking DPO
#### Data Construction\.
Using the SFT\-trained model, we collect1616new rollouts per mode under the same prompts\(pNC,pC\)\(p\_\{\\text\{NC\}\},\\,p\_\{\\text\{C\}\}\)as in Section[3\.2](https://arxiv.org/html/2607.22622#S3.SS2)\. Letym\+y\_\{m\}^\{\+\}andym−y\_\{m\}^\{\-\}denote a uniformly sampled chosen and rejected response from modem∈\{C,NC\}m\\in\\\{\\text\{C\},\\text\{NC\}\\\}, respectively\. Preference pairs\(yw,yl\)\(y\_\{w\},y\_\{l\}\)are assigned according to the following mutually exclusive, exhaustive rule:
\(yw,yl\)=\{DiscardifNC=0∧NNC=0\(yNC\+,yC−\)ifNNC=16∧NC<16\(yNC\+,yC\+\)ifNNC=16∧NC=16\(ym\+,ym−\),m∼Unif\(\{C,NC\}\)if0<NC=NNC<16\(yNC\+,yC−\)ifNC<NNC<16\(yC\+,yNC−\)ifNNC<NC\\displaystyle\(y\_\{w\},\\,y\_\{l\}\)=\\begin\{cases\}\\text\{Discard\}&\\text\{if \}N\_\{\\text\{C\}\}=0\\wedge N\_\{\\text\{NC\}\}=0\\\\\[2\.0pt\] \\bigl\(y\_\{\\text\{NC\}\}^\{\+\},\\;y\_\{\\text\{C\}\}^\{\-\}\\bigr\)&\\text\{if \}N\_\{\\text\{NC\}\}=16\\wedge N\_\{\\text\{C\}\}<16\\\\\[2\.0pt\] \\bigl\(y\_\{\\text\{NC\}\}^\{\+\},\\;y\_\{\\text\{C\}\}^\{\+\}\\bigr\)&\\text\{if \}N\_\{\\text\{NC\}\}=16\\wedge N\_\{\\text\{C\}\}=16\\\\\[2\.0pt\] \\begin\{aligned\} &\\bigl\(y\_\{m\}^\{\+\},\\;y\_\{m\}^\{\-\}\\bigr\),\\\\ &\\quad m\\sim\\mathrm\{Unif\}\(\\\{\\text\{C\},\\text\{NC\}\\\}\)\\end\{aligned\}&\\text\{if \}0<N\_\{\\text\{C\}\}=N\_\{\\text\{NC\}\}<16\\\\\[2\.0pt\] \\bigl\(y\_\{\\text\{NC\}\}^\{\+\},\\;y\_\{\\text\{C\}\}^\{\-\}\\bigr\)&\\text\{if \}N\_\{\\text\{C\}\}<N\_\{\\text\{NC\}\}<16\\\\\[2\.0pt\] \\bigl\(y\_\{\\text\{C\}\}^\{\+\},\\;y\_\{\\text\{NC\}\}^\{\-\}\\bigr\)&\\text\{if \}N\_\{\\text\{NC\}\}<N\_\{\\text\{C\}\}\\end\{cases\}
WhenNNC=16N\_\{\\text\{NC\}\}=16, the No\-CoT response is set asywy\_\{w\}to discourage unnecessary reasoning on trivially solvable queries\. Each accepted preference pair\(\(x,pAuto\),yw,yl\)\(\(x,\\,p\_\{\\text\{Auto\}\}\),\\,y\_\{w\},\\,y\_\{l\}\)is added to𝒟DPO\\mathcal\{D\}\_\{\\text\{DPO\}\}\.
#### Training Objective\.
The model is further optimized using the standard DPO objective over𝒟DPO\\mathcal\{D\}\_\{\\text\{DPO\}\}:
ℒDPO\(θ\)=−𝔼𝒟DPOlogσ\(\\displaystyle\\mathcal\{L\}\_\{\\text\{DPO\}\}\(\\theta\)=\-\\mathbb\{E\}\_\{\\mathcal\{D\}\_\{\\text\{DPO\}\}\}\\log\\sigma\\Big\(βlogpθ\(yw∣x,pAuto\)pref\(yw∣x,pAuto\)\\displaystyle\\beta\\log\\tfrac\{p\_\{\\theta\}\(y\_\{w\}\\mid x,p\_\{\\text\{Auto\}\}\)\}\{p\_\{\\text\{ref\}\}\(y\_\{w\}\\mid x,p\_\{\\text\{Auto\}\}\)\}−βlogpθ\(yl∣x,pAuto\)pref\(yl∣x,pAuto\)\)\\displaystyle\-\\beta\\log\\tfrac\{p\_\{\\theta\}\(y\_\{l\}\\mid x,p\_\{\\text\{Auto\}\}\)\}\{p\_\{\\text\{ref\}\}\(y\_\{l\}\\mid x,p\_\{\\text\{Auto\}\}\)\}\\Big\)whereprefp\_\{\\text\{ref\}\}is the frozen SFT reference policy andβ\\betacontrols deviation from the reference\.
## 4Experiments
### 4\.1Experimental Setup
#### Models\.
We conduct experiments on Qwen3\-Coder\-30B\-A3B\-Instruct111[huggingface\.co/Qwen/Qwen3\-Coder\-30B\-A3B\-Instruct](https://huggingface.co/Qwen/Qwen3-Coder-30B-A3B-Instruct)Qwen Team \([2025](https://arxiv.org/html/2607.22622#bib.bib22)\), a Mixture\-of\-Experts model with 30B total and 3B activated parameters, as our backbone\. All fine\-tuning is performed with LoRA\(Huet al\.,[2022](https://arxiv.org/html/2607.22622#bib.bib34)\); full training details are in Appendix[A](https://arxiv.org/html/2607.22622#A1)\.
#### Training Data\.
We construct our SFT and DPO datasets from the BIRD\(Liet al\.,[2023](https://arxiv.org/html/2607.22622#bib.bib21)\)training set which consists 9428 samples following the mode labeling procedure described in Sections[3\.2](https://arxiv.org/html/2607.22622#S3.SS2)and[3\.3](https://arxiv.org/html/2607.22622#S3.SS3)\. For the database prompt construction, we adopt the preprocessed schema format fromLiuet al\.\([2025](https://arxiv.org/html/2607.22622#bib.bib23)\), which follows the CodeS\(Liet al\.,[2024](https://arxiv.org/html/2607.22622#bib.bib30)\)pipeline\. Detailed information on the schema preprocessing procedure and dataset statistics are provided in Appendix[B](https://arxiv.org/html/2607.22622#A2)\(Table[3](https://arxiv.org/html/2607.22622#A2.T3), Table[4](https://arxiv.org/html/2607.22622#A2.T4)\)\.
#### Evaluation Benchmarks\.
We evaluate on Spider\(Yuet al\.,[2018](https://arxiv.org/html/2607.22622#bib.bib20)\), a cross\-domain benchmark with queries spanning four difficulty levels, and BIRD\(Liet al\.,[2023](https://arxiv.org/html/2607.22622#bib.bib21)\), which targets more realistic queries requiring external knowledge and exhibits heavier difficulty skew\.
#### Evaluation Metric\.
We reportExecution Accuracy\(EX\), the standard Text\-to\-SQL metric measuring the percentage of queries whose execution results match the gold SQL\.
#### Decoding Strategy\.
We evaluate each model under two decoding settings\.Greedy decodingselects the most probable token at each step\.Majority voting at 8\(Maj@8\) generates 8 independent outputs using sampling \(temperature=1\.0=1\.0\) and selects the final answer by majority vote over the resulting SQL execution outcomes\.
Table 1:Performance comparison of different models on the Spider and BIRD development sets\. Both Greedy and Maj@8 decoding results are reported \(mean±\\pmstd over 3 runs\)\. The best and second\-best results per column are shown inboldandunderlined, respectively\.#### Baselines\.
We compare AutoThinkSQL SFT and AutoThinkSQL SFT\+DPO \(ours\) against five baselines:Zero\-shot, the base Qwen3\-Coder\-30B\-A3B\-InstructQwen Team \([2025](https://arxiv.org/html/2607.22622#bib.bib22)\)model; andCoT\-onlyandNo\-CoT\-onlyvariants under both SFT and SFT\+DPO, which are trained to always generate or always skip a reasoning trace, respectively\. Full training hyperparameters are provided in Appendix[A](https://arxiv.org/html/2607.22622#A1)\. The prompt templates used for all training and evaluation are provided in Appendix[C](https://arxiv.org/html/2607.22622#A3)\.
### 4\.2Main Results
Table[4\.1](https://arxiv.org/html/2607.22622#S4.SS1.SSS0.Px5)reports Execution Accuracy on SpiderYuet al\.\([2018](https://arxiv.org/html/2607.22622#bib.bib20)\)and BIRDLiet al\.\([2023](https://arxiv.org/html/2607.22622#bib.bib21)\)dev sets consisting of 1034 and 1534 samples respectively across all baselines and our proposed methods, averaged over three runs with standard deviations\.
#### AutoThinkSQL performs strongly across most settings\.
AutoThinkSQL SFT\+DPO records the highest execution accuracy in three of four evaluation settings: Spider Greedy \(86\.20\), BIRD Greedy \(58\.23\), and BIRD Maj@8 \(60\.27\)\. On Spider Maj@8, AutoThinkSQL SFT\+DPO reaches 86\.78, which is0\.290\.29points behind CoT\-only SFT \(87\.07\), a gap within one standard deviation\. At the SFT stage alone, AutoThinkSQL already outperforms or matches both single\-mode baselines, ranking first or second across all evaluated settings\.
#### Single\-mode training reveals decoding\-dependent limitations\.
No\-CoT\-only SFT yields moderate gains under greedy decoding on both benchmarks \(Spider:83\.8183\.81, BIRD:56\.9156\.91\), yet its Maj@8 scores lag noticeably behind CoT\-only SFT by2\.872\.87points on Spider and2\.012\.01on BIRD, as the lack of reasoning diversity limits the benefit of majority voting\. CoT\-only SFT shows the opposite pattern, achieving the highest Maj@8 on Spider \(87\.0787\.07\) but becoming less stable on greedy decoding once DPO is applied on top\. These contrasting behaviors suggest that committing to a single reasoning mode makes it difficult to remain competitive across both decoding regimes\. In contrast, AutoThinkSQL outperforms the best counterpart among baselines on both Spider and Bird in most cases, demonstrating consistent gains across both benchmarks\.
#### AutoThinkSQL generalizes consistently across benchmarks\.
While single\-mode baselines each exhibit a clear weakness under at least one evaluation setting, AutoThinkSQL improves consistently under both greedy and Maj@8 decoding, and on both Spider, which has a relatively balanced difficulty distribution, and BIRD, which contains heavier difficulty skew and requires external knowledge\.
Table 2:Inference efficiency comparison on Spider and BIRD development sets \(mean±\\pmstd over 3 runs\)\.Lat\.denotes average latency \(ms\) per problem, andTok\.denotes average output tokens per generation\.### 4\.3Analysis
We analyze the inference cost savings enabled by auto\-thinking \(Table[4\.2](https://arxiv.org/html/2607.22622#S4.SS2.SSS0.Px3)\) and verify that routing behavior aligns with query difficulty \(Figure[1](https://arxiv.org/html/2607.22622#S4.F1)\)\.
#### AutoThinkSQL substantially reduces inference cost\.
Compared to CoT\-only SFT, AutoThinkSQL SFT reduces average output tokens by 21\.0% on Spider and 14\.7% on BIRD, while matching or exceeding its accuracy\. AutoThinkSQL SFT\+DPO uses 24\.9% fewer tokens on Spider and 18\.1% fewer on BIRD than CoT\-only SFT\+DPO, with latency following the same trend\.
Figure 1:Comparison of Chain\-of\-Thought \(CoT\) and No\-CoT trigger rates on the SpiderYuet al\.\([2018](https://arxiv.org/html/2607.22622#bib.bib20)\)benchmark across different difficulty levels\. The rates were calculated by generating 8 independent responses for each question\.
#### Routing aligns with query difficulty\.
Figure[1](https://arxiv.org/html/2607.22622#S4.F1)reports the CoT trigger rate of AutoThinkSQL across Spider’s four difficulty levels \(Easy, Medium, Hard, Extra Hard\) as defined byYuet al\.\([2018](https://arxiv.org/html/2607.22622#bib.bib20)\), computed over 8 independent samples per query\. Both AutoThinkSQL SFT and SFT\+DPO show a consistent monotonic trend: as query difficulty increases, the No\-CoT rate decreases and the CoT rate rises correspondingly, confirming that the model allocates reasoning effort in accordance with query complexity\. A zero\-shot baseline applying our auto\-thinking prompt \(Figure[5](https://arxiv.org/html/2607.22622#A5.F5)\) without fine\-tuning shows the same qualitative trend but at substantially lower CoT rates, indicating that the base model under\-invokes reasoning\.
## 5Conclusion
We proposed AutoThinkSQL, the first Text\-to\-SQL framework to integrate auto\-thinking into both SFT and DPO\. By learning when to invoke CoT, AutoThinkSQL matches or surpasses CoT\-only baselines on Spider and BIRD while substantially reducing inference cost, and remains robust under preference\-based alignment where single\-mode training degrades\. We leave extension to larger models and more diverse Text\-to\-SQL data as future work\.
## Limitations
In this work, our primary evaluation focuses on Spider and BIRD; we leave the exploration of other dialects, such as Spider 2\.0\(Leiet al\.,[2025](https://arxiv.org/html/2607.22622#bib.bib16)\)or BIRD\-CRITIC\(Liet al\.,[2026](https://arxiv.org/html/2607.22622#bib.bib17)\), as an avenue for future work\. For mode assignment, we employ rollout\-based supervision, which opens up opportunities for future research into more computationally lightweight heuristics at scale\. Lastly, we concentrate our current experiments on the Qwen3\-Coder family, paving the way for subsequent studies to examine cross\-family generalization to other code\-specialized LLMs like DeepSeek\-Coder\(Guoet al\.,[2024](https://arxiv.org/html/2607.22622#bib.bib18)\)\.
## Potential Risks
Like other Text\-to\-SQL systems, our model can generate incorrect SQL that, if executed without review, may cause unintended data access or modification in production databases\. An additional risk specific to our framework is that the auto\-thinking mechanism may bypass reasoning for queries it incorrectly deems simple, reducing the interpretability of the generated output and making errors harder to detect\. We recommend human review or sandboxed execution in deployment, particularly for high\-stakes use cases\.
## Acknowledgments
This work was supported by the National Research Foundation of Korea \(NRF\) grant funded by the Korea government \(MSIT\) \(No\. 2022R1A3B1077720\), the BK21 FOUR program of the Education and Research Program for Future ICT Pioneers, Seoul National University in 2026, Institute of Information & communications Technology Planning & Evaluation \(IITP\) grant funded by the Korea government\(MSIT\) \[No\.RS\-2021\-II211343, Artificial Intelligence Graduate School Program \(Seoul National University\), No\.2022\-0\-00959, RS\-2022\-II220959\], and Samsung Electronics Co\., Ltd \[IO250624\-13143\-01\]\.
## References
- G\. Fang, X\. Ma, and X\. Wang \(2026\)Thinkless: LLM learns when to think\.InThe Thirty\-ninth Annual Conference on Neural Information Processing Systems,External Links:[Link](https://openreview.net/forum?id=ariVQf0KZx)Cited by:[§2](https://arxiv.org/html/2607.22622#S2.p2.1)\.
- D\. Gao, H\. Wang, Y\. Li, X\. Sun, Y\. Qian, B\. Ding, and J\. Zhou \(2024\)Text\-to\-sql empowered by large language models: a benchmark evaluation\.Proc\. VLDB Endow\.17\(5\),pp\. 1132–1145\.External Links:ISSN 2150\-8097,[Link](https://doi.org/10.14778/3641204.3641221),[Document](https://dx.doi.org/10.14778/3641204.3641221)Cited by:[§2](https://arxiv.org/html/2607.22622#S2.p1.1)\.
- D\. Guo, Q\. Zhu, D\. Yang, Z\. Xie, K\. Dong, W\. Zhang, G\. Chen, X\. Bi, Y\. Wu, Y\. Li,et al\.\(2024\)DeepSeek\-coder: when the large language model meets programming–the rise of code intelligence\.arXiv preprint arXiv:2401\.14196\.Cited by:[§5](https://arxiv.org/html/2607.22622#Sx1.p1.1)\.
- E\. J\. Hu, yelong shen, P\. Wallis, Z\. Allen\-Zhu, Y\. Li, S\. Wang, L\. Wang, and W\. Chen \(2022\)LoRA: low\-rank adaptation of large language models\.InInternational Conference on Learning Representations,External Links:[Link](https://openreview.net/forum?id=nZeVKeeFYf9)Cited by:[Appendix A](https://arxiv.org/html/2607.22622#A1.SS0.SSS0.Px1.p1.9),[§4\.1](https://arxiv.org/html/2607.22622#S4.SS1.SSS0.Px1.p1.1)\.
- B\. Hui, J\. Yang, Z\. Cui, J\. Yang, D\. Liu, L\. Zhang, T\. Liu, J\. Zhang, B\. Yu, K\. Lu,et al\.\(2024\)Qwen2\.5\-coder technical report\.arXiv preprint arXiv:2409\.12186\.Cited by:[§1](https://arxiv.org/html/2607.22622#S1.p1.1)\.
- F\. Lei, J\. Chen, Y\. Ye, R\. Cao, D\. Shin, H\. SU, Z\. SUO, H\. Gao, W\. Hu, P\. Yin, V\. Zhong, C\. Xiong, R\. Sun, Q\. Liu, S\. Wang, and T\. Yu \(2025\)Spider 2\.0: evaluating language models on real\-world enterprise text\-to\-SQL workflows\.InThe Thirteenth International Conference on Learning Representations,External Links:[Link](https://openreview.net/forum?id=XmProj9cPs)Cited by:[§5](https://arxiv.org/html/2607.22622#Sx1.p1.1)\.
- H\. Li, S\. Wu, X\. Zhang, X\. Huang, J\. Zhang, F\. Jiang, S\. Wang, T\. Zhang, J\. Chen, R\. Shi, H\. Chen, and C\. Li \(2025\)OmniSQL: synthesizing high\-quality text\-to\-sql data at scale\.Proc\. VLDB Endow\.18\(11\),pp\. 4695–4709\.External Links:ISSN 2150\-8097,[Link](https://doi.org/10.14778/3749646.3749723),[Document](https://dx.doi.org/10.14778/3749646.3749723)Cited by:[§1](https://arxiv.org/html/2607.22622#S1.p1.1),[§2](https://arxiv.org/html/2607.22622#S2.p1.1)\.
- H\. Li, J\. Zhang, H\. Liu, J\. Fan, X\. Zhang, J\. Zhu, R\. Wei, H\. Pan, C\. Li, and H\. Chen \(2024\)CodeS: towards building open\-source language models for text\-to\-sql\.Proc\. ACM Manag\. Data2\(3\)\.External Links:[Link](https://doi.org/10.1145/3654930),[Document](https://dx.doi.org/10.1145/3654930)Cited by:[Appendix B](https://arxiv.org/html/2607.22622#A2.SS0.SSS0.Px1.p1.1),[§1](https://arxiv.org/html/2607.22622#S1.p1.1),[§2](https://arxiv.org/html/2607.22622#S2.p1.1),[§4\.1](https://arxiv.org/html/2607.22622#S4.SS1.SSS0.Px2.p1.1)\.
- J\. Li, B\. Hui, G\. Qu, J\. Yang, B\. Li, B\. Li, B\. Wang, B\. Qin, R\. Geng, N\. Huo,et al\.\(2023\)Can llm already serve as a database interface? a big bench for large\-scale database grounded text\-to\-sqls\.Advances in Neural Information Processing Systems36,pp\. 42330–42357\.Cited by:[Table 5](https://arxiv.org/html/2607.22622#A2.T5.1.1.4.3.1),[§1](https://arxiv.org/html/2607.22622#S1.p2.1),[§4\.1](https://arxiv.org/html/2607.22622#S4.SS1.SSS0.Px2.p1.1),[§4\.1](https://arxiv.org/html/2607.22622#S4.SS1.SSS0.Px3.p1.1),[§4\.2](https://arxiv.org/html/2607.22622#S4.SS2.p1.1)\.
- J\. Li, X\. Li, G\. Qu, P\. Jacobsson, B\. Qin, B\. Hui, S\. Si, N\. Huo, X\. Xu, Y\. Zhang, Z\. Tang, Y\. Li, F\. Widjaja, X\. Zhu, F\. Zhou, Y\. Huang, Y\. Papakonstantinou, F\. Ozcan, C\. Ma, and R\. Cheng \(2026\)SWE\-SQL: illuminating LLM pathways to solve user SQL issues in real\-world applications\.InThe Thirty\-ninth Annual Conference on Neural Information Processing Systems,External Links:[Link](https://openreview.net/forum?id=yRxXTdElLv)Cited by:[§5](https://arxiv.org/html/2607.22622#Sx1.p1.1)\.
- H\. Liu, H\. Li, X\. Zhang, R\. Chen, H\. Xu, T\. Tian, Q\. Qi, and J\. Zhang \(2025\)Uncovering the impact of chain\-of\-thought reasoning for direct preference optimization: lessons from text\-to\-sql\.InProceedings of the 63rd Annual Meeting of the Association for Computational Linguistics \(Volume 1: Long Papers\),pp\. 21223–21261\.Cited by:[Appendix B](https://arxiv.org/html/2607.22622#A2.SS0.SSS0.Px1.p1.1),[§1](https://arxiv.org/html/2607.22622#S1.p1.1),[§1](https://arxiv.org/html/2607.22622#S1.p2.1),[§4\.1](https://arxiv.org/html/2607.22622#S4.SS1.SSS0.Px2.p1.1)\.
- C\. Lou, Z\. Sun, X\. Liang, M\. Qu, W\. Shen, W\. Wang, Y\. Li, Q\. Yang, and S\. Wu \(2025\)Adacot: pareto\-optimal adaptive chain\-of\-thought triggering via reinforcement learning\.arXiv preprint arXiv:2505\.11896\.Cited by:[§1](https://arxiv.org/html/2607.22622#S1.p3.1),[§2](https://arxiv.org/html/2607.22622#S2.p2.1)\.
- P\. Ma, X\. Zhuang, C\. Xu, X\. Jiang, R\. Chen, and J\. Guo \(2026\)Sql\-r1: training natural language to sql reasoning model by reinforcement learning\.Advances in Neural Information Processing Systems38,pp\. 174505–174537\.Cited by:[§1](https://arxiv.org/html/2607.22622#S1.p1.1)\.
- M\. Pourreza, H\. Li, R\. Sun, Y\. Chung, S\. Talaei, G\. T\. Kakkar, Y\. Gan, A\. Saberi, F\. Ozcan, and S\. O\. Arik \(2025a\)CHASE\-SQL: multi\-path reasoning and preference optimized candidate selection in text\-to\-SQL\.InThe Thirteenth International Conference on Learning Representations,External Links:[Link](https://openreview.net/forum?id=CvGqMD5OtX)Cited by:[§2](https://arxiv.org/html/2607.22622#S2.p1.1)\.
- M\. Pourreza and D\. Rafiei \(2023\)DIN\-SQL: decomposed in\-context learning of text\-to\-SQL with self\-correction\.InThirty\-seventh Conference on Neural Information Processing Systems,External Links:[Link](https://openreview.net/forum?id=p53QDxSIc5)Cited by:[§1](https://arxiv.org/html/2607.22622#S1.p1.1),[§2](https://arxiv.org/html/2607.22622#S2.p1.1)\.
- M\. Pourreza, S\. Talaei, R\. Sun, X\. Wan, H\. Li, A\. Mirhoseini, A\. Saberi, and S\. O\. Arik \(2025b\)Reasoning\-SQL: reinforcement learning with SQL tailored partial rewards for reasoning\-enhanced text\-to\-SQL\.InSecond Conference on Language Modeling,External Links:[Link](https://openreview.net/forum?id=HbwkIDWQgN)Cited by:[§1](https://arxiv.org/html/2607.22622#S1.p1.1),[§2](https://arxiv.org/html/2607.22622#S2.p1.1)\.
- Qwen Team \(2025\)Qwen3\-coder: agentic coding in the world\.Note:[https://qwen\.ai/blog?id=qwen3\-coder](https://qwen.ai/blog?id=qwen3-coder)Accessed: 2026\-05\-18Cited by:[Table 5](https://arxiv.org/html/2607.22622#A2.T5.1.1.2.1.1),[§1](https://arxiv.org/html/2607.22622#S1.p3.1),[§4\.1](https://arxiv.org/html/2607.22622#S4.SS1.SSS0.Px1.p1.1),[§4\.1](https://arxiv.org/html/2607.22622#S4.SS1.SSS0.Px6.p1.1)\.
- R\. Rafailov, A\. Sharma, E\. Mitchell, C\. D\. Manning, S\. Ermon, and C\. Finn \(2023\)Direct preference optimization: your language model is secretly a reward model\.Advances in neural information processing systems36,pp\. 53728–53741\.Cited by:[§1](https://arxiv.org/html/2607.22622#S1.p3.1)\.
- J\. Schulman, F\. Wolski, P\. Dhariwal, A\. Radford, and O\. Klimov \(2017\)Proximal policy optimization algorithms\.arXiv preprint arXiv:1707\.06347\.Cited by:[§2](https://arxiv.org/html/2607.22622#S2.p2.1)\.
- Z\. Sprague, F\. Yin, J\. Rodriguez, D\. Jiang, M\. Wadhwa, P\. Singhal, X\. Zhao, X\. Ye, K\. Mahowald, and G\. Durrett \(2025\)To cot or not to cot? chain\-of\-thought helps mainly on math and symbolic reasoning\.InInternational Conference on Learning Representations,Vol\.2025,pp\. 94118–94162\.Cited by:[§1](https://arxiv.org/html/2607.22622#S1.p2.1)\.
- C\. Tai, Z\. Chen, T\. Zhang, X\. Deng, and H\. Sun \(2023\)Exploring chain of thought style prompting for text\-to\-SQL\.InProceedings of the 2023 Conference on Empirical Methods in Natural Language Processing,H\. Bouamor, J\. Pino, and K\. Bali \(Eds\.\),Singapore,pp\. 5376–5393\.External Links:[Link](https://aclanthology.org/2023.emnlp-main.327/),[Document](https://dx.doi.org/10.18653/v1/2023.emnlp-main.327)Cited by:[§2](https://arxiv.org/html/2607.22622#S2.p2.1)\.
- S\. Talaei, M\. Pourreza, Y\. Chang, A\. Mirhoseini, and A\. Saberi \(2024\)Chess: contextual harnessing for efficient sql synthesis\.arXiv preprint arXiv:2405\.16755\.Cited by:[§2](https://arxiv.org/html/2607.22622#S2.p1.1)\.
- S\. Tu, J\. Lin, Q\. Zhang, X\. Tian, L\. Li, X\. Lan, and D\. Zhao \(2026\)Learning when to think: shaping adaptive reasoning in r1\-style models via multi\-stage RL\.InThe Thirty\-ninth Annual Conference on Neural Information Processing Systems,External Links:[Link](https://openreview.net/forum?id=Hs3FrjwyVZ)Cited by:[§1](https://arxiv.org/html/2607.22622#S1.p3.1),[§2](https://arxiv.org/html/2607.22622#S2.p2.1)\.
- B\. Wang, C\. Ren, J\. Yang, X\. Liang, J\. Bai, L\. Chai, Z\. Yan, Q\. Zhang, D\. Yin, X\. Sun, and Z\. Li \(2025\)MAC\-SQL: a multi\-agent collaborative framework for text\-to\-SQL\.InProceedings of the 31st International Conference on Computational Linguistics,O\. Rambow, L\. Wanner, M\. Apidianaki, H\. Al\-Khalifa, B\. D\. Eugenio, and S\. Schockaert \(Eds\.\),Abu Dhabi, UAE,pp\. 540–557\.External Links:[Link](https://aclanthology.org/2025.coling-main.36/)Cited by:[§2](https://arxiv.org/html/2607.22622#S2.p1.1)\.
- J\. Yang, B\. Hui, M\. Yang, J\. Yang, J\. Lin, and C\. Zhou \(2024\)Synthesizing text\-to\-SQL data from weak and strong LLMs\.InProceedings of the 62nd Annual Meeting of the Association for Computational Linguistics \(Volume 1: Long Papers\),L\. Ku, A\. Martins, and V\. Srikumar \(Eds\.\),Bangkok, Thailand,pp\. 7864–7875\.External Links:[Link](https://aclanthology.org/2024.acl-long.425/),[Document](https://dx.doi.org/10.18653/v1/2024.acl-long.425)Cited by:[§2](https://arxiv.org/html/2607.22622#S2.p1.1)\.
- Z\. Yao, G\. Sun, L\. Borchmann, G\. Nuti, Z\. Shen, M\. Deng, B\. Zhai, H\. Zhang, A\. Li, and Y\. He \(2025\)Arctic\-text2sql\-r1: simple rewards, strong reasoning in text\-to\-sql\.arXiv preprint arXiv:2505\.20315\.Cited by:[§1](https://arxiv.org/html/2607.22622#S1.p1.1)\.
- T\. Yu, R\. Zhang, K\. Yang, M\. Yasunaga, D\. Wang, Z\. Li, J\. Ma, I\. Li, Q\. Yao, S\. Roman,et al\.\(2018\)Spider: a large\-scale human\-labeled dataset for complex and cross\-domain semantic parsing and text\-to\-sql task\.InProceedings of the 2018 conference on empirical methods in natural language processing,pp\. 3911–3921\.Cited by:[Table 5](https://arxiv.org/html/2607.22622#A2.T5.1.1.3.2.1),[§1](https://arxiv.org/html/2607.22622#S1.p2.1),[Figure 1](https://arxiv.org/html/2607.22622#S4.F1),[§4\.1](https://arxiv.org/html/2607.22622#S4.SS1.SSS0.Px3.p1.1),[§4\.2](https://arxiv.org/html/2607.22622#S4.SS2.p1.1),[§4\.3](https://arxiv.org/html/2607.22622#S4.SS3.SSS0.Px2.p1.1)\.
- J\. Zhang, N\. Lin, L\. Hou, L\. Feng, and J\. Li \(2025\)AdaptThink: reasoning models can learn when to think\.InProceedings of the 2025 Conference on Empirical Methods in Natural Language Processing,C\. Christodoulopoulos, T\. Chakraborty, C\. Rose, and V\. Peng \(Eds\.\),Suzhou, China,pp\. 3716–3730\.External Links:[Link](https://aclanthology.org/2025.emnlp-main.184/),[Document](https://dx.doi.org/10.18653/v1/2025.emnlp-main.184),ISBN 979\-8\-89176\-332\-6Cited by:[§2](https://arxiv.org/html/2607.22622#S2.p2.1)\.
- Y\. Zheng, R\. Zhang, J\. Zhang, Y\. Ye, Z\. Luo, Z\. Feng, and Y\. Ma \(2024\)LlamaFactory: unified efficient fine\-tuning of 100\+ language models\.InProceedings of the 62nd Annual Meeting of the Association for Computational Linguistics \(Volume 3: System Demonstrations\),Bangkok, Thailand\.External Links:[Link](http://arxiv.org/abs/2403.13372)Cited by:[Appendix A](https://arxiv.org/html/2607.22622#A1.SS0.SSS0.Px1.p1.9),[Table 5](https://arxiv.org/html/2607.22622#A2.T5.1.1.5.4.1)\.
## Appendix AImplementation Details
#### SFT Training\.
Both SFT and DPO are implemented using the LLaMA\-Factory framework\(Zhenget al\.,[2024](https://arxiv.org/html/2607.22622#bib.bib35)\)\. We fine\-tune Qwen3\-Coder\-30B\-A3B\-Instruct using LoRA\(Huet al\.,[2022](https://arxiv.org/html/2607.22622#bib.bib34)\)with rankr=16r\{=\}16,α=32\\alpha\{=\}32, and dropout0\.050\.05, applied to all attention and MLP projection layers \(q,k,v,o,gate,up,down\_proj\)\. We use the AdamW optimizer with a cosine learning rate schedule, a peak learning rate of1×10−41\\times 10^\{\-4\}, and a warmup ratio of0\.10\.1\. Training runs for33epochs with an effective batch size of6464and a maximum sequence length of40964096\. SFT is conducted for approximately 20 minutes with4×4\\timesNVIDIA H100 \(80GB\) GPUs using DeepSpeed ZeRO\-2 and bfloat16 precision\.
#### DPO Training\.
For hyperparameters on DPO training, we use lora rankr=16r\{=\}16,α=32\\alpha\{=\}32, dropout0\.050\.05, cosine learning rate schedule with a peak learning rate of1×10−41\\times 10^\{\-4\}and warmup ratio0\.10\.1, effective batch size6464, and maximum sequence length40964096andβ\\beta0\.30\.3\. DPO is conducted on4×4\\timesNVIDIA H100 \(80GB\) GPUs with DeepSpeed ZeRO\-3 and bfloat16 precision\. Training hours consumed are approximately 11 hours, 9 hours, and 4 hours for AutoThinkSQL, CoT\-only, no\-CoT\-only model, respectively\.
#### Inference\.
All inference is performed on4×4\\timesNVIDIA L40S GPUs using vLLM for efficient batched generation\. For Maj@8, we sample88independent outputs per query with temperature1\.01\.0and top\-pp1\.01\.0, and select the final answer by majority vote over execution outcomes\. Evaluation follows the codebase at[https://github\.com/QwenLM/Qwen3\-Coder/tree/main/qwencoder\-eval](https://github.com/QwenLM/Qwen3-Coder/tree/main/qwencoder-eval), applying the mode\-specific format instruction appropriate for each evaluated model\.
## Appendix BDataset Preprocessing
#### Data Schema Pre\-Processing\.
In this work, we utilize the preprocessed dataset provided byLiuet al\.\([2025](https://arxiv.org/html/2607.22622#bib.bib23)\), which follows the preprocessing methodology introduced in CodeS\(Liet al\.,[2024](https://arxiv.org/html/2607.22622#bib.bib30)\)\. Specifically, a schema item classifier is first employed to retrieve the tables and columns relevant to a given question\. Subsequently, values related to the questions are extracted using a coarse\-to\-fine approach\. Once all the necessary data components are successfully extracted, they are integrated to construct the final database prompt\.
#### Dataset Details\.
For SFT dataset construction, we collect1616independent rollouts under bothpNCp\_\{\\text\{NC\}\}\(Figure[4](https://arxiv.org/html/2607.22622#A5.F4)\) andpCp\_\{\\text\{C\}\}\(Figure[3](https://arxiv.org/html/2607.22622#A3.F3)\) for each BIRD training instance, as described in Section[3\.2](https://arxiv.org/html/2607.22622#S3.SS2)\. Responses generated underpNCp\_\{\\text\{NC\}\}are wrapped in\[SQL\] … \[/SQL\]tags before being included in the final training data\. Because AutoThinkSQL leverages rollouts from both modes, it can retain more training instances than CoT\-only or No\-CoT\-only baselines, which rely on a single mode and must discard any instance that yields no correct response under that mode\. The resulting SFT data statistics are summarized in Table[3](https://arxiv.org/html/2607.22622#A2.T3)\.
For DPO dataset construction, we similarly collect1616new rollouts per instance underpNCp\_\{\\text\{NC\}\}\(Figure[4](https://arxiv.org/html/2607.22622#A5.F4)\) andpCp\_\{\\text\{C\}\}\(Figure[3](https://arxiv.org/html/2607.22622#A3.F3)\) using the SFT\-trained model, while CoT\-only and No\-CoT\-only baselines collect rollouts under only their respective format instruction\. Auto\-thinking preference pairs are constructed as explained in Section[3\.3](https://arxiv.org/html/2607.22622#S3.SS3); instances with all\-correct or all\-incorrect responses are discarded\. The resulting DPO data sizes are shown in Table[4](https://arxiv.org/html/2607.22622#A2.T4), with AutoThinkSQL retaining more pairs by utilizing rollouts from bothpNCp\_\{\\text\{NC\}\}andpCp\_\{\\text\{C\}\}\.
Table 3:Number of SFT training dataset including the breakdown of CoT and No\-CoT pairs\.Table 4:Number of valid DPO training pairs generated by respective SFT models\.Table 5:Licenses and sources of scientific artifacts\.
## Appendix CPrompts
Figure[2](https://arxiv.org/html/2607.22622#A3.F2)shows the shared prompt template used for all SFT and DPO training instances\. The template combines a task overview, the preprocessed database schema, matched contents identified by schema linking, optional external knowledge, and the natural language question, followed by a mode\-specific format instruction\. Figure[5](https://arxiv.org/html/2607.22622#A5.F5)presents the auto\-thinking format instruction used by AutoThinkSQL, which instructs the model to first judge query complexity and then either emit the SQL directly or produce reasoning before the SQL\. For comparison, Figure[3](https://arxiv.org/html/2607.22622#A3.F3)and Figure[4](https://arxiv.org/html/2607.22622#A5.F4)show the CoT\-only and No\-CoT\-only format instructions used by the corresponding baselines\.
Prompt TemplateTask Overview:\{internallinenumbers\*\}You are a helpful SQL expert assistant\. Below, you are provided with a database schema and a natural language question\. Your task is to understand the schema and generate a valid SQL query to answer the question\.Database Engine:SQLiteDatabase Schema:<SCHEMA\_STR\>Matched Contents:<MATCHED\_STR\>External Knowledge:<EVIDENCE\>Question:<QUESTION\>\[FORMAT INSTRUCTION\]Figure 2:Shared prompt template for SFT and DPO training instances\.Format Instruction \(CoT\)\{internallinenumbers\*\}Please think step\-by\-step and output the final SQL query between \[SQL\] and \[/SQL\]\.Figure 3:CoT\-only format instruction\.
## Appendix DLicenses
We list the licenses and sources of all scientific artifacts used in this work in Table[5](https://arxiv.org/html/2607.22622#A2.T5)\. All artifacts are publicly released under permissive licenses that allow research use, and our usage is consistent with their intended purposes\.
## Appendix EUse of AI Assistants
We used AI assistants \(ChatGPT, Claude, and Gemini\) for both writing assistance \(grammar, phrasing, and translation\) and coding support \(debugging and boilerplate code\)\. All research ideas, experimental design, and analyses were conducted by the authors, and all AI\-assisted content was reviewed and verified\.
Format Instruction \(No\-CoT\)Please output only the final SQL query, starts with keyword \`SELECT\`\.Figure 4:No\-CoT\-only format instruction\.Format Instruction \(AutoThinkSQL\)Format Instructions:\{internallinenumbers\*\}Analyze the question, database schema, and external knowledge to determine how to write the SQL query\.First, evaluate the complexity of the problem\.\{internallinenumbers\*\}If it is an easy problem: Do not provide any reasoning or explanation\. Directly output the final SQL query enclosed within \[SQL\] and \[/SQL\] tags\.\{internallinenumbers\*\}If it is a difficult problem requiring thought: Write down your detailed reasoning and analysis process first as plain text\. After you have thoroughly thought through the problem, provide the final SQL query enclosed within \[SQL\] and \[/SQL\] tags at the very end\.Output format:\(For easy problems\)\[SQL\]Your SQL here\[/SQL\]\(For difficult problems\)Your reasoning here\[SQL\]Your SQL here\[/SQL\]Figure 5:Auto\-thinking format instruction\.Similar Articles
Integrating Reasoning and Generalization in Text-to-SQL via Self-Enhanced Fine-Tuning
This paper proposes CoTE-SQL, a self-enhanced fine-tuning framework for text-to-SQL that integrates self-reasoning traces, structured chain-of-thought prompting, and execution feedback to achieve state-of-the-art performance on Spider and Bird benchmarks.
Structured Thoughts For Improved Reasoning And Context Pruning
This paper introduces Structured Thoughts, a framework that organizes LLM reasoning into alternating <try> and <outcome> blocks, enabling context pruning and improving performance on reasoning benchmarks by up to 8.08% with 85% memory savings.
Progress-SQL: Improving Reinforcement Learning for Text-to-SQL via Progressive Rewards
Progress-SQL introduces a multi-turn reinforcement learning framework with progressive rewards for Text-to-SQL, using an Oracle-guided Diagnostic Tree to provide dense reward signals and improve SQL query generation on benchmarks like BIRD and Spider.
Knowledge Distillation for Low-Resource Open-source Text-to-SQL Model
This paper proposes a knowledge-aware Text-to-SQL framework that uses knowledge distillation to improve performance in low-resource settings by constructing task-specific knowledge bases and generating synthetic training data. Experiments on seven benchmarks show substantial improvements, especially for open-source models.
How to Fine-Tune a Reasoning Model? A Teacher-Student Cooperation Framework to Synthesize Student-Consistent SFT Data
This paper introduces TESSY, a teacher-student cooperative framework for fine-tuning reasoning models that generates on-policy SFT data by decoupling generation into capability tokens (from teacher) and style tokens (from student), addressing catastrophic forgetting issues when using off-policy teacher data.