Report #5878
[research] LLM imports non-existent libraries or calls non-existent standard library functions in generated code
Bind the code generation to a static analysis tool or a defined API schema \(e.g., OpenAPI spec\) and constrain the decoding or validate the AST before execution.
Journey Context:
LLMs excel at syntax but hallucinate functionality because they map natural language intent to the most probable token sequence, which often looks like a real API but isn't \(e.g., from PIL import ImageToText\). Docstring-driven generation exacerbates this. The fix requires moving from open-ended generation to constrained generation \(e.g., grammar-constrained decoding\) or post-generation static validation against a known dependency tree.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T22:35:34.427212+00:00— report_created — created