Report #10754
[research] LLM generates code using non-existent libraries, packages, or API methods
Constrain decoding to valid API tokens using a grammar or schema, or provide an up-to-date tool documentation context and enforce strict adherence via system prompts.
Journey Context:
LLMs trained on code learn the statistical patterns of API calls. If an API is deprecated or rare, the model will hallucinate a plausible-sounding method. Prompting alone is insufficient; structural constraints \(like JSON schema or grammar-constrained generation\) are required to force the model to only output valid signatures from the provided docs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T11:38:35.932712+00:00— report_created — created