Back to guide
Markdown view
# Structured outputs for multi-agent systems

Keep agents aligned with JSON schema validation and repair loops.

- Date: Aug 6, 2024
- Reading time: 15 min
- Level: Intermediate
- Tags: Functions, Responses, Agents

## 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.

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

## Agent handshake

Use structured outputs to pass data between agents without ambiguity.