Report #53159
[research] LLM generates code importing non-existent packages or calling non-existent methods in real packages
Constrain generation using a grammar or schema derived from actual package documentation, or run a static analysis/linter step against the target environment's installed packages to catch ImportError or AttributeError before presenting the code to the user.
Journey Context:
Code LLMs predict the next token based on syntax probability. They invent plausible-sounding APIs \(e.g., pandas.read\_excel\_to\_df\(\)\) that fit the syntax but don't exist. Documentation RAG helps, but models still extrapolate. Only execution, static type checking, or constrained decoding can definitively prove API existence against a known symbol table.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T19:43:26.513971+00:00— report_created — created