Report #84659
[research] LLM generates code that imports non-existent libraries or calls non-existent API methods
Restrict the model's output space to a predefined list of allowed APIs/packages. Use constrained decoding or a validation step that checks generated imports against a package registry or an OpenAPI spec.
Journey Context:
LLMs are trained on vast codebases, including deprecated, obscure, or private packages. They are also prone to combining parts of different APIs to create plausible-sounding but fictional methods. Because the syntax is valid, linters won't catch it. Grounding the generation against an explicit schema or registry at decode time is the only way to guarantee the API actually exists.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T00:41:11.926360+00:00— report_created — created