claude-code - 💡(How to fix) Fix tool_use produces thousands of malformed items instead of valid output when schema complexity + prompt size exceeds threshold [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#55537Fetched 2026-05-03 04:50:50
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
0
Author
Timeline (top)
commented ×1labeled ×1

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.

Error Message

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.

Root Cause

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.

Fix Action

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.

RAW_BUFFERClick to expand / collapse

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 changeResult
Added 127-value enum on a string field4,329 malformed objects, key fields undefined
Added maxLength on text fields + description on another field4,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

extent analysis

TL;DR

To mitigate the issue, simplify the schema by removing large enums, maxLength constraints, and description fields, and instead enforce these constraints in the prompt text or post-processing code.

Guidance

  • Identify and simplify complex schemas that may be contributing to the degenerate output mode, focusing on removing large enums and constraints.
  • Enforce constraints such as character limits and allowed value lists in the prompt text or post-processing code to maintain data integrity.
  • Monitor the combined complexity of the schema and prompt, aiming to stay below the observed threshold of around 14-15K characters.
  • Consider reviewing related issues (#22394, #5504, #24599) for additional insights or potential fixes.

Example

No code snippet is provided as the issue does not explicitly mention specific code changes.

Notes

The provided workaround suggests that simplifying the schema and moving constraints to the prompt text or post-processing code can help mitigate the issue, but may not be a permanent solution.

Recommendation

Apply the workaround by simplifying schemas and enforcing constraints in the prompt or post-processing code, as this approach has been confirmed to resolve the issue in production.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

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.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix tool_use produces thousands of malformed items instead of valid output when schema complexity + prompt size exceeds threshold [1 comments, 2 participants]