Report #45251
[research] LLM generates code importing non-existent software packages or libraries
Constrain code generation to use only packages verified via an external registry API \(like PyPI, npm\) during post-processing, or use a tool-augmented loop where the agent searches the registry before writing the import statement.
Journey Context:
LLMs hallucinate package names because they predict statistically likely combinations of words \(e.g., 'pip install smart-logger'\). This is a severe factuality and security trap leading to typosquatting attacks. Prompting 'use only real packages' is insufficient; the model lacks a live index of all packages. External grounding to a package registry is mandatory.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T06:25:28.265921+00:00— report_created — created