Mitigating LLM hallucinations in Text-to-SQL parsing with a self-refinement feedback loop and memory augmentation
摘要
With the rapid advancements in large language models (LLMs), the overall performance of Text-to-SQL systems has improved significantly. LLM-based approaches have demonstrated strong capabilities in both schema linking and SQL generation. However, due to undesirable behaviors exhibited by LLMs during reasoning, mainstream methods still suffer from issues such as incorrect value generation, errors in database schema elements, and logical inconsistencies that deviate from user intent. In this paper, we propose a Self-Refinement Feedback Loop and introduce a memory architecture comprising long-term and short-term components to enhance both the timeliness and generalization ability of the model. The correction loop enables the LLM to identify flawed SQL queries, analyze their underlying issues, generate verbal feedback, and iteratively refine the queries based on this feedback–thereby mitigating the negative effects of LLM hallucinations in Text-to-SQL tasks. We integrate our method with existing Text-to-SQL models, including DIN-SQL and DAIL-SQL, and evaluate it on the BIRD dataset. Experimental results show that our approach can effectively improve the performance of these models. We release code on https://github.com/MKMaS-GUET/SRFL-main.