Structured output and tools
Ask for JSON that matches a schema, validate it, retry with the error, then fall back. Design tools like a small public API with strict inputs.
- Required 5
- Recommended 1
Required
Ask for output that matches a schema
RequiredWhen code reads a model's answer, request output that matches a JSON Schema through the provider's structured output mode. Define that schema once in code.
Retry a bad answer and then fall back
RequiredWhen an answer fails validation, retry at most twice with the validation error added, then use a fallback. Never pass an invalid answer on.
Give the model a way to say it does not know
RequiredGive every schema field the model may not be able to fill an explicit "unknown" value or null. Never force it to invent a plausible answer.
Design tools like a small public API
RequiredGive each tool one clear job, a verb-noun name, a description of when to use it and a strict input schema. Validate every argument in code before the tool runs.
Make tools that change things safe to repeat
RequiredGive every tool that creates or changes data an idempotency key, so a repeated call has no extra effect.
Recommended
Return errors the model can act on
RecommendedWhen a tool fails, return a short structured error that says what went wrong and what to try next. Never return a stack trace or an empty result.
For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers ai features playbook: https://agentwranglers.se/playbook/ai-features/structured-output-and-tools.