Reliable Answers for Recurring Questions: Boosting Text-to-SQL Accuracy with Template Constrained Decoding
Open Access
- 4 December 2025
- journal article
- Published by Association for Computing Machinery (ACM) in Proceedings of the ACM on Management of Data
- Vol. 3 (6) , 1-26
Abstract
Large language models (LLMs) have revolutionized Text-to-SQL generation, allowing users to query structured data using natural language with growing ease. Yet, real-world deployment remains challenging, especially in complex or unseen schemas, due to inconsistent accuracy and the risk of generating invalid SQL. We introduce Template Constrained Decoding (TeCoD), a system that addresses these limitations by harnessing the recurrence of query patterns in labeled workloads. TeCoD converts historical NL-SQL pairs into reusable templates and introduces a robust template selection module that uses a fine-tuned natural language inference model to match or reject queries efficiently. Once the template is selected, TeCoD enforces it during SQL generation through grammar-constrained decoding, implemented via a novel partitioned strategy that ensures both syntactic validity and efficiency. Together, these components yield up to 36% higher execution accuracy than in-context learning (ICL) and 2.2× lower latency on matched queries.Keywords
All Related Versions
This publication has 17 references indexed in Scilit:
- Optimizing Reasoning for Text-to-SQL with Execution Feedback2025
- Combining Small Language Models and Large Language Models for Zero-Shot NL2SQLProceedings of the VLDB Endowment, 2024
- RESDSQL: Decoupling Schema Linking and Skeleton Parsing for Text-to-SQLProceedings of the AAAI Conference on Artificial Intelligence, 2023
- CatSQL : Towards Real World Natural Language to SQL ApplicationsProceedings of the VLDB Endowment, 2023
- ACT-SQL: In-Context Learning for Text-to-SQL with Automatically-Generated Chain-of-Thought2023
- CRUSH4SQL: Collective Retrieval Using Schema Hallucination For Text2SQL2023
- Diverse Parallel Data Synthesis for Cross-Database Adaptation of Text-to-SQL Parsers2022
- RAT-SQL: Relation-Aware Schema Encoding and Linking for Text-to-SQL Parsers2020
- Natural Language Data Management and Interfaces2017
- Constructing an interactive natural language interface for relational databasesProceedings of the VLDB Endowment, 2014