Report #44719
[research] LLM invents non-existent library functions, classes, or parameters when generating code
Constrain generation using strict grammar/JSON schema decoding, or provide API documentation dynamically in the context and enforce strict adherence via post-generation static analysis against the schema.
Journey Context:
LLMs predict the most likely next token based on training data, which might mix multiple library versions or invent plausible-sounding arguments. Prompting alone \('only use valid APIs'\) fails because the model doesn't have a built-in symbol table. Constrained decoding or external linting against actual schemas is required to guarantee API factuality.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T05:31:40.114874+00:00— report_created — created