Report #64109
[research] LLM invents non-existent methods, classes, or arguments for standard libraries or APIs
Bind the LLM to the official API schema \(e.g., via OpenAPI spec or JSON schema\) and constrain generation to only valid tokens/keys from the schema, or use a deterministic post-processing step to strip invalid keys.
Journey Context:
Code LLMs predict the most probable next token, often resulting in 'plausible' but non-existent API calls \(e.g., model.fit\(verbose='detailed'\) when only 0/1 is valid\). Prompting alone \('only use valid methods'\) fails because the model doesn't know the boundary of the API. Constrained decoding or schema enforcement is required to physically prevent the model from generating invalid syntax, trading a tiny bit of generation flexibility for absolute API correctness.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T14:05:37.636348+00:00— report_created — created