claude-code - 💡(How to fix) Fix output_config.format returns 400 'compiled grammar is too large' with no documented limits [1 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#55539Fetched 2026-05-03 04:50:47
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1labeled ×1

When using output_config.format with a JSON schema that has more than approximately 24 optional parameters, the API returns:

400: "compiled grammar is too large"

This limit was discovered empirically through trial and error. There is no documentation on:

  • What the compiled grammar size limit is
  • How schema features (optional fields, enums, nested objects, arrays with maxItems) contribute to grammar size
  • How to estimate whether a given schema will compile successfully before sending a request

Error Message

This limit was discovered empirically through trial and error. There is no documentation on: Documentation should specify grammar size limits and how schema features contribute to compiled size. Ideally, the error message should indicate which part of the schema is causing the limit to be exceeded, or provide an estimated vs. maximum grammar size.

Root Cause

When using output_config.format with a JSON schema that has more than approximately 24 optional parameters, the API returns:

400: "compiled grammar is too large"

This limit was discovered empirically through trial and error. There is no documentation on:

  • What the compiled grammar size limit is
  • How schema features (optional fields, enums, nested objects, arrays with maxItems) contribute to grammar size
  • How to estimate whether a given schema will compile successfully before sending a request

Fix Action

Workaround

Make all fields required (eliminates the optional-field state space doubling). Strip description fields from schemas before passing to the API. Avoid large enums and maxItems. Flatten nested objects. If the schema still exceeds the limit, fall back to unconstrained text generation with manual JSON parsing.

Code Example

400: "compiled grammar is too large"
RAW_BUFFERClick to expand / collapse

Description

When using output_config.format with a JSON schema that has more than approximately 24 optional parameters, the API returns:

400: "compiled grammar is too large"

This limit was discovered empirically through trial and error. There is no documentation on:

  • What the compiled grammar size limit is
  • How schema features (optional fields, enums, nested objects, arrays with maxItems) contribute to grammar size
  • How to estimate whether a given schema will compile successfully before sending a request

Schema features that increase grammar size (discovered empirically)

  • Optional fields (each roughly doubles the FSM state space)
  • Large enums (100+ values)
  • maxItems on arrays (grammar must track count)
  • Deeply nested objects
  • description fields (unclear if they affect compilation, but they increase raw schema size)

Expected behavior

Documentation should specify grammar size limits and how schema features contribute to compiled size. Ideally, the error message should indicate which part of the schema is causing the limit to be exceeded, or provide an estimated vs. maximum grammar size.

Workaround

Make all fields required (eliminates the optional-field state space doubling). Strip description fields from schemas before passing to the API. Avoid large enums and maxItems. Flatten nested objects. If the schema still exceeds the limit, fall back to unconstrained text generation with manual JSON parsing.

extent analysis

TL;DR

To mitigate the "compiled grammar is too large" error, simplify the JSON schema by reducing optional parameters, avoiding large enums, and flattening nested objects.

Guidance

  • Review the schema for optional fields and consider making them required to reduce the FSM state space.
  • Limit the use of large enums (over 100 values) and maxItems on arrays, as these contribute to increased grammar size.
  • Remove description fields from the schema before passing it to the API, as they may increase raw schema size.
  • Consider flattening deeply nested objects to reduce grammar size.

Example

No code snippet is provided as the issue does not contain specific code examples.

Notes

The exact grammar size limit and how schema features contribute to it are not documented, making it challenging to estimate whether a given schema will compile successfully. The provided workaround may not be suitable for all use cases, especially those requiring optional fields or large enums.

Recommendation

Apply the workaround by simplifying the schema, as there is no clear indication of a fixed version that addresses this issue. This approach can help mitigate the error, but it may require significant changes to the schema design.

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

Documentation should specify grammar size limits and how schema features contribute to compiled size. Ideally, the error message should indicate which part of the schema is causing the limit to be exceeded, or provide an estimated vs. maximum grammar size.

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 output_config.format returns 400 'compiled grammar is too large' with no documented limits [1 participants]