All guides

Structured outputs for multi-agent systems

Keep agents aligned with JSON schema validation and repair loops.

Intermediate15 min readAug 6, 2024
FunctionsResponsesAgents
Key takeaways
  • Define schema contracts before you build workflows.
  • Validate every output before tool execution.
  • Use repair prompts to recover from invalid JSON.

Schema first design

Document the output schema before you write the prompt. Make each field required and typed.

Validate and repair

If a response fails schema validation, retry with a repair prompt that only fixes the broken fields.

{
  "summary": "string",
  "risks": [{ "title": "string", "impact": "string" }],
  "next_steps": ["string"]
}

Agent handshake

Use structured outputs to pass data between agents without ambiguity.