Researchers at the Korea Advanced Institute of Science and Technology (KAIST) have developed a technology that fixes only the incorrect parts when AI makes mistakes while searching corporate databases, without having to rebuild everything from scratch.
KAIST said on Thursday that a team led by Min-su Kim (김민수), a professor in the School of Computing, developed SafeQL, a technology that step-by-step corrects errors that occur when converting natural-language questions into SQL (Structured Query Language) database queries.
Use of "text to SQL" technology is increasing, with AI converting everyday questions such as "What was the best-selling product last year?" into SQL to retrieve corporate sales, customer and inventory data.
But if AI uses tables or fields that do not exist in the database or links data incorrectly, the query command may not run. Previously, when such errors occurred, the entire SQL was sent back to a large language model (LLM) to be generated anew. This process could create new errors and increased costs and time as the LLM was used repeatedly.
Instead of regenerating the entire SQL, SafeQL finds and fixes only the incorrect parts based on database error information and what is actually stored. It step-by-step corrects missing tables or fields, missing data joins, incorrect functions or search values.
The team applied a "Safe Query Space" method that checks, among multiple correction candidates, those closest to the original AI-generated SQL first. It also reduced the time required for correction by excluding in advance candidates with mismatched data types or low relevance.
SafeQL was implemented inside PostgreSQL, an open-source database management program. Only when partial fixes are difficult does it call the LLM again, reducing unnecessary AI use.
The team verified performance using Bird and Spider, international text-to-SQL benchmarks. On Bird, it resolved up to 87.4 percent of initial SQL execution errors, while reducing token use by up to 15.1 times and correction time by up to 29.6 times compared with existing methods. On Spider, it also confirmed performance by recording 91.7 percent execution accuracy.
The team expects SafeQL can be used in various areas including enterprise AI agents, natural-language data analysis, business intelligence and data-analysis copilots.
Kim said, "For AI to take on real work in companies, it is important to find the required data accurately." He added, "SafeQL is a technology that reduces AI errors, costs and time at the same time."
The research involved KAIST School of Computing researcher Geon-ho Lee (이건호) as first author and Kim as corresponding author. The results will be presented at VLDB, an international conference in the database field to be held in Boston in the United States.