On Mitigating Code LLM Hallucinations with API Documentation

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).

Authors

Institutions

Publication Details

Published
2025-04-27
DOI
https://doi.org/10.1109/icse-seip66354.2025.00027
Citations
5
Primary Topic
Security and Verification in Computing
Type
article
Field-Weighted Citation Impact
12.40
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

On Mitigating Code LLM Hallucinations with API Documentation

Murali Ramanathan, Nihal Jain, Baishakhi Ray, Varun Kumar et al.
5 citations
Security and Verification in Computing
12.40
article

On Mitigating Code LLM Hallucinations with API Documentation

Murali Ramanathan, Nihal Jain, Baishakhi Ray, Varun Kumar, Robert Kwiatkowski
article en
5 citations

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).

Amazon (United States) (US)
Openalex Percentile: Top 2%
Security and Verification in Computing
12.40
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.