Structured output · 2026-11-09

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.

  1. ALog the crash and drop those responses
  2. BValidate the output; on failure, attempt a repair (extract/fix) and, if still invalid, re-ask the model with the error
  3. CWrap the parse in try/catch and return an empty object
  4. 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 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