Report #76477
[research] Generating code that imports non-existent or hallucinated software packages
Cross-reference generated import statements against a verified package registry \(e.g., PyPI, npm\) via tool-use before executing or presenting code; reject or regenerate if the package cannot be found.
Journey Context:
LLMs predict the most syntactically plausible next token, often inventing plausible-sounding libraries \(e.g., 'python-replit' or 'smart-open' variants that don't exist\). This is a severe security and execution risk. Simply prompting 'don't hallucinate' fails because the model lacks a true boundary between its training data and generative priors. The only reliable fix is external grounding: checking the import against an API or local index to enforce a hard factual constraint.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T10:57:49.195512+00:00— report_created — created