De-Hallucinator: Mitigating LLM Hallucinations in Code Generation Tasks via Iterative Grounding
Not on the map. Why?
Abstract (arXiv)
Large language models (LLMs) trained on datasets of publicly available source code have established a new state of the art in code generation tasks. However, these models are mostly unaware of the code that exists within a specific project, preventing the models from making good use of existing APIs. Instead, LLMs often invent, or "hallucinate", non-existent APIs or produce variants of already existing code. This paper presents De-Hallucinator, a technique that grounds the predictions of an LLM through a novel combination of retrieving suitable API references and iteratively querying the model with increasingly suitable context information in the prompt. The approach exploits the observation that predictions by LLMs often resemble the desired code, but they fail to correctly refer to already existing APIs. De-Hallucinator automatically identifies project-specific API references related to the model's initial predictions and adds these references into the prompt. Unlike retrieval-augmented generation (RAG), our approach uses the initial prediction(s) by the model to iteratively retrieve increasingly suitable API references. Our evaluation applies the approach to two tasks: predicting API usages in Python and generating tests in JavaScript. We show that De-Hallucinator consistently improves the generated code across five LLMs. In particular, the approach improves the edit distance by 23.3-50.6% and the recall of correctly predicted API usages by 23.9-61.0% for code completion, and improves the number of fixed tests that initially failed because of hallucinations by 63.2%, resulting in a 15.5% increase in statement coverage for test generation.
Key facts. Cited by 14 papers in the map (data through 7 Oct 2026). First posted on arXiv 3 Jan 2024.
Builds on
No reference list yet.
Built on by
Citing papers per year: 2024: 1; 2025: 7; 2026: 6.
14 papers.
Sort:
By area:
- 2025Understanding Software Engineering Agents: A Study of Thought-Action-Result Trajectoriescited by 75
- 2025What to Retrieve for Effective Retrieval-Augmented Code Generation? An Empirical Study and Beyondcited by 22
- 2025Retrieval-Augmented Code Generation: A Survey with Focus on Repository-Level Approachescited by 20
- 2025Hallucination by Code Generation LLMs: Taxonomy, Benchmarks, Mitigation, and Challengescited by 9
- 2024Assessing the Latent Automated Program Repair Capabilities of Large Language Models using Round-Trip Translationcited by 3
- 2025Hallucination in LLM-Based Code Generation: An Automotive Case Studycited by 2
- 2025Library Hallucinations in LLM-Generated Code: A Risk Analysis Grounded in Developer Queriescited by 1
- 2026FASE: Fast Adaptive Semantic Entropy for Code Qualitycited by 1
- 2025Intent-Driven Storage Systems: From Low-Level Tuning to High-Level Understandingcited by 0
- 2026An Empirical Analysis of Static Analysis Methods for Detection and Mitigation of Code Library Hallucinationscited by 0
- 2026Neuro-Symbolic Agents for Hallucination-Free Requirements Reusecited by 0
- 2026Task Abstention for Large Language Models in Code Generationcited by 0
- 2026Model-Driven Requirements Configuration with Three-Valued Uncertainty Scoring28 Jul 2026
- 2026Mitigating Errors in LLM-Generated Web API Invocations via Retrieval-Augmented Generation and Constrained Decoding7 Jul 2026
- 2026FASE: Fast Adaptive Semantic Entropy for Code Quality8 Jun 2026
- 2026Task Abstention for Large Language Models in Code Generation16 May 2026
- 2026Neuro-Symbolic Agents for Hallucination-Free Requirements Reuse2 May 2026
- 2026An Empirical Analysis of Static Analysis Methods for Detection and Mitigation of Code Library Hallucinations9 Apr 2026
- 2025Retrieval-Augmented Code Generation: A Survey with Focus on Repository-Level Approaches6 Oct 2025
- 2025Intent-Driven Storage Systems: From Low-Level Tuning to High-Level Understanding29 Sep 2025
- 2025Library Hallucinations in LLM-Generated Code: A Risk Analysis Grounded in Developer Queries26 Sep 2025
- 2025Hallucination in LLM-Based Code Generation: An Automotive Case Study15 Aug 2025
- 2025Understanding Software Engineering Agents: A Study of Thought-Action-Result Trajectories23 Jun 2025
- 2025Hallucination by Code Generation LLMs: Taxonomy, Benchmarks, Mitigation, and Challenges29 Apr 2025
- 2025What to Retrieve for Effective Retrieval-Augmented Code Generation? An Empirical Study and Beyondcited by 22
- 2025Retrieval-Augmented Code Generation: A Survey with Focus on Repository-Level Approachescited by 20
- 2026Mitigating Errors in LLM-Generated Web API Invocations via Retrieval-Augmented Generation and Constrained Decodingcited by 0
- 2026Mitigating Errors in LLM-Generated Web API Invocations via Retrieval-Augmented Generation and Constrained Decoding7 Jul 2026
- 2025Retrieval-Augmented Code Generation: A Survey with Focus on Repository-Level Approaches6 Oct 2025
- 2025What to Retrieve for Effective Retrieval-Augmented Code Generation? An Empirical Study and Beyond26 Mar 2025
- 2025Hallucination by Code Generation LLMs: Taxonomy, Benchmarks, Mitigation, and Challengescited by 9
- 2024Assessing the Latent Automated Program Repair Capabilities of Large Language Models using Round-Trip Translationcited by 3
- 2025Hallucination in LLM-Based Code Generation: An Automotive Case Studycited by 2
- 2025Library Hallucinations in LLM-Generated Code: A Risk Analysis Grounded in Developer Queriescited by 1
- 2026FASE: Fast Adaptive Semantic Entropy for Code Qualitycited by 1
- 2025Intent-Driven Storage Systems: From Low-Level Tuning to High-Level Understandingcited by 0
- 2026An Empirical Analysis of Static Analysis Methods for Detection and Mitigation of Code Library Hallucinationscited by 0
- 2026Task Abstention for Large Language Models in Code Generationcited by 0
- 2026Model-Driven Requirements Configuration with Three-Valued Uncertainty Scoringcited by 0
- 2026Model-Driven Requirements Configuration with Three-Valued Uncertainty Scoring28 Jul 2026
- 2026FASE: Fast Adaptive Semantic Entropy for Code Quality8 Jun 2026
- 2026Task Abstention for Large Language Models in Code Generation16 May 2026
- 2026An Empirical Analysis of Static Analysis Methods for Detection and Mitigation of Code Library Hallucinations9 Apr 2026
- 2025Intent-Driven Storage Systems: From Low-Level Tuning to High-Level Understanding29 Sep 2025
- 2025Library Hallucinations in LLM-Generated Code: A Risk Analysis Grounded in Developer Queries26 Sep 2025
- 2025Hallucination in LLM-Based Code Generation: An Automotive Case Study15 Aug 2025
- 2025Hallucination by Code Generation LLMs: Taxonomy, Benchmarks, Mitigation, and Challenges29 Apr 2025
- 2024Assessing the Latent Automated Program Repair Capabilities of Large Language Models using Round-Trip Translation15 Jan 2024
Similar, not cited
Close in wording, no citation either way
- 2025Towards Mitigating API Hallucination in Code Generated by LLMs with Hierarchical Dependency Aware
- 2024LLM Hallucinations in Practical Code Generation: Phenomena, Mechanism, and Mitigation
- 2026Are you Synthesizing or Recalling? Evaluating LLMs on Algorithmic Code Retrieval
- 2026When LLMs Lag Behind: Knowledge Conflicts from Evolving APIs in Code Generation
- 2024A Comprehensive Framework for Evaluating API-oriented Code Generation in Large Language Models
- 2026HalluJudge: A Reference-Free Hallucination Detection for Context Misalignment in Code Review Automation
- 2026Diagnosing Knowledge Gaps in LLM Tool Use: An Agentic Benchmark for Novel API Acquisition
- 2024Iterative Refinement of Project-Level Code Context for Precise Code Generation with Compiler Feedback