Report #4008
[research] LLM importing non-existent libraries or using fabricated package names in generated code
Constrain code generation to a predefined list of allowed packages/imports. If generating Python, require the agent to execute a pip search or pip install --dry-run via a tool to verify the package exists before writing the import statement.
Journey Context:
LLMs frequently hallucinate plausible-sounding package names \(e.g., python-clipboard instead of pyperclip\) because they optimize for syntactic coherence. This leads to ModuleNotFoundError at runtime. Static analysis or sandboxed execution is required because the model's parametric memory cannot reliably distinguish between real and plausible package names.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:39:25.830291+00:00— report_created — created