What is it about?
Many people would like to ask questions about databases using everyday language instead of writing complex SQL queries. Modern AI models can often translate these natural language questions into SQL, but they still make mistakes—especially when the database structure is unfamiliar or when the same type of question is asked in slightly different ways. This paper introduces a new method called Template Constrained Decoding (TeCoD) that makes these translations more reliable for recurring questions—questions that follow similar patterns but differ in details such as names, dates, or numbers. TeCoD learns from previously answered questions and turns them into reusable “templates.” When a new question arrives, the system checks whether it matches one of these templates. If it does, the AI is guided to follow that template while filling in only the necessary details. By constraining the AI’s output in this way, TeCoD greatly reduces errors and ensures that the generated SQL is both valid and faithful to the intended structure. Experiments across multiple benchmarks and language models show that this approach produces far more accurate answers and runs faster than common prompting methods alone.
Featured Image
Photo by Mika Baumeister on Unsplash
Why is it important?
Most real-world organizations repeatedly ask similar analytical questions about their data, even if the wording changes. Existing Text-to-SQL systems treat each question almost independently, which wastes this valuable history and leads to inconsistent performance. This work is unique because it explicitly exploits repetition in enterprise workloads. Instead of only showing past examples to the AI, it locks in the known structure of successful queries and uses it to guide future generations. As a result, TeCoD can raise accuracy for matched (recurring) questions from around 60% with standard in-context learning to close to 90%, while also reducing response time. The practical impact is significant: businesses can obtain more trustworthy answers for their most common queries without expensive model fine-tuning or massive labeled datasets. This makes natural language database interfaces more dependable, cost-effective, and suitable for everyday use in production systems.
Read the Original
This page is a summary of: Reliable Answers for Recurring Questions: Boosting Text-to-SQL Accuracy with Template Constrained Decoding, Proceedings of the ACM on Management of Data, December 2025, ACM (Association for Computing Machinery),
DOI: 10.1145/3769822.
You can read the full text:
Resources
Contributors
The following have contributed to this page







