Optimizing Small Language Models for NL2SQL via Chain-of-Thought Fine-Tuning
Organizations: Google AI, Global Services Delivery
Abstract
Translating Natural Language to SQL (NL2SQL) remains a critical bottleneck for democratization of data in enterprises. Although Large Language Models (LLMs) like Gemini 2.5 and other LLMs have demonstrated impressive zero-shot capabilities, their high inference costs limit deployment at scale. This paper explores the efficacy of fine-tuning both large and small language models on NL2SQL tasks. Our research reveals a counter-intuitive scaling phenomenon. Fine-tuning large models (Gemini 2.5 Flash/Lite) on standard datasets yields negligible returns, often leading to overfitting on complex queries. Conversely, small models (Qwen) show significant gains. Fine-tuning improved the small model baseline from 36% to 45%, and further enriching the dataset with explicit Chain-of-Thought (CoT) reasoning surged accuracy to 54.5%(Fig 2). While this is still lower than the accuracy of large models like Gemini 2.5 , it does serve the business goal of significant cost reduction, latency in inference time and also meeting the business critical performance accuracy threshold.This paper demonstrates that transferring reasoning patterns enables compute-efficient smaller models to approach production-grade performance.
Figures & tables
| Difficulty | Query Count | Complexity Score Range | Median Score |
|---|---|---|---|
| Easy | 2,100 | 0 (Min) – 1 (Max) | 0.0 |
| Medium | 2,800 | 1 (Min) – 3 (Max) | 2.0 |
| Hard | 2,100 | 3 (Min) – 20 (Max) | 4.0 |
| Exp ID | Model | Training Method | Dataset Size | Hyperparameters | Exec Acc (600 Q) |
|---|---|---|---|---|---|
| G-Flash-Base | Gemini 2.5 Flash | Zero-shot | N/A | N/A | 73.17% |
| G-Flash-FT | Gemini 2.5 Flash | Standard SFT | Full Spider | Ep: 3, LRM: 1, Adpt: 16 | 72.50% |
| G-Lite-Base | Gemini 2.5 F-Lite | Zero-shot | N/A | N/A | 73.00% |
| G-Lite-FT | Gemini 2.5 F-Lite | Standard SFT | Full Spider | Ep: 3, LRM: 5e-5, Adpt: 16 | 73.83% |
| Qwen-Base | Qwen (7b) | Zero-shot | N/A | N/A | 36.17% |
| Qwen-SFT | Qwen (7b) | Standard SFT | Full Spider | Ep: 3, LRM: 2e-5, Adpt: 16 | 45.33% |
Text-to-SQL
Text-to-SQL translates natural-language questions into executable database queries, linking user intent to schemas, values, and SQL logic.
See all 169 papers