- Token usage cut by up to 15.1 times; correction time reduced by up to 29.6 times
- Lower AI costs and higher reliability expected to accelerate practical use of AI agents
South Korean researchers have developed a technology that identifies and corrects only the flawed parts of AI-generated database queries — without rewriting them from scratch. The advance is drawing attention as a potential accelerator for commercial AI workplace assistants, as it could significantly cut the time and cost companies incur when deploying AI for business tasks.
KAIST announced Friday that a research team led by Professor Kim Min-su of the School of Computing has developed SafeQL, a system that detects and incrementally repairs errors that arise when natural-language questions are converted into SQL (Structured Query Language) database commands.
Companies are increasingly using "Text-to-SQL" technology, which lets employees ask questions in everyday language and have AI translate them into SQL to retrieve data on sales, customers, inventory and more. The problem is that AI makes mistakes. If a generated query references a table or field that does not exist in the database, or incorrectly joins data, the SQL fails to execute.
Until now, when such errors occurred, the error information was sent back to a large language model (LLM) — the technology underlying generative AI tools such as ChatGPT — to regenerate the entire SQL query. That process risks altering parts that were already correct or introducing new errors, and repeatedly calling the LLM drives up both costs and processing time.
SafeQL takes a fundamentally different approach. Rather than asking AI to regenerate the entire query, it uses the error information returned by the database along with the actual stored data to pinpoint the faulty section and correct only that part.
The system checks whether nonexistent tables or fields were referenced, then works through missing data joins, misused functions and incorrect search values in sequence. It calls the LLM again only when a targeted fix cannot resolve the problem, keeping unnecessary AI usage to a minimum.
The research team also designed a "Safe Query Space" method that searches first for the fix closest to the AI's original query among all executable candidates in the database. Rather than checking every possible fix indiscriminately, the system prioritizes candidates most likely to work and eliminates low-probability ones early, reducing processing time.
Validated against the BIRD and Spider benchmarks widely used to evaluate AI database search performance, SafeQL resolved up to 87.4 percent of execution errors in AI-generated SQL on the BIRD benchmark. It also improved execution accuracy — the rate at which the correct answer is retrieved — by up to 5.8 percentage points over the previous best-performing technology.
Compared with the conventional approach of having AI regenerate the entire SQL query, SafeQL reduced AI token usage by up to 15.1 times and cut error-correction time by up to 29.6 times.
"SafeQL corrects only the flawed parts instead of starting over when AI makes a mistake during a search, reducing errors, costs and time all at once," Professor Kim said. "We expect it to accelerate reliable AI workplace automation."
nbgkoo@heraldcorp.com