The model hit the token limit halfway through a JSON object.
Your parser throws on every long list.
- ARepair the truncated JSON with a regex that closes the brackets
- BSwitch the format to YAML, which tolerates truncation better
- 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
- 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.
- Structured outputYour classifier uses DeepSeek’s JSON mode.
- Structured outputYou need reliable JSON from the model to feed a downstream service.
- Structured outputAbout 2% of responses come back as JSON with a trailing comma or a stray note before the object, and your pipeline crashes on them.
- Structured outputYou need three fields from the model.
More on Way of the Agent
- Course programThe first three modules are free: start in the browser or the app, no card needed.
- Library: guides, skills and promptsReady prompt templates, grouped into collections.
- AI ChroniclesSourced stories from the history of AI.
- ConceptsPlain-language explainers of agent engineering.
- Learn AI agentsApps and courses for learning AI agents, compared honestly.
Real situations from building agents - with the answer and why.
Solve a new one every day on the Path