About 2% of responses come back as JSON with a trailing comma or a stray note before the object, and your…
About 2% of responses come back as JSON with a trailing comma or a stray note before the object, and your pipeline crashes on them.
- ALog the crash and drop those responses
- BValidate the output; on failure, attempt a repair (extract/fix) and, if still invalid, re-ask the model with the error
- CWrap the parse in try/catch and return an empty object
- DRetry the exact same call, unchanged, until it parses - at 2% failure the second attempt almost always succeeds, so no repair logic is needed
Answer: B
Validate the output; on failure, attempt a repair (extract/fix) and, if still invalid, re-ask the model with the error
Why
Real systems assume some malformed output and build a validate→repair→re-ask ladder. Dropping data loses work, empty objects hide bugs, and blind retries waste calls without addressing why it failed.
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