Mitigating Errors in LLM-Generated Web API Invocations via Retrieval-Augmented Generation and Constrained Decoding
Technische Universität Darmstadt(德累斯顿技术大学);Hessian Center for Artificial Intelligence (hessian.AI)(黑森人工智能中心);Pariton AI;National Research Center for Applied Cybersecurity ATHENE(应用网络安全国家研究中心ATHENE)
Daniel Maninger, Leon Chemnitz, Jannis Brugger, Tushar Lamba, Amir Molzam Sharifloo, Mira Mezini
备注:
54 pages, 11 figures; supersedes arXiv:2509.20172v6, which is a discarded journal extension of our work
Web API集成是现代软件系统的基石,但由于API规范复杂且不断演变,编写正确的Web API调用代码仍然具有挑战性。尽管大语言模型越来越多地用于代码生成,但先前的工作已通过实证表明,它们生成正确的Web API集成的能力有限。同时,缓解技术及其在这种情况下的有效性仍未得到充分理解。在本文中,我们提出并系统地评估了检索增强生成(RAG)和约束解码(CD)作为两种互补的方法,以改进大语言模型生成的Web API调用代码。对于RAG,我们设计了一个检索器,该检索器处理OpenAPI规范并检索紧凑的端点表示,以注入到模型提示中。对于CD,我们引入了从OpenAPI规范到基于正则表达式的约束的自动转换,这些约束在生成过程中强制执行。我们在WAPIIBench的现有合成数据集和从GitHub存储库派生的新真实世界数据集上评估了这两种方法。我们的结果表明,RAG在生成完整的API调用时减少了幻觉并提高了正确性,但在已经提供端点时会降低正确性,因为它鼓励生成不必要的参数。相比之下,CD可靠地防止了非法URL、HTTP方法和参数,并显著提高了两种起始代码的整体正确性。
英文摘要:
Integration of web APIs is a cornerstone of modern software systems, yet writing correct web API invocation code remains challenging due to complex and evolving API specifications. Although LLMs are increasingly used for code generation, previous work has empirically shown that their ability to generate correct web API integrations is limited. At the same time, mitigation techniques and their effectiveness for this setting remain insufficiently understood.
In this paper, we propose and systematically evaluate retrieval-augmented generation (RAG) and constrained decoding (CD) as two complementary approaches to improving LLM-generated web API invocation code. For RAG, we design a retriever that processes OpenAPI specifications and retrieves compact endpoint representations to inject into model prompts. For CD, we introduce an automatic translation from OpenAPI specifications to regex-based constraints enforced during generation.
We evaluate both approaches on WAPIIBench's existing synthetic dataset and on a new real-world dataset derived from GitHub repositories. Our results show that RAG reduces hallucinations and improves correctness when generating full API invocations but reduces it when the endpoint is already provided as it encourages the generation of unnecessary parameters. In contrast, CD reliably prevents illegal URLs, HTTP methods, and arguments and substantially improves overall correctness for both starter codes.
Q-ARE: An Evaluation Dataset for Query Based API Recommendation
College of Computer Science and Technology, National University of Defense Technology(国防科技大学计算机学院);State Key Laboratory of Complex & Critical Software Environment(复杂与关键软件环境国家重点实验室)
Web API(WAPI)是一种API,其与消费者的交互是通过互联网完成的。虽然通过互联网访问可能具有挑战性,但主要是在WAPI发展时,它使提供商有可能监控其使用情况,并了解和分析消费者的行为。目前,WAPI的使用情况主要用于流量监控和故障排除。即使它们包含有关消费者行为的宝贵信息,但供应商没有充分利用它们。在本文中,我们首先考虑应用程序开发生命周期的两个阶段,并在此基础上区分两种不同类型的使用日志,即开发日志和生产日志。对于其中的每一个,我们显示了潜在的分析(例如,WAPI可用性评估,消费者需求识别),以及可能由不合适的日志格式造成的主要障碍。然后,我们进行了一个案例研究,使用来自不同部署和不同格式的相同WAPI的日志,以证明这些障碍的发生,同时正确的日志格式的重要性。接下来,基于案例研究结果,我们提出了WAPI日志数据的主要质量问题,并解释了它们对数据分析的影响。对于每一个问题,我们都给出了一些关于如何处理它们的实际建议,以及减轻其根源的建议。
CodeArena: A Collective Evaluation Platform for LLM Code Generation
Nanyang Technological University(南洋理工大学);National University of Singapore(新加坡国立大学);The University of Hong Kong(香港大学);Monash University(莫纳什大学);TikTok(抖音)
Understanding and Mitigating Library-Related Issues in LLM-Generated Code
IReSCoMath Research Laboratory, Faculty of Sciences, University of Gabes(加贝斯大学理学院 IReSCoMath 研究实验室);National School of Engineering, Gabes(加贝斯国立工程学院);Department of Electrical & Software Engineering, University of Calgary(卡尔加里大学电气与软件工程系)
AutoGEEval: A Multimodal and Automated Framework for Geospatial Code Generation on GEE with Large Language Models
Wuhan University(武汉大学);State Key Laboratory of Information Engineering in Surveying, Mapping and Remote Sensing, Wuhan University(武汉大学测绘遥感信息工程国家重点实验室);Collaborative Innovation Center of Geospatial Technology, Wuhan University(武汉大学地理空间技术协同创新中心);School of Resource and Environmental Sciences, Wuhan University(武汉大学资源与环境科学学院);School of Remote Sensing and Information Engineering, Wuhan University(武汉大学遥感信息工程学院)