Report #15256
[research] Code generation agent fabricates standard library methods, classes, or parameters that do not exist in the target framework
Inject the actual API documentation or type signatures into the prompt context \(grounded generation\) and constrain the output grammar using a schema or LSP \(Language Server Protocol\) validation step before presenting the code to the user.
Journey Context:
LLMs trained on code learn the statistical distribution of syntax but lack a formal symbol table. They invent highly plausible methods \(e.g., str.normalize\('NFC'\) in a language that doesn't support it\). Linting catches syntax errors but not hallucinated API calls. The only reliable fix is grounding the model in the actual AST/API spec and validating the output against it. The tradeoff is the cost of retrieving and injecting API docs vs. the cost of a broken build.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T23:40:54.654412+00:00— report_created — created