mlsanityData to 7 Oct 2026

Mitigating Errors in LLM-Generated Web API Invocations via Retrieval-Augmented Generation and Constrained Decoding

arXiv 2607.05936 ↗First posted 7 Jul 2026cs.SE cs.LGcited by 0

On the map: Retrieval-augmented generation → RAG for code

Abstract (arXiv)

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.

Key facts. No citing papers in the map yet (data through 7 Oct 2026). Placed in RAG for code, one of 15 directions in Retrieval-augmented generation. Builds on 16 of its 59 references that are in the map. First posted on arXiv 7 Jul 2026.

Builds on

16 of 59 references.

References · 16

  1. 2024The Llama 3 Herd of Modelscited by 14,192
  2. 2023Code Llama: Open Foundation Models for Codecited by 2,105
  3. 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,154
  4. 2024Qwen2.5-Coder Technical Reportcited by 1,151
  5. 2024StarCoder 2 and The Stack v2: The Next Generationcited by 484
  6. 2023Efficient Guided Generation for Large Language Modelscited by 192
  7. 2025Survey on Evaluation of LLM-based Agentscited by 190
  8. 2023RestGPT: Connecting Large Language Models with Real-World RESTful APIscited by 129
  9. 2024What's Wrong with Your Code Generated by Large Language Models? An Extensive Studycited by 52
  10. 2025RAG-MCP: Mitigating Prompt Bloat in LLM Tool Selection via Retrieval-Augmented Generationcited by 26
  11. 2024De-Hallucinator: Mitigating LLM Hallucinations in Code Generation Tasks via Iterative Groundingcited by 14
  12. 2023Don't Fine-Tune, Decode: Syntax Error-Free Tool Use via Constrained Decodingcited by 13
4 more
  1. 2024Applying RLAIF for Code Generation with API-usage in Lightweight LLMscited by 10
  2. 2022Dialog2API: Task-Oriented Dialogue with API Description and Example Programscited by 9
  3. 2021Compositional Generalization for Natural Language Interfaces to Web APIscited by 7
  4. 2023Pop Quiz! Do Pre-trained Code Models Possess Knowledge of Correct API Names?cited by 3

Built on by

Not cited yet.

Similar, not cited

Close in wording, no citation either way

  1. 2026OOPS: Automated generation of REST API specification via LLMs ↗
  2. 2025When LLMs Meet API Documentation: Can Retrieval Augmentation Aid Code Generation Just as It Helps Developers?
  3. 2026APITestGenie: Generating Web API Tests from Requirements and API Specifications with LLMs ↗
  4. 2025Evaluating LLMs on Sequential API Call Through Automated Test Generation
  5. 2024A Comprehensive Framework for Evaluating API-oriented Code Generation in Large Language Models
  6. 2025Towards Mitigating API Hallucination in Code Generated by LLMs with Hierarchical Dependency Aware
  7. 2025What to Retrieve for Effective Retrieval-Augmented Code Generation? An Empirical Study and Beyond
  8. 2026When LLMs Lag Behind: Knowledge Conflicts from Evolving APIs in Code Generation