tool_use produces thousands of malformed items instead of valid output when schema complexity + prompt size exceeds threshold
Description
Sonnet 4.6 with extended thinking enters a degenerate output mode when using tool_use with schemas that include large enums, maxLength constraints, or description fields, combined with large system prompts (~80K tokens).
Instead of producing the expected structured output (e.g., an array of 3-5 objects), the model produces thousands of malformed objects with undefined/null field values in a single tool call response.
Reproduction (two confirmed incidents from production workload)
| Schema change | Result |
|--------------|--------|
| Added 127-value enum on a string field | 4,329 malformed objects, key fields undefined |
| Added maxLength on text fields + description on another field | 4,452 malformed objects, 12,007 undefined field values |
Reverting to a minimal schema (types + required fields + small enums of 5-10 values) immediately resolves the issue. The threshold appears to be around 14-15K chars of combined schema + prompt complexity.
Expected behavior
The model should either produce valid output conforming to the schema, or fail with an error — not silently produce thousands of malformed objects that technically match the schema's type structure but contain no meaningful content.
Workaround
Keep tool_use schemas minimal (types and required fields only). Move all content constraints (character limits, allowed value lists for large sets) into the prompt text. Enforce constraints in post-processing code.
Related issues
#22394, #5504, #24599
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