Report #8531
[research] LLM hallucinates non-existent methods, classes, or API parameters when generating code, creating syntactically plausible but invalid code
Provide the exact API schema or library documentation in the context, and constrain decoding \(e.g., via grammar-constrained generation or structured outputs\) to only use valid identifiers from the schema.
Journey Context:
Code LLMs predict the most likely token based on syntax and common patterns, not the specific library version. Without schema grounding, they will confidently invent plausible-sounding methods. Constrained decoding forces the model to align its high-probability syntax generation with the actual API surface.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:44:52.461156+00:00— report_created — created