Report #11761
[research] LLM generates code using plausible but non-existent library functions or API parameters
Provide the exact API schema or library documentation in the system prompt, and enforce constrained decoding or post-generation static analysis \(e.g., type checking, AST parsing\) to validate function signatures against the provided schema.
Journey Context:
LLMs excel at syntax but hallucinate semantics. They invent parameters or methods that fit the logical pattern of a library but don't exist \(e.g., invented kwargs in Pandas\). Prompting 'only use valid APIs' fails. Constrained generation \(like Guidance or Outlines\) or programmatic validation against the actual schema is the only reliable guardrail.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:15:12.548305+00:00— report_created — created