SafeQL: Search-based Refinement for Safe and Efficient LLM-based Text-to-SQL

📅 2026-08-10
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
This work addresses the challenge that SQL queries generated by large language models (LLMs) often violate database schemas, leading to invalid outputs. Existing approaches typically rely on full query regeneration, which is inefficient and prone to repeating errors. To overcome this limitation, the paper introduces a search-based refinement paradigm that repositions the database management system (DBMS) from a passive feedback provider to an active guide. By parsing DBMS execution feedback, the method incrementally repairs only the erroneous segments of a query and iteratively validates candidate solutions within a constrained, safe query space. Integrating LLM capabilities with DBMS feedback and constraint-guided local search, the proposed approach achieves significant improvements in both execution accuracy and inference efficiency on the Bird and Spider benchmarks, outperforming conventional regeneration strategies.
📝 Abstract
Large language models (LLMs) have advanced Text-to-SQL by enabling natural language interfaces to databases without task-specific fine-tuning. However, existing LLM-based systems remain unreliable, often generating SQL queries that are invalid under the database schema, referencing non-existent tables, attributes, functions, or values. Such errors persist because interactions with the database management system (DBMS) are typically limited to error messages, leaving it in a largely passive role during query refinement. This paper proposes SafeQL, \textit{a search-based refinement paradigm that redefines the role of the DBMS as an active guide in the refinement process}. Instead of regenerating entire queries after execution failure, SafeQL interprets DBMS feedback to incrementally repair only the erroneous components. Each refinement step is formulated as a guided search within a \textit{safe query space}, where candidate queries are progressively validated through DBMS execution, thereby converging to an executable query and preventing repeated regeneration of errors. Experiments on the Bird and Spider benchmarks show that SafeQL significantly improves execution accuracy and efficiency compared to regeneration-based methods.
Problem

Research questions and friction points this paper is trying to address.

Text-to-SQL
LLM reliability
SQL generation errors
DBMS feedback
query refinement
Innovation

Methods, ideas, or system contributions that make the work stand out.

search-based refinement
DBMS-guided repair
safe query space
incremental SQL repair
Text-to-SQL
🔎 Similar Papers