On Mitigating Code LLM Hallucinations with API Documentation
Not on the map. Why?
Abstract (arXiv)
In this study, we address the issue of API hallucinations in various software engineering contexts. We introduce CloudAPIBench, a new benchmark designed to measure API hallucination occurrences. CloudAPIBench also provides annotations for frequencies of API occurrences in the public domain, allowing us to study API hallucinations at various frequency levels. Our findings reveal that Code LLMs struggle with low frequency APIs: for e.g., GPT-4o achieves only 38.58% valid low frequency API invocations. We demonstrate that Documentation Augmented Generation (DAG) significantly improves performance for low frequency APIs (increase to 47.94% with DAG) but negatively impacts high frequency APIs when using sub-optimal retrievers (a 39.02% absolute drop). To mitigate this, we propose to intelligently trigger DAG where we check against an API index or leverage Code LLMs' confidence scores to retrieve only when needed. We demonstrate that our proposed methods enhance the balance between low and high frequency API performance, resulting in more reliable API invocations (8.20% absolute improvement on CloudAPIBench for GPT-4o).
Key facts. Cited by 21 papers in the map (data through 7 Oct 2026). Builds on 41 of its 58 references that are in the map. First posted on arXiv 13 Jul 2024.
Builds on
41 of 58 references.
References · 41
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2020Scaling Laws for Neural Language Modelscited by 6,411
- 2021Program Synthesis with Large Language Modelscited by 3,509
- 2023Code Llama: Open Foundation Models for Codecited by 2,105
- 2023ToolLLM: Facilitating Large Language Models to Master 16000+ Real-world APIscited by 1,880
- 2023Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflectioncited by 1,800
- 2022Language Models (Mostly) Know What They Knowcited by 1,783
- 2023Gorilla: Large Language Model Connected with Massive APIscited by 1,302
- 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,154
- 2022When Not to Trust Language Models: Investigating Effectiveness of Parametric and Non-Parametric Memoriescited by 1,103
- 2023Large Language Models Can Be Easily Distracted by Irrelevant Contextcited by 820
- 2023REPLUG: Retrieval-Augmented Black-Box Language Modelscited by 786
29 more
- 2023Active Retrieval Augmented Generationcited by 506
- 2024StarCoder 2 and The Stack v2: The Next Generationcited by 484
- 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 417
- 2023Making Retrieval-Augmented Language Models Robust to Irrelevant Contextcited by 364
- 2023RepoCoder: Repository-Level Code Completion Through Iterative Retrieval and Generationcited by 357
- 2023RepoBench: Benchmarking Repository-Level Code Auto-Completion Systemscited by 346
- 2023How Language Model Hallucinations Can Snowballcited by 310
- 2023The Impact of AI on Developer Productivity: Evidence from GitHub Copilotcited by 264
- 2022Prompting GPT-3 To Be Reliablecited by 258
- 2022Grounded Copilot: How Programmers Interact with Code-Generating Modelscited by 216
- 2023A Stitch in Time Saves Nine: Detecting and Mitigating Hallucinations of LLMs by Validating Low-Confidence Generationcited by 202
- 2023CrossCodeEval: A Diverse and Multilingual Benchmark for Cross-File Code Completioncited by 181
- 2022DocPrompting: Generating Code by Retrieving the Docscited by 151
- 2022GitHub Copilot AI pair programmer: Asset or Liability?cited by 150
- 2024Fine-grained Hallucination Detection and Editing for Language Modelscited by 146
- 2024CodeGemma: Open Code Models Based on Gemmacited by 145
- 2022Impact of Pretraining Term Frequencies on Few-Shot Reasoningcited by 142
- 2024To Believe or Not to Believe Your LLMcited by 120
- 2024Granite Code Models: A Family of Open Foundation Models for Code Intelligencecited by 116
- 2024Beyond Functional Correctness: Exploring Hallucinations in LLM-Generated Codecited by 106
- 2023Lift Yourself Up: Retrieval-augmented Text Generation with Self Memorycited by 103
- 2023Self-Knowledge Guided Retrieval Augmentation for Large Language Modelscited by 69
- 2023Shall We Pretrain Autoregressive Language Models with Retrieval? A Comprehensive Studycited by 63
- 2024API-BLEND: A Comprehensive Corpora for Training and Benchmarking API LLMscited by 39
- 2023Ever: Mitigating Hallucination in Large Language Models through Real-Time Verification and Rectificationcited by 38
- 2023A Static Evaluation of Code Completion by Large Language Modelscited by 14
- 2023How Well Do Large Language Models Truly Ground?cited by 14
- 2023Private-Library-Oriented Code Generation with Large Language Modelscited by 10
- 2023StubCoder: Automated Generation and Repair of Stub Code for Mock Objectscited by 1
Built on by
Citing papers per year: 2024: 5; 2025: 11; 2026: 5.
21 papers.
Sort:
By area:
- 2024Agents in Software Engineering: Survey, Landscape, and Visioncited by 60
- 2024Reducing Tool Hallucination via Reliability Alignmentcited by 37
- 2024An LLM Agent for Automatic Geospatial Data Analysiscited by 21
- 2025When LLMs Meet API Documentation: Can Retrieval Augmentation Aid Code Generation Just as It Helps Developers?cited by 12
- 2025Hallucination by Code Generation LLMs: Taxonomy, Benchmarks, Mitigation, and Challengescited by 9
- 2024Retrieval-Augmented Test Generation: How Far Are We?cited by 7
- 2024A Methodology for Evaluating RAG Systems: A Case Study On Configuration Dependency Validationcited by 6
- 2025Towards Mitigating API Hallucination in Code Generated by LLMs with Hierarchical Dependency Awarecited by 6
- 2025Agent WARPP: Workflow Adherence via Runtime Parallel Personalizationcited by 3
- 2025Isolating Language-Coding from Problem-Solving: Benchmarking LLMs with PseudoEvalcited by 2
- 2025CCCI: Code Completion with Contextual Information for Complex Data Transfer Tasks Using Large Language Modelscited by 2
- 2025FalseCrashReducer: Mitigating False Positive Crashes in OSS-Fuzz-Gen Using Agentic AIcited by 2
9 more
- 2025Library Hallucinations in LLM-Generated Code: A Risk Analysis Grounded in Developer Queriescited by 1
- 2025HFuzzer: Testing Large Language Models for Package Hallucinations via Phrase-based Fuzzingcited by 1
- 2026Bridging Generation and Training: A Systematic Review of Quality Issues in LLMs for Codecited by 1
- 2026Correct Code, Vulnerable Dependencies: A Large Scale Measurement Study of LLM-Specified Library Versionscited by 1
- 2025Improving Multi-turn Task Completion in Task-Oriented Dialog Systems via Prompt Chaining and Fine-Grained Feedbackcited by 0
- 2025Benchmarking Web API Integration Code Generationcited by 0
- 2026LibEvoBench: Probing Temporal Knowledge Stratification in Code Generation Modelscited by 0
- 2026Skills That Don't Exist: A Large-Scale Study of Hallucinated Skill Recommendation in LLM Agentscited by 0
- 2026Can Agents Design Libraries for Agents?cited by 0
- 2026Can Agents Design Libraries for Agents?29 Sep 2026
- 2026Skills That Don't Exist: A Large-Scale Study of Hallucinated Skill Recommendation in LLM Agents14 Jul 2026
- 2026LibEvoBench: Probing Temporal Knowledge Stratification in Code Generation Models24 Jun 2026
- 2026Correct Code, Vulnerable Dependencies: A Large Scale Measurement Study of LLM-Specified Library Versions7 May 2026
- 2026Bridging Generation and Training: A Systematic Review of Quality Issues in LLMs for Code6 May 2026
- 2025FalseCrashReducer: Mitigating False Positive Crashes in OSS-Fuzz-Gen Using Agentic AI2 Oct 2025
- 2025HFuzzer: Testing Large Language Models for Package Hallucinations via Phrase-based Fuzzing28 Sep 2025
- 2025Library Hallucinations in LLM-Generated Code: A Risk Analysis Grounded in Developer Queries26 Sep 2025
- 2025Benchmarking Web API Integration Code Generation24 Sep 2025
- 2025Agent WARPP: Workflow Adherence via Runtime Parallel Personalization23 Jul 2025
- 2025Towards Mitigating API Hallucination in Code Generated by LLMs with Hierarchical Dependency Aware8 May 2025
- 2025Hallucination by Code Generation LLMs: Taxonomy, Benchmarks, Mitigation, and Challenges29 Apr 2025
9 more
- 2025CCCI: Code Completion with Contextual Information for Complex Data Transfer Tasks Using Large Language Models29 Mar 2025
- 2025When LLMs Meet API Documentation: Can Retrieval Augmentation Aid Code Generation Just as It Helps Developers?19 Mar 2025
- 2025Isolating Language-Coding from Problem-Solving: Benchmarking LLMs with PseudoEval26 Feb 2025
- 2025Improving Multi-turn Task Completion in Task-Oriented Dialog Systems via Prompt Chaining and Fine-Grained Feedback18 Feb 2025
- 2024Reducing Tool Hallucination via Reliability Alignment5 Dec 2024
- 2024An LLM Agent for Automatic Geospatial Data Analysis24 Oct 2024
- 2024A Methodology for Evaluating RAG Systems: A Case Study On Configuration Dependency Validation11 Oct 2024
- 2024Retrieval-Augmented Test Generation: How Far Are We?19 Sep 2024
- 2024Agents in Software Engineering: Survey, Landscape, and Vision13 Sep 2024
- 2024Agents in Software Engineering: Survey, Landscape, and Visioncited by 60
- 2024Reducing Tool Hallucination via Reliability Alignmentcited by 37
- 2024An LLM Agent for Automatic Geospatial Data Analysiscited by 21
- 2025Agent WARPP: Workflow Adherence via Runtime Parallel Personalizationcited by 3
- 2025FalseCrashReducer: Mitigating False Positive Crashes in OSS-Fuzz-Gen Using Agentic AIcited by 2
- 2026Skills That Don't Exist: A Large-Scale Study of Hallucinated Skill Recommendation in LLM Agentscited by 0
- 2026Skills That Don't Exist: A Large-Scale Study of Hallucinated Skill Recommendation in LLM Agents14 Jul 2026
- 2025FalseCrashReducer: Mitigating False Positive Crashes in OSS-Fuzz-Gen Using Agentic AI2 Oct 2025
- 2025Agent WARPP: Workflow Adherence via Runtime Parallel Personalization23 Jul 2025
- 2024Reducing Tool Hallucination via Reliability Alignment5 Dec 2024
- 2024An LLM Agent for Automatic Geospatial Data Analysis24 Oct 2024
- 2024Agents in Software Engineering: Survey, Landscape, and Vision13 Sep 2024
- 2025When LLMs Meet API Documentation: Can Retrieval Augmentation Aid Code Generation Just as It Helps Developers?cited by 12
- 2024Retrieval-Augmented Test Generation: How Far Are We?cited by 7
- 2024A Methodology for Evaluating RAG Systems: A Case Study On Configuration Dependency Validationcited by 6
- 2025Towards Mitigating API Hallucination in Code Generated by LLMs with Hierarchical Dependency Awarecited by 6
- 2025Towards Mitigating API Hallucination in Code Generated by LLMs with Hierarchical Dependency Aware8 May 2025
- 2025When LLMs Meet API Documentation: Can Retrieval Augmentation Aid Code Generation Just as It Helps Developers?19 Mar 2025
- 2024A Methodology for Evaluating RAG Systems: A Case Study On Configuration Dependency Validation11 Oct 2024
- 2024Retrieval-Augmented Test Generation: How Far Are We?19 Sep 2024
- 2025Hallucination by Code Generation LLMs: Taxonomy, Benchmarks, Mitigation, and Challengescited by 9
- 2025Isolating Language-Coding from Problem-Solving: Benchmarking LLMs with PseudoEvalcited by 2
- 2025CCCI: Code Completion with Contextual Information for Complex Data Transfer Tasks Using Large Language Modelscited by 2
- 2025Library Hallucinations in LLM-Generated Code: A Risk Analysis Grounded in Developer Queriescited by 1
- 2025HFuzzer: Testing Large Language Models for Package Hallucinations via Phrase-based Fuzzingcited by 1
- 2026Bridging Generation and Training: A Systematic Review of Quality Issues in LLMs for Codecited by 1
- 2026Correct Code, Vulnerable Dependencies: A Large Scale Measurement Study of LLM-Specified Library Versionscited by 1
- 2025Improving Multi-turn Task Completion in Task-Oriented Dialog Systems via Prompt Chaining and Fine-Grained Feedbackcited by 0
- 2025Benchmarking Web API Integration Code Generationcited by 0
- 2026LibEvoBench: Probing Temporal Knowledge Stratification in Code Generation Modelscited by 0
- 2026Can Agents Design Libraries for Agents?cited by 0
- 2026Can Agents Design Libraries for Agents?29 Sep 2026
- 2026LibEvoBench: Probing Temporal Knowledge Stratification in Code Generation Models24 Jun 2026
- 2026Correct Code, Vulnerable Dependencies: A Large Scale Measurement Study of LLM-Specified Library Versions7 May 2026
- 2026Bridging Generation and Training: A Systematic Review of Quality Issues in LLMs for Code6 May 2026
- 2025HFuzzer: Testing Large Language Models for Package Hallucinations via Phrase-based Fuzzing28 Sep 2025
- 2025Library Hallucinations in LLM-Generated Code: A Risk Analysis Grounded in Developer Queries26 Sep 2025
- 2025Benchmarking Web API Integration Code Generation24 Sep 2025
- 2025Hallucination by Code Generation LLMs: Taxonomy, Benchmarks, Mitigation, and Challenges29 Apr 2025
- 2025CCCI: Code Completion with Contextual Information for Complex Data Transfer Tasks Using Large Language Models29 Mar 2025
- 2025Isolating Language-Coding from Problem-Solving: Benchmarking LLMs with PseudoEval26 Feb 2025
- 2025Improving Multi-turn Task Completion in Task-Oriented Dialog Systems via Prompt Chaining and Fine-Grained Feedback18 Feb 2025