A robust natural language text-to-SQL generation framework with dynamic strategies based on LLMs.
Saved in:
| Title: | A robust natural language text-to-SQL generation framework with dynamic strategies based on LLMs. |
|---|---|
| Authors: | Su X; Lianyungang Power Supply Company, State Grid Jiangsu Electric Power Co., Ltd., Lianyungang, Jiangsu, 222000, China., Gu Y; Lianyungang Power Supply Company, State Grid Jiangsu Electric Power Co., Ltd., Lianyungang, Jiangsu, 222000, China., Wang P; Lianyungang Power Supply Company, State Grid Jiangsu Electric Power Co., Ltd., Lianyungang, Jiangsu, 222000, China., Gu W; Lianyungang Power Supply Company, State Grid Jiangsu Electric Power Co., Ltd., Lianyungang, Jiangsu, 222000, China., Qi L; Jiangsu Electric Power Information Technology Co., Ltd., Nanjing, Jiangsu, 221000, China. miaomiaoguoke@gmail.com., He J; Jiangsu Electric Power Information Technology Co., Ltd., Nanjing, Jiangsu, 221000, China. |
| Source: | Scientific reports [Sci Rep] 2026 Feb 09; Vol. 16 (1). Date of Electronic Publication: 2026 Feb 09. |
| Publication Type: | Journal Article |
| Language: | English |
| Journal Info: | Publisher: Nature Publishing Group Country of Publication: England NLM ID: 101563288 Publication Model: Electronic Cited Medium: Internet ISSN: 2045-2322 (Electronic) Linking ISSN: 20452322 NLM ISO Abbreviation: Sci Rep Subsets: MEDLINE; PubMed not MEDLINE |
| Imprint Name(s): | Original Publication: London : Nature Publishing Group, copyright 2011- |
| Abstract: | Natural language text-to-SQL generation (Text2SQL) aims to translate natural language questions into executable SQL queries. Although the emergence of large language models (LLMs) has led to significant advancements in this field, their performance degrades sharply with question complexity increases. A key limitation of current LLM-based methods lies in their uniform generation strategies, which fail to adapt dynamically to varying question complexity. To address this issue, we propose TriSQL, a novel three-stage framework designed to analyze question complexity and generate accurate and executable SQL. First, a Question-Guided Schema Selector is conceived to get the most relevant schema to the question using cross attention. Second, a Structure-Aware SQL Generator takes both the question and the selected schema as input, employing hierarchical decoding to generate a syntactically valid initial SQL. Finally, a Complexity-Aware SQL Refiner is designed with LLM to dynamically adjust strategies corresponding to the complexity of question and initial SQL, ensuring that the final generated SQL is both accurate and executable. Experimental results on the Spider benchmark and its variants show that TriSQL achieves state-of-the-art execution accuracy, surpasses existing LLM-based methods, and provides both high efficiency and strong robustness. (© 2026. The Author(s).) |
| Competing Interests: | Declarations. Competing interests: The authors declare no competing interests. |
| References: | Mernik, M., Heering, J. & Sloane, A. M. When and how to develop domain-specific languages. ACM Comput. Surv. (CSUR) 37, 316–344 (2005). (PMID: 10.1145/1118890.1118892) Fowler, M. Domain-specific languages (Addison-Wesley Professional, 2010). Deng, X. et al. Structure-grounded pretraining for text-to-sql. In The 2021 Annual Conference of the North American Chapter of the Association for Computational Linguistics (2021). Yu, T. et al. Grappa: Grammar-augmented pre-training for table semantic parsing. In International Conference on Learning Representations. Hazboun, F.H., Owda, M. & Owda, A. Y. A natural language interface to relational databases using an online analytic processing hypercube. AI 2, 720–737 (2021). Li, J. et al. Dir: a large-scale dialogue rewrite dataset for cross-domain conversational text-to-sql. Appl. Sci. 13, 2262 (2023). (PMID: 10.3390/app13042262) Soni, K. & Sachdeva, S. Mtable: Visual query interface for browsing and navigation in nosql data stores. J. Comput. Lang. 82, 101312 (2025). (PMID: 10.1016/j.cola.2024.101312) Hristidis, V., Papakonstantinou, Y. & Gravano, L. Efficient ir-style keyword search over relational databases. In Proceedings 2003 VLDB Conference, 850–861 (Elsevier, 2003). Gan, Y., Chen, X. & Purver, M. Exploring underexplored limitations of cross-domain text-to-sql generalization. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, 8926–8931 (2021). Wang, B., Shin, R., Liu, X., Polozov, O. & Richardson, M. Rat-sql: Relation-aware schema encoding and linking for text-to-sql parsers. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, 7567–7578 (2020). Qi, J. et al. Rasat: Integrating relational structures into pretrained seq2seq model for text-to-sql. In Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, 3215–3229 (2022). Tran, Q.-B.-H., Waheed, A. A. & Chung, S.-T. Robust text-to-cypher using combination of bert, graphsage, and transformer (cobgt) model. Appl. Sci. 14, 7881 (2024). (PMID: 10.3390/app14177881) Ma, C., Zhang, W., Huang, M., Feng, S. & Wu, Y. Integrating relational structure to heterogeneous graph for chinese nl2sql parsers. Electronics 12, 2093 (2023). (PMID: 10.3390/electronics12092093) Achiam, J. et al. Gpt-4 technical report. arXiv preprint arXiv:2303.08774 (2023). Chen, M. et al. Evaluating large language models trained on code. arXiv preprint arXiv:2107.03374 (2021). Zhang, K. et al. Refsql: A retrieval-augmentation framework for text-to-sql generation. In Findings of the Association for Computational Linguistics: EMNLP, 664–673 (2023). Naghshnejad, P., Theis Marchan, G., Olayiwola, T., Kumar, R. & Romagnoli, J. Graph-based modeling and molecular dynamics for ion activity coefficient prediction in polymeric ion-exchange membranes. Ind. Eng. Chem. Res. 64, 599–612 (2024). Zhao, X., Zhou, X. & Li, G. Chat2data: An interactive data analysis system with rag, vector databases and llms. Proceedings of the VLDB Endowment 17, 4481–4484 (2024). (PMID: 10.14778/3685800.3685905) Du, X., Hu, S., Zhou, F., Wang, C. & Nguyen, B. M. Fi-nl2py2sql: Financial industry nl2sql innovation model based on python and large language model. Future Internet 17, 12 (2025). (PMID: 10.3390/fi17010012) Wang, H., Guo, L., Yubin, L., Liu, L. & Jiajin, H. Gpt-based text-to-sql for spatial databases. ISPRS Int. J. Geo-Inf. 14, 288 (2025). (PMID: 10.3390/ijgi14080288) Pourreza, M. & Rafiei, D. Din-sql: Decomposed in-context learning of text-to-sql with self-correction. Adv. Neural Inf. Process. Syst. 36, 36339–36348 (2023). Lewis, M. et al. Bart: Denoising sequence-to-sequence pre-training for natural language generation, translation, and comprehension. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, 7871–7880 (2020). Gan, Y. et al. Towards robustness of text-to-sql models against synonym substitution. In Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers), 2505–2515 (2021). Hazoom, M., Malik, V. & Bogin, B. Text-to-sql in the wild: A naturally-occurring dataset based on stack exchange data. In Proceedings of the 1st Workshop on Natural Language Processing for Programming (NLP4Prog 2021), 77–87 (2021). Chang, Y. et al. A survey on evaluation of large language models. ACM Trans. Intell. Syst. Technol. 15, 1–45 (2024). (PMID: 10.1145/3641289) Guo, C. et al. Retrieval-augmented gpt-3.5-based text-to-sql framework with sample-aware prompting and dynamic revision chain. In International Conference on Neural Information Processing, 341–356 (Springer, 2023). Perez, E., Kiela, D. & Cho, K. True few-shot learning with language models. Adv. Neural Inf. Process. Syst. 34, 11054–11070 (2021). Banitaba, F. S., Aygun, S. & Najafi, M. H. Late breaking results: Fortifying neural networks: Safeguarding against adversarial attacks with stochastic computing. CoRR (2024). Vougiouklis, P. et al. Fastrat: Fast and efficient cross-lingual text-to-sql semantic parsing. In Proceedings of the 13th International Joint Conference on Natural Language Processing and the 3rd Conference of the Asia-Pacific Chapter of the Association for Computational Linguistics (Volume 1: Long Papers), 564–576 (2023). Li, Z. et al. Pet-sql: A prompt-enhanced two-stage text-to-sql framework with cross-consistency. CoRR (2024). Hammami, L. et al. Automated classification of cancer morphology from italian pathology reports using natural language processing techniques: A rule-based approach. J. Biomed. Inform. 116, 103712 (2021). (PMID: 10.1016/j.jbi.2021.10371233609761) Yin, P. & Neubig, G. Tranx: A transition-based neural abstract syntax parser for semantic parsing and code generation. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing: System Demonstrations, 7–12 (2018). Sutskever, I., Vinyals, O. & Le, Q. V. Sequence to sequence learning with neural networks. In Proceedings of the 28th International Conference on Neural Information Processing Systems-Volume 2, 3104–3112 (2014). Lin, K., Bogin, B., Neumann, M., Berant, J. & Gardner, M. Grammar-based neural text-to-sql generation. arXiv preprint arXiv:1905.13326 (2019). Griswold, M. A. et al. Generalized autocalibrating partially parallel acquisitions (grappa). Magn. Reson. Med. 47, 1202–1210 (2002). (PMID: 10.1002/mrm.1017112111967) Cao, R. et al. Lgesql: Line graph enhanced text-to-sql model with mixed local and non-local relations. In Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers), 2541–2555 (2021). Bahdanau, D., Cho, K. H. & Bengio, Y. Neural machine translation by jointly learning to align and translate. In 3rd International Conference on Learning Representations, ICLR 2015 (2015). Luong, M.-T., Pham, H. & Manning, C. D. Effective approaches to attention-based neural machine translation. In Proceedings of the 2015 Conference on Empirical Methods in Natural Language Processing, 1412–1421 (2015). Xu, X. & Liu, C. & Song, D (Generating structured queries from natural language without reinforcement learning, SQLNet, 2018). Zhang, R. et al. Editing-based sql query generation for cross-domain context-dependent questions. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP), 5338–5349 (2019). Zhang, H., Cao, R., Chen, L., Xu, H. & Yu, K. Act-sql: In-context learning for text-to-sql with automatically-generated chain-of-thought. Find. Assoc. Comput. Linguist.: EMNLP 2023, 3501–3532 (2023). Biswal, A. et al. Text2sql is not enough: Unifying ai and databases with tag. CoRR (2024). Hongjin, S. et al. Selective annotation makes language models better few-shot learners. In The Eleventh International Conference on Learning Representations (2022). Zhang, Y., Zhou, S. & Huang, G. Se-hcl: Schema enhanced hybrid curriculum learning for multi-turn text-to-sql. IEEE Access 12, 39902–39912 (2024). (PMID: 10.1109/ACCESS.2024.3365522) Li, H., Zhang, J., Li, C. & Chen, H. Resdsql: Decoupling schema linking and skeleton parsing for text-to-sql. Proc. AAAI Conf. Artif. Intell. 37, 13067–13075 (2023). Stratica, N., Kosseim, L. & Desai, B. C. Using semantic templates for a natural language interface to the cindi virtual library. Data Knowl. Eng. 55, 4–19 (2005). (PMID: 10.1016/j.datak.2004.12.002) Cai, R. et al. An encoder-decoder framework translating natural language to database queries. In Proceedings of the 27th International Joint Conference on Artificial Intelligence, 3977–3983 (2018). Fu, Y., Ye, S. & Fan, H. Generate text-to-sql queries based on sketch filling. IEEE Access 12, 152392–152403 (2024). Li, S., He, Y., Ao, L. & Qi, R. Rgisql: Integrating refined grammatical information into relational graph neural network for text-to-sql task. Appl. Sci. 14, 10359 (2024). (PMID: 10.3390/app142210359) Jeong, G. et al. Improving text-to-sql with a hybrid decoding method. Entropy 25, 513 (2023). (PMID: 10.3390/e250305133698140110048569) Scholak, T., Schucher, N. & Bahdanau, D. Picard: Parsing incrementally for constrained auto-regressive decoding from language models. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, 9895–9901 (2021). Ji, X., Parameswaran, A. & Hulsebos, M. Target: Benchmarking table retrieval for generative tasks. In NeurIPS 2024 Third Table Representation Learning Workshop (2024). Li, B., Luo, Y., Chai, C., Li, G. & Tang, N. The dawn of natural language to sql: Are we fully ready? CoRR 17, (11) 3318–3331 (2024). Ouyang, L. et al. Training language models to follow instructions with human feedback. Adv. Neural Inf. Process. Syst. 35, 27730–27744 (2022). Touvron, H. et al. Llama: Open and efficient foundation language models. arXiv preprint arXiv:2302.13971 (2023). Pourreza, M. & Rafiei, D. Evaluating cross-domain text-to-sql models and benchmarks. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, 1601–1611 (2023). Kang, N., Singh, B., Afzal, Z., van Mulligen, E. M. & Kors, J. A. Using rule-based natural language processing to improve disease normalization in biomedical text. J. Am. Med. Inform. Assoc. 20, 876–881 (2013). (PMID: 10.1136/amiajnl-2012-00117323043124) Wang, T. et al. Dbcopilot: Natural language querying over massive databases via schema routing. Preprint (2025). Kanburoglu, A. B. & Tek, F. B. Turspider: A turkish text-to-sql dataset and llm-based study. IEEE Access 12, 169379–169387 (2024). Hui, B. et al. S2sql: Injecting syntax to question-schema interaction graph encoder for text-to-sql parsers. Find. Assoc. Comput. Linguist.: ACL 2022, 1254–1262 (2022). Mahmud, T., Hasan, K. A., Ahmed, M. & Chak, T. H. C. A rule based approach for nlp based query processing. In 2015 2nd international conference on electrical information and communication technologies (EICT), 78–82 (IEEE, 2015). Yu, T. et al. Spider: A large-scale human-labeled dataset for complex and cross-domain semantic parsing and text-to-sql task. In 2018 Conference on Empirical Methods in Natural Language Processing, EMNLP 2018, 3911–3921 (Association for Computational Linguistics, 2018). |
| Grant Information: | J2024170 The Science and Technology Project of State Grid Corporation of China |
| Entry Date(s): | Date Created: 20260209 Latest Revision: 20260305 |
| Update Code: | 20260305 |
| PubMed Central ID: | PMC12953869 |
| DOI: | 10.1038/s41598-026-39128-9 |
| PMID: | 41663560 |
| Database: | MEDLINE |
| Abstract: | Natural language text-to-SQL generation (Text2SQL) aims to translate natural language questions into executable SQL queries. Although the emergence of large language models (LLMs) has led to significant advancements in this field, their performance degrades sharply with question complexity increases. A key limitation of current LLM-based methods lies in their uniform generation strategies, which fail to adapt dynamically to varying question complexity. To address this issue, we propose TriSQL, a novel three-stage framework designed to analyze question complexity and generate accurate and executable SQL. First, a Question-Guided Schema Selector is conceived to get the most relevant schema to the question using cross attention. Second, a Structure-Aware SQL Generator takes both the question and the selected schema as input, employing hierarchical decoding to generate a syntactically valid initial SQL. Finally, a Complexity-Aware SQL Refiner is designed with LLM to dynamically adjust strategies corresponding to the complexity of question and initial SQL, ensuring that the final generated SQL is both accurate and executable. Experimental results on the Spider benchmark and its variants show that TriSQL achieves state-of-the-art execution accuracy, surpasses existing LLM-based methods, and provides both high efficiency and strong robustness.<br /> (© 2026. The Author(s).) |
|---|---|
| ISSN: | 2045-2322 |
| DOI: | 10.1038/s41598-026-39128-9 |
Full Text Finder
Nájsť tento článok vo Web of Science