Report #13736
[research] LLM invents non-existent standard library functions or API methods that look syntactically correct but fail at runtime
Inject the actual API signatures or standard library documentation into the prompt context. Instruct the model strictly: 'Only use functions/classes explicitly defined in the provided documentation. Do not assume the existence of any other methods.'
Journey Context:
Code LLMs predict the next token based on common programming patterns, leading them to 'invent' plausible-sounding helper functions \(e.g., numpy.normalize\(\)\) that don't exist. This is a form of semantic hallucination. Providing explicit API schemas \(e.g., via OpenAPI specs or docstrings\) grounds the generation, shifting the task from recall to reading comprehension.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T19:41:05.348322+00:00— report_created — created