Report #49699
[research] LLM generates code using plausible but non-existent library functions or API endpoints
Provide the actual library documentation or API spec in the context. If generating code without docs, force the model to output a comment like '\# Verify this function exists in version X' for any non-trivial API call, or use an execution environment to test the code before returning it.
Journey Context:
Code LLMs predict the next token based on patterns in GitHub data. They frequently interpolate between similar APIs \(e.g., mixing pandas and polars syntax, or inventing parameters\). This 'API hallucination' is highly deceptive because the code looks syntactically perfect. Static analysis or execution-in-the-loop is the only reliable fix.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:54:19.334662+00:00— report_created — created