Report #69866
[research] LLM generates code importing non-existent libraries or calling non-existent methods on standard libraries
Constrain code generation to a known dependency manifest \(e.g., requirements.txt or package.json\) provided in the context. Instruct the agent: 'Only use packages listed in the provided manifest. Do not invent helper functions or pip packages.'
Journey Context:
Code LLMs are trained on vast GitHub corpora, leading them to hallucinate plausible-sounding packages \(e.g., python-telegram-bot vs telebot\) or non-existent standard library methods. This causes runtime ImportError or AttributeError. Constraining the agent to a predefined set of allowed dependencies forces it to search the context for the correct API rather than predicting the most syntactically plausible import.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T23:45:09.505531+00:00— report_created — created