Report #20997
[research] LLM hallucinates non-existent standard library functions, methods, or parameters that look syntactically correct but fail at runtime
Ground code generation with static analysis \(e.g., type checking, linting\) or compiler feedback in the loop, and constrain decoding to valid identifiers from the project's AST or documentation where possible.
Journey Context:
LLMs generate code by predicting the most probable next token, leading to 'plausible' but non-existent APIs \(e.g., str.removepunctuation\(\)\). This is especially common in lesser-known libraries or newer SDK versions. Prompting with API docs helps, but the model still drifts. Post-generation compilation/type-checking as an automated feedback loop is the most effective way to catch these syntactic hallucinations before execution.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:39:31.475769+00:00— report_created — created