SQL-R1: Training Natural Language to SQL Reasoning Model By Reinforcement Learning
Preprint
Abstract
Natural Language to SQL (NL2SQL) enables intuitive interactions with databases by transforming natural language queries into structured SQL statements. Despite recent advancements in enhancing human-computer interaction within database applications, significant challenges persist, particularly regarding the inference performance in complex scenarios involving multi-table joins and nested queries. Current methodologies primarily utilize supervised fine-tuning (SFT) to train the NL2SQL model, which may limit adaptability and interpretability in new environments (e.g., finance and healthcare). In order to enhance the reasoning performance of the NL2SQL model in the above complex situations, we introduce SQL-R1, a novel NL2SQL reasoning model trained by the reinforcement learning (RL) algorithms. We design a specialized RL-based reward function tailored for NL2SQL tasks and discussed the impact of cold start on the effectiveness of intensive training. In addition, we achieve competitive accuracy using only a tiny amount of synthetic NL2SQL data for augmented training and further explore data engineering for RL. In existing experiments, SQL-R1 achieves execution accuracy of 88.6% and 66.6% on the benchmark Spider and BIRD, respectively, only using the 7B base model.Keywords
All Related Versions
This publication has 13 references indexed in Scilit:
- Next-Generation Database Interfaces: A Survey of LLM-Based Text-to-SQLIEEE Transactions on Knowledge and Data Engineering, 2025
- NL2SQL-BUGs: A Benchmark for Detecting Semantic Errors in NL2SQL Translation2025
- OmniSQL: Synthesizing High-Quality Text-to-SQL Data at ScaleProceedings of the VLDB Endowment, 2025
- OpenSearch-SQL: Enhancing Text-to-SQL with Dynamic Few-shot and Consistency AlignmentProceedings of the ACM on Management of Data, 2025
- CodeS: Towards Building Open-source Language Models for Text-to-SQLProceedings of the ACM on Management of Data, 2024
- DTS-SQL: Decomposed Text-to-SQL with Small Large Language Models2024
- Synthesizing Text-to-SQL Data from Weak and Strong LLMs2024
- Text-to-SQL Empowered by Large Language Models: A Benchmark EvaluationProceedings of the VLDB Endowment, 2024
- RESDSQL: Decoupling Schema Linking and Skeleton Parsing for Text-to-SQLProceedings of the AAAI Conference on Artificial Intelligence, 2023
- Steerable Self-Driving Data VisualizationIEEE Transactions on Knowledge and Data Engineering, 2020