paperbot · PL 论文追踪

全部论文 待读 收藏

P1 Towards Mitigating API Hallucination in Code Generated by LLMs with Hierarchical Dependency Aware

面向层次化依赖感知的LLM生成代码中API幻觉缓解
FSE Proceedings of the 33rd ACM International Conference on the Foundations of Software Engineering2025匹配度 5/10 · 论文关注用层次依赖分析与约束解码缓解LLM代码生成中的API幻觉,属于程序分析与LLM代码生成的交叉,和用户PL→AI/AI→PL的大方向相关;但它既不针对ML系统或Agentic程序的静态分析,也不是用LLM改进静态分析/形式化验证,因此不落在核心研究问题上。引用 2 inbox
Yujia Chen, Mingyu Chen, Cuiyun Gao, Zhihan Jiang, Zhongqi Li, Yuchi Ma
crossref: 2026-09-12

AI 速览

一句话:提出MARIN,通过层次依赖挖掘与依赖约束解码缓解LLM代码生成中的API幻觉。

大型语言模型在自动代码生成中常出现API幻觉,即调用不存在的API或错误使用现有API。现有检索增强生成方法往往忽略实际项目中的结构依赖,且未真正验证生成的API是否可用。本文提出MARIN框架,包含两个阶段:层次依赖挖掘分析当前函数的局部与全局依赖,为LLM输入补充完整的项目上下文;依赖约束解码利用挖掘出的依赖自适应约束生成过程,确保生成的API符合项目规范。为评估API幻觉程度,作者构建了APIHul-Bench基准,并提出微幻觉数量MiHN与宏幻觉率MaHR两个新指标。在六个先进LLM上的实验表明,MARIN相比RAG平均降低MiHN 67.52%、MaHR 73.56%;应用于华为内部项目及两个专有LLM时,平均降低MiHN 57.33%、MaHR 59.41%。

问题
LLM在代码生成中容易产生API幻觉,包括调用不存在的API或误用现有API,而现有RAG方法忽略项目结构依赖且未验证API可用性。
方法
MARIN通过层次依赖挖掘分析函数的局部与全局依赖以补充项目上下文,并利用依赖约束解码自适应约束生成过程,使生成的API符合项目规范。
评估
构建APIHul-Bench基准与MiHN、MaHR两个指标,在六个先进LLM以及华为内部项目和两个专有LLM上验证API幻觉降低效果。
原文摘要(Abstract)

Application Programming Interfaces (APIs) are crucial in modern software development. Large Language Models (LLMs) assist in automated code generation but often struggle with API hallucination, including invoking non-existent APIs and misusing existing ones in practical development scenarios. Existing studies resort to Retrieval-Augmented Generation (RAG) methods for mitigating the hallucination issue, but tend to fail since they generally ignore the structural dependencies in practical projects and do not indeed validate whether the generated APIs are available or not. To address these limitations, we propose MARIN, a framework for mitigating API hallucination in code generated by LLMs with hierarchical dependency aware. MARIN consists of two phases: Hierarchical Dependency Mining, which analyzes local and global dependencies of the current function, aiming to supplement comprehensive project context in LLMs' input, and Dependency Constrained Decoding, which utilizes mined dependencies to adaptively constrain the generation process, aiming to ensure the generated APIs align with the project's specifications. To facilitate the evaluation of the degree of API hallucination, we introduce a new benchmark APIHul-Bench and two new metrics including Micro Hallucination Number (MiHN) and Macro Hallucination Rate (MaHR). Experiments on six state-of-the-art LLMs demonstrate that MARIN effectively reduces API hallucinations, achieving an average decrease of 67.52% in MiHN and 73.56% in MaHR compared to the RAG approach. Applied to Huawei's internal projects and two proprietary LLMs, MARIN achieves average decreases of 57.33% in MiHN and 59.41% in MaHR.

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@inproceedings{paperbot9009,
  title = {Towards Mitigating API Hallucination in Code Generated by LLMs with Hierarchical Dependency Aware},
  author = {Yujia Chen and Mingyu Chen and Cuiyun Gao and Zhihan Jiang and Zhongqi Li and Yuchi Ma},
  booktitle = {FSE},
  year = {2025},
  doi = {10.1145/3696630.3728569}
}