Report #13200
[research] Code generation invents non-existent libraries, classes, or API endpoints that look syntactically valid
Constrain code generation to a predefined schema or API specification \(e.g., via constrained decoding or providing an OpenAPI spec in context\), and mandate web search for any unfamiliar package imports.
Journey Context:
LLMs trained on code learn the statistical patterns of imports and function calls. They will confidently hallucinate 'from utils import smart\_parser' or 'pip install ai-toolkit' because they fit the syntactic distribution of real packages. This causes silent runtime failures or supply-chain attacks if the package is later published. The fix requires grounding: if an import isn't in the standard library or provided context, the agent must search/verify it exists before writing it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T18:10:33.147808+00:00— report_created — created