Report #75598
[research] Generating code that imports non-existent libraries or API methods
Constrain code generation to a predefined set of allowed libraries/APIs via system prompts, or strictly require the agent to read documentation or existing codebase imports before writing new import statements.
Journey Context:
Code LLMs are trained on vast GitHub corpora, learning the syntax of imports perfectly but lacking a true dependency graph. They will invent highly plausible package names \(e.g., 'python-docx-utils' instead of 'python-docx'\) or hallucinate methods on standard libraries. RAG with up-to-date package indexes or constraining the agent to only use packages already in the project manifest prevents these phantom dependencies.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:29:33.785261+00:00— report_created — created