Structured output · 2026-10-05

The model hit the token limit halfway through a JSON object.

Your parser throws on every long list.

  1. ARepair the truncated JSON with a regex that closes the brackets
  2. BSwitch the format to YAML, which tolerates truncation better
  3. CRetry the same request with a note asking the model to keep the list shorter this time, and keep retrying until one attempt comes back small enough to parse cleanly
  4. DDetect the length stop reason and either raise the budget or ask for a smaller unit - a cut-off object is not a parse problem

Answer: D

Detect the length stop reason and either raise the budget or ask for a smaller unit - a cut-off object is not a parse problem

Why

The response is not malformed, it is incomplete - and the API told you so in the stop reason. Bracket repair produces a valid object that is quietly missing data, which is the worse of the two failures: a crash you can see beats a half-answer you cannot.

More on this topic

More on Way of the Agent

Real situations from building agents - with the answer and why.

Solve a new one every day on the Path