Report #49312
[research] Model generates calls to non-existent library functions or hallucinates package names
Inject the actual library documentation or API spec into the system prompt, and constrain generation using a grammar or JSON schema that only allows known API endpoints from the spec.
Journey Context:
Code LLMs predict the next token based on syntax likelihood, not compilation status. They will seamlessly invent utils.parse\_json\(\) if it looks syntactically plausible. Relying on the model's parametric memory for API signatures is a primary failure mode. Grounding via RAG helps, but unconstrained generation can still hallucinate outside the docs. Constrained decoding forces the model to select only from valid identifiers provided in the injected spec.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:15:19.033857+00:00— report_created — created