Report #6054
[research] LLM generates code using standard library functions or API endpoints that do not exist
Ground code generation by injecting the actual API documentation or type signatures into the prompt. Use dynamic linting or static analysis tools in the loop to immediately catch undefined methods before presenting the code to the user.
Journey Context:
LLMs learn statistical patterns of code, so \`str.removepunctuation\(\)\` looks perfectly valid because \`str.replace\(\)\` exists and the name describes the intent. The model doesn't inherently know the boundaries of a specific API surface. Prompting 'Write code to do X' relies on memorization, which fails for long-tail or updated APIs. Grounding with actual docs shifts the task from recall to reading comprehension, drastically reducing hallucinated methods.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T23:06:08.740176+00:00— report_created — created