{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/sql-r1-training-natural-language-to-sql","title":"SQL-R1: Training Natural Language to SQL Reasoning Model By Reinforcement Learning","arxiv_id":"2504.08600","date":"2025-04-11","proceeding":null,"authors":["Peixian Ma","Xialie Zhuang","Chengjin Xu","Xuhui Jiang","Ran Chen","Jian Guo"],"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 reasoning 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 and synthetic data 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 67.1\\% on the benchmark Spider and BIRD, respectively. The code is available at https://github.com/IDEA-FinAI/SQL-R1 .","url_abs":"https://arxiv.org/abs/2504.08600v3","url_pdf":"https://arxiv.org/pdf/2504.08600v3.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"links_only","authors_date_abstract":"arXiv metadata, CC0 1.0 (https://info.arxiv.org/help/license), from the Kaggle arXiv metadata snapshot of 2026-09-12"},"code_links":[{"paper_slug":"sql-r1-training-natural-language-to-sql","repo_url":"https://github.com/IDEA-FinAI/SQL-R1","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":null,"atlas_url":"https://app.syntology.ai/?focus=2504.08600","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2504.08600"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"deterministic:regex_extraction","url":"https://github.com/IDEA-FinAI/SQL-R1","reach":{"status":"ok","spdx":"Apache-2.0"}}],"summary":{"ran_violates":4,"ran":3,"ran_draft_wrong":3,"ran_fixture":1,"ran_honours":1,"unverified":10},"by_repo_kind":{"official":{"samples":18,"ran":8,"repositories":1},"community":{"samples":4,"ran":4,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"8231e3fdffa9c8ee","entry":"condition_has_like","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"src/evaluation_spider.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/src/evaluation_spider.py","link_basis":"harvester_set","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"8231e3fdffa9c8ee"}},{"code_sha256_prefix":"f2d76234528d3b57","entry":"condition_has_or","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"src/evaluation_spider.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/src/evaluation_spider.py","link_basis":"harvester_set","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"f2d76234528d3b57"}},{"code_sha256_prefix":"0992d2a47ae733fa","entry":"get_schema","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"src/evaluations/spider1_evaluations/src/process_sql.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/src/evaluations/spider1_evaluations/src/process_sql.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"0992d2a47ae733fa"}},{"code_sha256_prefix":"c4dcaf29b663a364","entry":"get_schema_from_json","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"src/evaluations/spider1_evaluations/src/process_sql.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/src/evaluations/spider1_evaluations/src/process_sql.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"c4dcaf29b663a364"}},{"code_sha256_prefix":"4127f7104f276d1b","entry":"parse_response","repo":"DataArcTech/SQL-R1","repo_kind":"community","path":"src/inference.py","file_url":"https://github.com/DataArcTech/SQL-R1/blob/HEAD/src/inference.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"4127f7104f276d1b"}},{"code_sha256_prefix":"ea2e45a6df8f96db","entry":"permute_tuple","repo":"DataArcTech/SQL-R1","repo_kind":"community","path":"src/evaluations/spider1_evaluations/src/exec_eval.py","file_url":"https://github.com/DataArcTech/SQL-R1/blob/HEAD/src/evaluations/spider1_evaluations/src/exec_eval.py","link_basis":"first_harvest_node","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"well_formed","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"ea2e45a6df8f96db"}},{"code_sha256_prefix":"dcd3006254e3d81a","entry":"quick_rej","repo":"DataArcTech/SQL-R1","repo_kind":"community","path":"src/evaluations/spider1_evaluations/src/exec_eval.py","file_url":"https://github.com/DataArcTech/SQL-R1/blob/HEAD/src/evaluations/spider1_evaluations/src/exec_eval.py","link_basis":"first_harvest_node","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"dcd3006254e3d81a"}},{"code_sha256_prefix":"63fda278334d1f2e","entry":"read_data","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"src/evaluation_spider.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/src/evaluation_spider.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"63fda278334d1f2e"}},{"code_sha256_prefix":"f49ea7fd7f652e43","entry":"remove_sql_comments","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"src/utils/prepare_input_seq.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/src/utils/prepare_input_seq.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"f49ea7fd7f652e43"}},{"code_sha256_prefix":"21331a58f93375e4","entry":"union_tensor_dict","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"verl/protocol.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/verl/protocol.py","link_basis":"harvester_set","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"DEP_MISSING","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"21331a58f93375e4"}},{"code_sha256_prefix":"fb60a4c142ce9cb2","entry":"unorder_row","repo":"DataArcTech/SQL-R1","repo_kind":"community","path":"src/evaluations/spider1_evaluations/src/exec_eval.py","file_url":"https://github.com/DataArcTech/SQL-R1/blob/HEAD/src/evaluations/spider1_evaluations/src/exec_eval.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"fb60a4c142ce9cb2"}},{"code_sha256_prefix":"25f0ea3f460f6ce1","entry":"unpad_dataproto","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"verl/protocol.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/verl/protocol.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"25f0ea3f460f6ce1"}},{"code_sha256_prefix":"0d3763ae4f97d43c","entry":"compare_sql","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"src/evaluation_bird_post.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/src/evaluation_bird_post.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"0d3763ae4f97d43c"}},{"code_sha256_prefix":"91f2db0ec7a2841f","entry":"compare_sql_wrapper","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"src/evaluation_bird_post.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/src/evaluation_bird_post.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"91f2db0ec7a2841f"}},{"code_sha256_prefix":"6ad9f49ae16cf31d","entry":"execute_query","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"src/data_preprocess/nl2sql_synsql_nonvalue.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/src/data_preprocess/nl2sql_synsql_nonvalue.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"6ad9f49ae16cf31d"}},{"code_sha256_prefix":"490449c025d402b2","entry":"execute_sql","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"src/evaluation_bird_post.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/src/evaluation_bird_post.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"490449c025d402b2"}},{"code_sha256_prefix":"15b496c5d27aa7dc","entry":"format_sql","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"src/evaluation_spider_post.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/src/evaluation_spider_post.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"15b496c5d27aa7dc"}},{"code_sha256_prefix":"5e51a446415a6550","entry":"get_schema_slot","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"src/data_preprocess/nl2sql_synsql_nonvalue.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/src/data_preprocess/nl2sql_synsql_nonvalue.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"5e51a446415a6550"}},{"code_sha256_prefix":"73750dcbdb55d522","entry":"get_table_names","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"src/data_preprocess/nl2sql_synsql_nonvalue.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/src/data_preprocess/nl2sql_synsql_nonvalue.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"73750dcbdb55d522"}},{"code_sha256_prefix":"919cf310ad4c189a","entry":"get_weight_loader","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"verl/models/weight_loader_registry.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/verl/models/weight_loader_registry.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"919cf310ad4c189a"}},{"code_sha256_prefix":"062dbe705bf0ea9b","entry":"obtain_db_ddls","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"src/utils/prepare_input_seq.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/src/utils/prepare_input_seq.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"062dbe705bf0ea9b"}},{"code_sha256_prefix":"b72b76d185b39d84","entry":"tokenize","repo":"IDEA-FinAI/SQL-R1","repo_kind":"official","path":"src/evaluations/spider1_evaluations/src/process_sql.py","file_url":"https://github.com/IDEA-FinAI/SQL-R1/blob/HEAD/src/evaluations/spider1_evaluations/src/process_sql.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"b72b76d185b39d84"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}