Agentic Text-to-SQL in Enterprise Environments: Balancing Planning Paradigms and Pragmatic Self-Repair

  • Renato Miyaji Grupo Visagio
  • Vitor Bedin Grupo Visagio
  • João Victor Monteiro Macedo Grupo Visagio
  • Renato Moulin Grupo Visagio
  • Leonardo Machado Grupo Visagio

Resumo


The rapid adoption of Large Language Models (LLMs) has revolutionized Text-to-SQL systems, yet translating queries in complex enterprise environments remains challenging due to schema hallucinations and domain-specific jargon. We propose a multi-agent architecture that replaces internal generative self-correction with a database-driven self-repair loop and a two-tier Retrieval-Augmented Generation (RAG) system. We evaluate multiple planning and tool-use methods using a real-world corporate dataset. Our findings reveal that dual-system reasoning architectures provide an optimal balance of syntactic precision and user intent alignment. Furthermore, heavy iterative self-refinement introduces latency without proportional execution gains. This work establishes guidelines for designing reliable Text-to-SQL agents by decoupling cognitive planning from deterministic technical execution.

Referências

Albrecht, A. (2009). sqlparse: A non-validating sql parser for python.

Baptista, J. V. R. and Garcia, L. P. F. (2025). Graphrag on electronic health record: A knowledge graph-enhanced rag approach for healthcare information access. In Brazilian Conference on Intelligent Systems (BRACIS), volume 35, pages 615–630, Porto Alegre. Sociedade Brasileira de Computação.

Broder, A. Z. (1997). On the resemblance and containment of documents. In Compression and Complexity of Sequences (SEQUENCES).

Brown, T. B., Mann, B., Ryder, N., Subbiah, M., Kaplan, J., Dhariwal, P., Neelakantan, A., Shyam, P., Sastry, G., Askell, A., Agarwal, S., Herbert-Voss, A., Krueger, G., Henighan, T., Child, R., Ramesh, A., Ziegler, D. M., Wu, J., Winter, C., Hesse, C., Chen, M., Sigler, E., Litwin, M., Gray, S., Chess, B., Clark, J., Berner, C., McCandlish, S., Radford, A., Sutskever, I., and Amodei, D. (2020). Language models are few-shot learners. In Advances in Neural Information Processing Systems (NeurIPS).

Cao, B., Liao, W., Sun, Y., Fang, D., Li, H., and Lam, W. (2026). Apex-sql: Talking to the data via agentic exploration for text-to-sql. arXiv preprint arXiv:2602.16720.

Chaturvedi, S., Chadha, A., and Bindschaedler, L. (2024). Sql-of-thought: Multi-agentic text-to-sql with guided error correction. In Advances in Neural Information Processing Systems (NeurIPS).

Chen, Z., Chen, S., White, M., Mooney, R., Payani, A., Srinivasa, J., Su, Y., and Sun, H. (2023). Text-to-sql error correction with language models of code. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (ACL).

Eckmann, M. et al. (2025). Hlr-sql: Human-like reasoning for text-to-sql with the human in the loop. Information Systems.

Hong, Z., Chen, H., Yuan, Z., Zhang, Q., Zhuang, L., Liao, Q., Huang, F., Song, Y., and Huang, X. (2026). Errorllm: Modeling sql errors for text-to-sql refinement. arXiv preprint arXiv:2603.03742.

Ip, J. (2023). Deepeval: The llm evaluation framework. Confident AI.

Kahneman, D. (2011). Thinking, Fast and Slow. Farrar, Straus and Giroux.

Kamoi, R., Zhang, Y., Zhang, N., Han, J., and Zhang, R. (2024). When can llms actually correct their own mistakes? a critical survey of self-correction of llms. Transactions of the Association for Computational Linguistics, 12:1417–1440.

Katsogiannis-Meimarakis, G. and Koutrika, G. (2023). A survey on deep learning approaches for text-to-sql. The VLDB Journal.

Lin, B. Y., Fu, Y., Yang, K., Ammanabrolu, P., Brahman, F., Huang, S., Bhagavatula, C., Choi, Y., and Ren, X. (2023). Swiftsage: A generative agent with fast and slow thinking for complex interactive tasks. In Advances in Neural Information Processing Systems (NeurIPS).

