Reliable Answers for Recurring Questions: Boosting Text-to-SQL Accuracy with Template Constrained Decoding
Smit Jivani, Sarvam Maheshwari, Sunita Sarawagi
TLDR
TeCoD boosts Text-to-SQL accuracy and reliability by using reusable templates and constrained decoding for recurring query patterns.
Key contributions
- Converts historical NL-SQL pairs into reusable templates for recurring query patterns.
- Employs a fine-tuned NLI model for robust and efficient template selection.
- Enforces templates during SQL generation via novel grammar-constrained decoding.
- Achieves up to 36% higher accuracy and 2.2x lower latency on matched queries.
Why it matters
LLM-based Text-to-SQL struggles with accuracy and invalid outputs, hindering real-world deployment. TeCoD offers a practical solution by leveraging recurring query patterns, significantly boosting reliability and efficiency. This makes LLM-generated SQL more robust for complex, unseen schemas.
Original 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.2x lower latency on matched queries.
📬 Weekly AI Paper Digest
Get the top 10 AI/ML arXiv papers from the week — summarized, scored, and delivered to your inbox every Monday.