Report #56637
[research] LLM invents non-existent methods, classes, or parameters in standard libraries or internal APIs
Provide the exact API signatures or documentation as context in the system prompt or via RAG. Constrain the generation using grammar-constrained decoding or structured outputs, and explicitly instruct the model to only use functions present in the provided context.
Journey Context:
LLMs learn the syntax and style of code APIs but lose precision on exact namespacing, especially for less popular or internal APIs. They confidently generate syntactically valid code that throws AttributeError at runtime. Few-shot prompting with correct API usage is less effective than providing the actual API spec as grounding context, because the model's prior weights often override the few-shot examples.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T01:33:31.794023+00:00— report_created — created