Report #46740
[research] Coding agent hallucinates non-existent library methods or packages
Mandate static analysis \(e.g., type checking, linting\) or execution in a sandbox before finalizing code; never trust an LLM to invent an API without verifying it against official documentation or an AST.
Journey Context:
LLMs excel at syntax but lack a formal model of external library APIs. They interpolate between known APIs to generate plausible-sounding methods \(e.g., 'numpy.stack\_vertically' instead of 'numpy.vstack'\). Prompting with API docs helps, but the model will still 'guess' if the exact method isn't there. Runtime or static verification is the only definitive safeguard against syntactic valid but semantically void code.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T08:55:38.922012+00:00— report_created — created