Liu, X., Shen, S., Li, B., Ma, P., Jiang, R., Zhang, Y., Fan, J., Li, G., Tang, N., and Luo, Y. (2025). A survey of text-to-sql in the era of llms: Where are we, and where are we going? IEEE Transactions on Knowledge and Data Engineering.

Liu, Y., Iter, D., Xu, Y., Wang, S., Xu, R., and Zhu, C. (2023). G-eval: Nlg evaluation using gpt-4 with better human alignment. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, pages 2511–2522, Singapore. Association for Computational Linguistics.

Madaan, A., Tandon, N., Gupta, P., Hallinan, S., Gao, L., Wiegreffe, S., Alon, U., Dziri, N., Prabhumoye, S., Yang, Y., Gupta, S., Majumder, B. P., Hermann, K., Welleck, S., Yazdanbakhsh, A., and Clark, P. (2023). Self-refine: Iterative refinement with self-feedback. In Advances in Neural Information Processing Systems (NeurIPS).

Martinelli, I. and Ponti, M. A. (2025). Towards secure retrieval-augmented generation: Preventing llm data leaks with rbac. In Brazilian Conference on Intelligent Systems (BRACIS), volume 35, pages 500–515, Porto Alegre. Sociedade Brasileira de Computação.

Mekala, D., Weston, J., Lanchantin, J., Raileanu, R., Lomeli, M., Shang, J., and Dwivedi-Yu, J. (2024). Toolverifier: Generalization to new tools via self-verification. In Conference on Empirical Methods in Natural Language Processing (EMNLP).

Pinna, G., Perezhohin, Y., Manzoni, L., et al. (2025). Redefining text-to-sql metrics by incorporating semantic and structural similarity. Scientific Reports.

Pourreza, M., Li, H., Sun, R., Chung, Y., Talaei, S., Kakkar, G. T., Gan, Y., Saberi, A., Ozcan, F., and Arik, S. (2025). Chase-sql: Multi-path reasoning and preference optimized candidate selection in text-to-sql. In International Conference on Learning Representations (ICLR) Workshop.

Shi, L., Tang, Z., Zhang, N., Zhang, X., and Yang, Z. (2025). A survey on employing large language models for text-to-sql tasks. ACM Computing Surveys.

Shinn, N., Cassano, F., Berman, E., Gopinath, A., Narasimhan, K., and Yao, S. (2023). Reflexion: Language agents with verbal reinforcement learning. In Advances in Neural Information Processing Systems (NeurIPS).

Talaei, S., Pourreza, M., Chang, Y.-C., Mirhoseini, A., and Saberi, A. (2024). Chess: Contextual harnessing for efficient sql synthesis. arXiv preprint arXiv:2405.16755.

Wang, X., Wei, J., Schuurmans, D., Le, Q. V., Chi, E. H., Narang, S., Chowdhery, A., and Zhou, D. (2023). Self-consistency improves chain of thought reasoning in language models. In International Conference on Learning Representations (ICLR).

Xu, B., Peng, Z., Lei, B., Mukherjee, S., Liu, Y., and Xu, D. (2023). Rewoo: Decoupling reasoning from observations for efficient augmented language models. arXiv preprint arXiv:2305.18323.

Yao, S., Zhao, J., Yu, D., Du, N., Shafran, I., Narasimhan, K., and Cao, Y. (2023). React: Synergizing reasoning and acting in language models. In International Conference on Learning Representations.

Zhang, X., Liu, Y., Wang, Z., et al. (2026). Text-to-graph query using semantic subgraph retrieval. Knowledge-Based Systems.
Publicado
19/10/2026
MIYAJI, Renato; BEDIN, Vitor; MACEDO, João Victor Monteiro; MOULIN, Renato; MACHADO, Leonardo. Agentic Text-to-SQL in Enterprise Environments: Balancing Planning Paradigms and Pragmatic Self-Repair. In: ENCONTRO NACIONAL DE INTELIGÊNCIA ARTIFICIAL E COMPUTACIONAL (ENIAC), 23. , 2026, Cuiabá/MT. Anais [...]. Porto Alegre: Sociedade Brasileira de Computação, 2026 . p. 753-764. ISSN 2763-9061. DOI: https://doi.org/10.5753/eniac.2026.30325.