[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-detail-83016-en":3,"doc-seo-83016-105":30,"detail-sidebar-cat-0-en-105":91},{"code":4,"msg":5,"data":6},0,"success",{"doc_id":7,"user_id":8,"nickname":9,"user_avatar":10,"doc_module":4,"category_id":11,"category_name":12,"doc_title":13,"doc_description":14,"doc_content":15,"file_id":16,"file_url":17,"file_type":18,"file_size":19,"view_count":20,"is_deleted":4,"is_public":21,"is_downloadable":21,"audit_status":21,"page_count":22,"language":23,"language_code":24,"site_id":25,"html_lang":24,"table_of_contents":26,"faqs":27,"seo_title":13,"seo_description":14,"update_tm":28,"read_time":29},83016,7971461740909,"Levi","https://ap-avatar.wpscdn.com/davatar_155a257f0dc6eb9ab79c44ca47cae57d",8,"Research & Report","Mitigating Errors in LLM-Generated Web API Invocations via Retrieval-Augmented Generation and Constrained Decoding","Web API integration code is hard to generate correctly because API specifications are complex and continuously evolve, and LLM-based code generation still suffers from limited reliability. This paper proposes retrieval-augmented generation (RAG) and constrained decoding (CD) to improve LLM-produced web API invocations. RAG injects compact endpoint representations retrieved from OpenAPI specs, while CD automatically converts OpenAPI into regex-based constraints enforced during generation. Experiments on synthetic and real GitHub-derived datasets assess hallucinations and overall correctness.","arXiv :2607 .05936v 1 [ cs . SE] 7 Jul 2026  \nMitigating Errors in LLM-Generated Web API Invocations via Retrieval-Augmented Generation and Constrained Decoding  \nDANIEL MANINGER, Technische Universität Darmstadt, Germany and Hessian Center for Artificial Intelligence (hessian.AI), Germany  \nLEON CHEMNITZ, Pariton AI, Germany and Technische Universität Darmstadt, Germany  \nJANNIS BRUGGER, Technische Universität Darmstadt, Germany and Hessian Center for Artificial Intelligence (hessian.AI), Germany  \nTUSHAR LAMBA, Technische Universität Darmstadt, Germany  \nAMIR MOLZAM SHARIFLOO, Technische Universität Darmstadt, Germany  \nMIRA MEZINI, Technische Universität Darmstadt, Germany, Hessian Center for Artificial Intelligence (hessian.AI), Germany, and National Research Center for Applied Cybersecurity ATHENE, Germany  \nIntegration 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.  \nIn 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.  \nWe 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](HTTP methods), and arguments and substantially improves overall correctness for both starter codes.  \nCCS Concepts: • Software and its engineering → Automatic programming; • Computing methodologies → Neural networks;  \n• Information systems → RESTful web services.  \nAdditional Key Words and Phrases: artificial intelligence, software engineering, large language models, code generation, web APIs, benchmarks, retrieval-augmented generation, constrained decoding  \nAuthors’ Contact Information: Daniel Maninger, Technische Universität Darmstadt, Darmstadt, Germany and Hessian Center for Artificial Intelligence (hessian.AI), Darmstadt, Germany, [daniel](daniel.maninger@tu-darmstadt.de)[.](daniel.maninger@tu-darmstadt.de)[maninger@tu-darmstadt](daniel.maninger@tu-darmstadt.de)[.](daniel.maninger@tu-darmstadt.de)[de](daniel.maninger@tu-darmstadt.de); Leon Chemnitz, ParitonAI, Berlin, Germany and Technische Universität Darmstadt, Darmstadt, Germany, [leon](leon.chemnitz@pariton.ai)[.](leon.chemnitz@pariton.ai)[chemnitz@pariton](leon.chemnitz@pariton.ai)[.](leon.chemnitz@pariton.ai)[ai](leon.chemnitz@pariton.ai); Jannis Brugger, Technische Universität Darmstadt, Darmstadt, Germany and Hessian Center for Artificial Intelligence (hessian.AI), Darmstadt, Germany, [jannis](jannis.brugger@tu-darmstadt.de)[.](jannis.brugger@tu-darmstadt.de)[brugger@tu-darmstadt](jannis.brugger@tu-darmstadt.de)[.](jannis.brugger@tu-darmstadt.de)[de](jannis.brugger@tu-darmstadt.de); Tushar Lamba, Technische Universität Darmstadt, Darmstadt, Germany, tushar.lamba@stud.tu-darmstadt.de; Amir Molzam Sharifloo, Technische Universität Darmstadt, Darmstadt, Germany, amir.molzam@tu-darmstadt.de; Mira Mezini, Technische Universität Darmstadt, Darmstadt, Germany and Hessian Center for Artificial Intelligence (hessian.AI),","cbCaim7GdDRqefyL","https://ap.wps.com/l/cbCaim7GdDRqefyL","pdf",944739,4,1,54,"English","en",105,"# Introduction\n## Problem: Correct Web API Invocation\n## Proposed Approaches: RAG and Constrained Decoding\n## Evaluation Setup and Datasets\n## Results and Findings","[{\"question\":\"What problem does the paper address in LLM-generated web API code?\",\"answer\":\"It addresses the difficulty of writing correct web API invocation code from evolving and complex API specifications, where LLMs can hallucinate and generate incorrect integrations.\"},{\"question\":\"How does retrieval-augmented generation (RAG) help generate web API invocations?\",\"answer\":\"RAG uses a retriever that processes OpenAPI specifications and injects compact endpoint representations into the model prompt to guide generation.\"},{\"question\":\"How does constrained decoding (CD) reduce illegal or invalid API invocations?\",\"answer\":\"CD translates OpenAPI specifications into regex-based constraints that are enforced during generation, preventing illegal URLs, HTTP methods, and arguments and improving correctness.\"}]",1784184682,136,{"code":4,"msg":31,"data":32},"ok",{"site_id":25,"language":24,"slug":33,"title":13,"keywords":34,"description":14,"schema_data":35,"social_meta":86,"head_meta":88,"extra_data":90,"updated_unix":28},"mitigating-errors-in-llm-generated-web-api-invocations-via-retrieval-augmented-generation-and-constrained-decoding","",{"@graph":36,"@context":85},[37,53,68],{"@type":38,"itemListElement":39},"BreadcrumbList",[40,44,48,51],{"item":41,"name":42,"@type":43,"position":21},"https://docshare.wps.com","Home","ListItem",{"item":45,"name":46,"@type":43,"position":47},"https://docshare.wps.com/document/","Document",2,{"item":49,"name":12,"@type":43,"position":50},"https://docshare.wps.com/document/research-report/",3,{"item":52,"name":13,"@type":43,"position":20},"https://docshare.wps.com/document/mitigating-errors-in-llm-generated-web-api-invocations-via-retrieval-augmented-generation-and-constrained-decoding/83016/",{"url":52,"name":13,"@type":54,"author":55,"headline":13,"publisher":57,"fileFormat":60,"inLanguage":24,"description":14,"dateModified":61,"datePublished":62,"encodingFormat":60,"isAccessibleForFree":63,"interactionStatistic":64},"DigitalDocument",{"name":9,"@type":56},"Person",{"url":41,"name":58,"@type":59},"DocShare","Organization","application/pdf","2026-07-22","2026-07-16",true,{"@type":65,"interactionType":66,"userInteractionCount":20},"InteractionCounter",{"@type":67},"ViewAction",{"@type":69,"mainEntity":70},"FAQPage",[71,77,81],{"name":72,"@type":73,"acceptedAnswer":74},"What problem does the paper address in LLM-generated web API code?","Question",{"text":75,"@type":76},"It addresses the difficulty of writing correct web API invocation code from evolving and complex API specifications, where LLMs can hallucinate and generate incorrect integrations.","Answer",{"name":78,"@type":73,"acceptedAnswer":79},"How does retrieval-augmented generation (RAG) help generate web API invocations?",{"text":80,"@type":76},"RAG uses a retriever that processes OpenAPI specifications and injects compact endpoint representations into the model prompt to guide generation.",{"name":82,"@type":73,"acceptedAnswer":83},"How does constrained decoding (CD) reduce illegal or invalid API invocations?",{"text":84,"@type":76},"CD translates OpenAPI specifications into regex-based constraints that are enforced during generation, preventing illegal URLs, HTTP methods, and arguments and improving correctness.","https://schema.org",{"og:url":52,"og:type":87,"og:title":13,"og:site_name":58,"og:description":14},"article",{"robots":89,"canonical":52},"index,follow",{"doc_id":7,"site_id":25},{"code":4,"msg":5,"data":92},[93,97,101,105,110,115,120,123,128,131,135],{"id":21,"doc_module":4,"doc_module_name":46,"category_name":94,"show_sort_weight":95,"slug":96},"Story & Novel",90,"story-novel",{"id":47,"doc_module":4,"doc_module_name":46,"category_name":98,"show_sort_weight":99,"slug":100},"Literature",80,"literature",{"id":20,"doc_module":4,"doc_module_name":46,"category_name":102,"show_sort_weight":103,"slug":104},"Exam",70,"exam",{"id":106,"doc_module":4,"doc_module_name":46,"category_name":107,"show_sort_weight":108,"slug":109},5,"Comic",60,"comic",{"id":111,"doc_module":4,"doc_module_name":46,"category_name":112,"show_sort_weight":113,"slug":114},6,"Technology",50,"technology",{"id":116,"doc_module":4,"doc_module_name":46,"category_name":117,"show_sort_weight":118,"slug":119},7,"Healthcare",40,"healthcare",{"id":11,"doc_module":4,"doc_module_name":46,"category_name":12,"show_sort_weight":121,"slug":122},30,"research-report",{"id":124,"doc_module":4,"doc_module_name":46,"category_name":125,"show_sort_weight":126,"slug":127},9,"Religion & Spirituality",20,"religion-spirituality",{"id":126,"doc_module":4,"doc_module_name":46,"category_name":129,"show_sort_weight":126,"slug":130},"World Cup","world-cup",{"id":132,"doc_module":4,"doc_module_name":46,"category_name":133,"show_sort_weight":132,"slug":134},10,"Lifestyle","lifestyle",{"id":136,"doc_module":4,"doc_module_name":46,"category_name":137,"show_sort_weight":106,"slug":138},19,"General","general"]