Structured Output Parsing
Agents pass model output to code, and code needs structure. Structured output means coaxing the model to return data in a strict shape like JSON that a program can parse without guesswork.
The challenge
- A model trained on free text may add prose, code fences, or trailing commas.
- One malformed field can break the parser and stall the whole loop.
- Subtle drift, like a number returned as a string, causes silent downstream bugs.
Techniques
- Provide a schema and a concrete example of the exact shape you want.
- Use constrained decoding or a structured output mode that forces valid syntax.
- Validate the parsed result against the schema and reject or repair failures.
Repair and retry
Even with constraints, occasional outputs are malformed. A robust agent validates, and on failure either asks the model to fix its own output or retries with a sharper instruction. Treating model output as untrusted input, validated before use, prevents one bad response from corrupting the rest of the agent's work.
Key idea
Structured output forces the model into a strict parseable shape, validated before use so a malformed field cannot derail the agent.