On Mitigating Code LLM Hallucinations with API Documentation
Authors:
- 27 April 2025
- conference paper
- Published by Institute of Electrical and Electronics Engineers (IEEE)
- p. 237-248
Abstract
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).Keywords
All Related Versions
This publication has 15 references indexed in Scilit:
- Private-library-oriented code generation with large language modelsKnowledge-Based Systems, 2025
- StubCoder : Automated Generation and Repair of Stub Code for Mock ObjectsACM Transactions on Software Engineering and Methodology, 2023
- GitHub Copilot AI pair programmer: Asset or Liability?Journal of Systems and Software, 2023
- Grounded Copilot: How Programmers Interact with Code-Generating ModelsProceedings of the ACM on Programming Languages, 2023
- RepoCoder: Repository-Level Code Completion Through Iterative Retrieval and Generation2023
- Shall We Pretrain Autoregressive Language Models with Retrieval? A Comprehensive Study2023
- When Not to Trust Language Models: Investigating Effectiveness of Parametric and Non-Parametric Memories2023
- A Static Evaluation of Code Completion by Large Language Models2023
- Impact of Pretraining Term Frequencies on Few-Shot Numerical Reasoning2022
- An Empirical Study of API Stability and Adoption in the Android Ecosystem2013