REVIEW
Mitigating Errors in LLM-Generated Web API Invocations via Retrieval-Augmented Generation and Constrained Decoding
Software Engineering · Submitted 7 Jul 2026 · 59 references
Pith's verdict: CD contribution is solid and immediately deployable; RAG+CD appendix tables are duplicated, undermining RQ3 verifiability.
Why Pith says this
Highlight any text to comment on it.
Referee report
The paper
The paper claims
Constrained decoding zeroes hallucinated API calls
The reading
What carries the argument
The key machinery is the automatic constraint translator: a system that takes an OpenAPI specification and produces a set of hierarchical generation rules, each consisting of a regex-encoded start condition, stop condition, and body. The rules are triggered sequentially—first matching the HTTP method, then narrowing the URL space to endpoints supporting that method, then narrowing parameters to those defined for the identified endpoint, and finally constraining parameter values by data type. Capture groups and conditional patterns prevent duplicate parameters; negative lookahead assertions prevent closing a parameter list before all required parameters are present. The constraints are model-
Extended reading notes
Core claim
The paper's central discovery is that OpenAPI specifications can be automatically translated into regex-based decoding constraints that make it structurally impossible for an LLM to generate a web API invocation violating the specification—no hallucinated URLs, methods, or arguments—while simultaneously improving overall correctness across models. This works because the constraints are derived directly from the machine-readable specification rather than learned or approximated, turning a soft knowledge problem (does the model remember the API?) into a hard structural guarantee (can the model generate tokens outside the allowed space?). The paper also discovers that RAG and CD interact non-tr
Load-bearing premise
The evaluation measures correctness by comparing generated request configurations against a single ground-truth configuration per task, which may not capture the full space of valid solutions—particularly for the real-world dataset, where some tasks require no parameters beyond path variables, meaning a model can score correct simply by generating a closing parenthesis.
Editorial extensions
If this is right
- Any externally documented interface with a machine-readable specification—database schemas, protocol buffers, GraphQL schemas—could in principle use the same specification-to-constraint translation to guarantee specification-compliant code generation.
- The finding that RAG causes parameter over-inclusion suggests that retrieval-augmented code generation systems broadly may suffer from a 'completeness bias' where models treat retrieved documentation as a checklist rather than a reference, a problem that constrained decoding can partially mitigate by blocking unnecessary parameters.
- The zero-hallucination guarantee from CD could shift the burden of API correctness verification from post-generation testing to generation-time enforcement, changing how developers interact with LLM-based code assistants for integration tasks.
- The model-specific variability in RAG's effectiveness implies that production deployments of retrieval-augmented code generation need per-model validation, whereas CD can be applied more uniformly.
Reading between the lines
- The constraint approach could be extended beyond Axios/JavaScript to other HTTP client libraries and languages, since the OpenAPI specification is language-agnostic—only the syntax-level regexes would need adaptation.
- The observation that CD slightly increases non-executable code rates suggests a tension between structural constraint and generation fluency; investigating whether more permissive constraint formulations (e.g., allowing multiple valid syntax patterns) could reduce this penalty would be a natural next step.
- If OpenAPI specifications could be automatically version-detected from task descriptions, the requirement for users to manually specify the API could be removed, enabling fully automated specification-to-constraint pipelines in IDE-integrated code assistants.
- The finding that smaller constrained models can match or exceed larger unconstrained models (e.g., Code Llama 70B with CD outperforming GPT-4o without CD on argument completion) suggests that constraint enforcement may be a more cost-effective path to correctness than scaling model size.
Original abstract
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.
Figures
Figures reproduced from arXiv:2607.05936 by the authors.
References
Discussion
Disagree with the review, or know something it missed? Leave a comment, highlight any passage above to comment on it, or challenge this review formally.