{"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/pet-sql-a-prompt-enhanced-two-stage-text-to","title":"PET-SQL: A Prompt-Enhanced Two-Round Refinement of Text-to-SQL with Cross-consistency","arxiv_id":"2403.09732","date":"2024-03-13","proceeding":null,"authors":["Zhishuai Li","Xiang Wang","Jingjing Zhao","Sun Yang","Guoqing Du","Xiaoru Hu","Bin Zhang","Yuxiao Ye","Ziyue Li","Rui Zhao","Hangyu Mao"],"abstract":"Recent advancements in Text-to-SQL (Text2SQL) emphasize stimulating the large language models (LLM) on in-context learning, achieving significant results. Nevertheless, they face challenges when dealing with verbose database information and complex user intentions. This paper presents a two-stage framework to enhance the performance of current LLM-based natural language to SQL systems. We first introduce a novel prompt representation, called reference-enhanced representation, which includes schema information and randomly sampled cell values from tables to instruct LLMs in generating SQL queries. Then, in the first stage, question-SQL pairs are retrieved as few-shot demonstrations, prompting the LLM to generate a preliminary SQL (PreSQL). After that, the mentioned entities in PreSQL are parsed to conduct schema linking, which can significantly compact the useful information. In the second stage, with the linked schema, we simplify the prompt's schema information and instruct the LLM to produce the final SQL. Finally, as the post-refinement module, we propose using cross-consistency across different LLMs rather than self-consistency within a particular LLM. Our methods achieve new SOTA results on the Spider benchmark, with an execution accuracy of 87.6%.","url_abs":"https://arxiv.org/abs/2403.09732v4","url_pdf":"https://arxiv.org/pdf/2403.09732v4.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":"pet-sql-a-prompt-enhanced-two-stage-text-to","repo_url":"https://github.com/zhshlii/petsql","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"none","reach":{"status":"ok"}}],"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":[],"datasets_introduced":[],"methods_introduced":[],"results":[{"leaderboard":"/sota/text-to-sql-on-spider","task":"Text-To-SQL","dataset":"spider","model":"PET-SQL","rank_in_archive_order":2,"of":20,"metrics":{"Exact Match Accuracy (Test)":"66.6","Execution Accuracy (Test)":"87.6"},"uses_additional_data":false}],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2403.09732","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2403.09732"}},"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/zhshlii/petsql","reach":{"status":"ok"}}],"summary":{"ran":6,"unverified":3},"by_repo_kind":{"official":{"samples":9,"ran":6,"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":9,"samples":[{"code_sha256_prefix":"2df2345e37499e87","entry":"add_fk","repo":"zhshlii/petsql","repo_kind":"official","path":"src/sources/data_preprocess.py","file_url":"https://github.com/zhshlii/petsql/blob/HEAD/src/sources/data_preprocess.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"2df2345e37499e87"}},{"code_sha256_prefix":"a9a626332f19ef82","entry":"extract_sql_from_text","repo":"zhshlii/petsql","repo_kind":"official","path":"src/sources/post_process.py","file_url":"https://github.com/zhshlii/petsql/blob/HEAD/src/sources/post_process.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"a9a626332f19ef82"}},{"code_sha256_prefix":"a1579e74824be11f","entry":"jaccard_similarity","repo":"zhshlii/petsql","repo_kind":"official","path":"src/sources/sql_gen/sql_gen_utils.py","file_url":"https://github.com/zhshlii/petsql/blob/HEAD/src/sources/sql_gen/sql_gen_utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"a1579e74824be11f"}},{"code_sha256_prefix":"6a69173ee0ca1628","entry":"match_shift","repo":"zhshlii/petsql","repo_kind":"official","path":"src/sources/sql_gen/sql_gen_utils.py","file_url":"https://github.com/zhshlii/petsql/blob/HEAD/src/sources/sql_gen/sql_gen_utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"6a69173ee0ca1628"}},{"code_sha256_prefix":"a449070528b531b5","entry":"parallel_call","repo":"zhshlii/petsql","repo_kind":"official","path":"src/sources/llms/codellama.py","file_url":"https://github.com/zhshlii/petsql/blob/HEAD/src/sources/llms/codellama.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"a449070528b531b5"}},{"code_sha256_prefix":"e479cb4ded98503f","entry":"process_duplication","repo":"zhshlii/petsql","repo_kind":"official","path":"src/sources/post_process.py","file_url":"https://github.com/zhshlii/petsql/blob/HEAD/src/sources/post_process.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"e479cb4ded98503f"}},{"code_sha256_prefix":"9ffa3fa74322b44b","entry":"gen_ppl_from_json","repo":"zhshlii/petsql","repo_kind":"official","path":"src/sources/data_preprocess.py","file_url":"https://github.com/zhshlii/petsql/blob/HEAD/src/sources/data_preprocess.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"9ffa3fa74322b44b"}},{"code_sha256_prefix":"8ece35cab7884b63","entry":"mask_question_with_schema_linking","repo":"zhshlii/petsql","repo_kind":"official","path":"src/sources/sql_gen/sql_gen_utils.py","file_url":"https://github.com/zhshlii/petsql/blob/HEAD/src/sources/sql_gen/sql_gen_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"8ece35cab7884b63"}},{"code_sha256_prefix":"09f737d9dfa539d6","entry":"parallel_call","repo":"zhshlii/petsql","repo_kind":"official","path":"src/sources/llms/llama2.py","file_url":"https://github.com/zhshlii/petsql/blob/HEAD/src/sources/llms/llama2.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"09f737d9dfa539d6"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}