Report #92353
[research] LLM generates code using non-existent libraries, classes, or methods that look syntactically correct
Constrain generation using a grammar or schema derived from the actual library documentation \(e.g., JSON schema, TypeScript declarations\), or enforce a static analysis step \(like mypy or tsc\) in the loop to reject hallucinated symbols before execution.
Journey Context:
LLMs predict the next token based on syntax patterns. If a library has a get\_user\(\) method but the agent needs get\_admin\(\), the LLM might confidently generate get\_admin\(\) because it fits the syntactic and semantic context. Prompting 'don't hallucinate' fails because the model doesn't know the boundary of its training data. Hard constraints via type hints or external compiler validation are required to map generated text to the actual API surface.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T13:36:24.425696+00:00— report_created — created