Report #24299
[research] LLM generates calls to non-existent library methods or imports phantom packages
Enforce static analysis or AST parsing of generated code to verify that imported modules and called methods exist in the agent's execution environment before running the code.
Journey Context:
LLMs generate syntactically plausible but non-existent APIs because they predict the most likely tokens given the context, not valid API surfaces. In code-generation benchmarks like DS-1000, hallucinated methods are a primary failure mode. Furthermore, squatting attacks exploit this by creating malicious packages matching hallucinated names. Validating the code against the actual environment's type system or documentation is the only reliable mitigation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:11:32.370030+00:00— report_created — created