{"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/mag-sql-multi-agent-generative-approach-with","title":"MAG-SQL: Multi-Agent Generative Approach with Soft Schema Linking and Iterative Sub-SQL Refinement for Text-to-SQL","arxiv_id":"2408.07930","date":"2024-08-15","proceeding":null,"authors":["Wenxuan Xie","Gaochen Wu","BoWen Zhou"],"abstract":"Recent In-Context Learning based methods have achieved remarkable success in Text-to-SQL task. However, there is still a large gap between the performance of these models and human performance on datasets with complex database schema and difficult questions, such as BIRD. Besides, existing work has neglected to supervise intermediate steps when solving questions iteratively with question decomposition methods, and the schema linking methods used in these works are very rudimentary. To address these issues, we propose MAG-SQL, a multi-agent generative approach with soft schema linking and iterative Sub-SQL refinement. In our framework, an entity-based method with tables' summary is used to select the columns in database, and a novel targets-conditions decomposition method is introduced to decompose those complex questions. Additionally, we build a iterative generating module which includes a Sub-SQL Generator and Sub-SQL Refiner, introducing external oversight for each step of generation. Through a series of ablation studies, the effectiveness of each agent in our framework has been demonstrated. When evaluated on the BIRD benchmark with GPT-4, MAG-SQL achieves an execution accuracy of 61.08%, compared to the baseline accuracy of 46.35% for vanilla GPT-4 and the baseline accuracy of 57.56% for MAC-SQL. Besides, our approach makes similar progress on Spider. The codes are available at https://github.com/LancelotXWX/MAG-SQL.","url_abs":"https://arxiv.org/abs/2408.07930v4","url_pdf":"https://arxiv.org/pdf/2408.07930v4.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":"abstracts"},"code_links":[{"paper_slug":"mag-sql-multi-agent-generative-approach-with","repo_url":"https://github.com/LancelotXWX/MAG-SQL","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"none","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"in-context-learning","task_name":"In-Context Learning"},{"task_slug":"text-to-sql","task_name":"Text to SQL"},{"task_slug":"text-to-sql","task_name":"Text-To-SQL"}],"methods":[{"method_slug":"absolute-position-encodings","method_name":"Absolute Position Encodings"},{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"gpt-4","method_name":"GPT-4"},{"method_slug":"label-smoothing","method_name":"Label Smoothing"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"position-wise-feed-forward-layer","method_name":"Position-Wise Feed-Forward Layer"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"transformer","method_name":"Transformer"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2408.07930","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2408.07930"}},"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":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/LancelotXWX/MAG-SQL","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran_violates":3,"ran_honours":1,"ran":15,"ran_draft_wrong":2,"unverified":4},"by_repo_kind":{"official":{"samples":25,"ran":21,"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":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"evaluation/evaluation_spider.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/evaluation/evaluation_spider.py","link_basis":"plan_row","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"8231e3fdffa9c8ee"}},{"code_sha256_prefix":"f2d76234528d3b57","entry":"condition_has_or","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"evaluation/evaluation_spider.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/evaluation/evaluation_spider.py","link_basis":"plan_row","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f2d76234528d3b57"}},{"code_sha256_prefix":"954c76e256cc7220","entry":"condition_has_sql","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"evaluation/evaluation_spider.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/evaluation/evaluation_spider.py","link_basis":"plan_row","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"954c76e256cc7220"}},{"code_sha256_prefix":"9c222961369b8d61","entry":"execute_sql","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"evaluation/evaluation_bird_ex.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/evaluation/evaluation_bird_ex.py","link_basis":"plan_row","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9c222961369b8d61"}},{"code_sha256_prefix":"9a2dafca24381ab4","entry":"execute_sql","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"evaluation/evaluation_bird_ves.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/evaluation/evaluation_bird_ves.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9a2dafca24381ab4"}},{"code_sha256_prefix":"0992d2a47ae733fa","entry":"get_schema","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"evaluation/process_sql.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/evaluation/process_sql.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0992d2a47ae733fa"}},{"code_sha256_prefix":"c4dcaf29b663a364","entry":"get_schema_from_json","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"evaluation/process_sql.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/evaluation/process_sql.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c4dcaf29b663a364"}},{"code_sha256_prefix":"b724cc2d4066a429","entry":"is_commonword","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"main_scripts/bridge_content_encoder.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/main_scripts/bridge_content_encoder.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"b724cc2d4066a429"}},{"code_sha256_prefix":"f39fdc1ce6cffe08","entry":"is_number","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"main_scripts/bridge_content_encoder.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/main_scripts/bridge_content_encoder.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f39fdc1ce6cffe08"}},{"code_sha256_prefix":"d56a1f9221823a48","entry":"is_stopword","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"main_scripts/bridge_content_encoder.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/main_scripts/bridge_content_encoder.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d56a1f9221823a48"}},{"code_sha256_prefix":"e683610fb710931f","entry":"is_valid_date","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"main_scripts/utils.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/main_scripts/utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"e683610fb710931f"}},{"code_sha256_prefix":"6e6792ab3f04a268","entry":"is_valid_date_column","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"main_scripts/utils.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/main_scripts/utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"6e6792ab3f04a268"}},{"code_sha256_prefix":"2b57439bdcb8e43d","entry":"iterated_execute_sql","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"evaluation/evaluation_bird_ves.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/evaluation/evaluation_bird_ves.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"2b57439bdcb8e43d"}},{"code_sha256_prefix":"2178b95c919ae420","entry":"join_tokens","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"evaluation/parse.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/evaluation/parse.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"2178b95c919ae420"}},{"code_sha256_prefix":"72eccdcbaaff9c8d","entry":"load_json","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"evaluation/evaluation_bird_ex.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/evaluation/evaluation_bird_ex.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"72eccdcbaaff9c8d"}},{"code_sha256_prefix":"f23d6ff3772963bc","entry":"permute_tuple","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"evaluation/exec_eval.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/evaluation/exec_eval.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f23d6ff3772963bc"}},{"code_sha256_prefix":"58e472cff9780d63","entry":"postprocess","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"evaluation/parse.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/evaluation/parse.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"58e472cff9780d63"}},{"code_sha256_prefix":"a40510ba6a37f798","entry":"quick_rej","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"evaluation/exec_eval.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/evaluation/exec_eval.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a40510ba6a37f798"}},{"code_sha256_prefix":"009030dd773225d2","entry":"rename_file","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"main_scripts/utils.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/main_scripts/utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"009030dd773225d2"}},{"code_sha256_prefix":"13917dfdddd70f5e","entry":"replace_multiple_spaces","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"evaluation/evaluation_bird_ex.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/evaluation/evaluation_bird_ex.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"13917dfdddd70f5e"}},{"code_sha256_prefix":"afc8ef89576ef2aa","entry":"unorder_row","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"evaluation/exec_eval.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/evaluation/exec_eval.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"afc8ef89576ef2aa"}},{"code_sha256_prefix":"61ca5e74d54e4c09","entry":"api_func","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"main_scripts/llm.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/main_scripts/llm.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"61ca5e74d54e4c09"}},{"code_sha256_prefix":"3553bf8903f0b994","entry":"clean_abnormal","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"evaluation/evaluation_bird_ves.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/evaluation/evaluation_bird_ves.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3553bf8903f0b994"}},{"code_sha256_prefix":"a0e3cdde26258b5d","entry":"safe_call_llm","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"main_scripts/llm.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/main_scripts/llm.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a0e3cdde26258b5d"}},{"code_sha256_prefix":"a906f5de1f5971b0","entry":"tokenize","repo":"LancelotXWX/MAG-SQL","repo_kind":"official","path":"evaluation/process_sql.py","file_url":"https://github.com/LancelotXWX/MAG-SQL/blob/HEAD/evaluation/process_sql.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a906f5de1f5971b0"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}