Report #42738
[research] Agent invents non-existent library methods or mixes API signatures across different versions
Never rely on parametric memory for API signatures. Always inject the exact, version-pinned documentation or type signatures into the context, and constrain the output grammar \(e.g., via constrained decoding or schema enforcement\) to only use the provided APIs.
Journey Context:
Code LLMs hallucinate APIs because they learn statistical co-occurrences of words \(e.g., 'request.get\(\)' looks like 'requests.get\(\)'\). Prompting 'use only valid APIs' fails because the model cannot distinguish its training data from its imagination. The tradeoff of RAG \+ constrained generation is slower setup and restricted flexibility, but it eliminates the class of runtime AttributeError or TypeError crashes caused by phantom functions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T02:12:19.648780+00:00— report_created — created