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 2
- Recommended 4
Required
Design tools like a small public API
AIF-15Give 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
AIF-17Give every tool that creates or changes data an idempotency key, so a repeated call has no extra effect.
Recommended
Ask for output that matches a schema
AIF-12When 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
AIF-13When 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
AIF-14Give 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.
Return errors the model can act on
AIF-16When 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.
Read this with
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/ai-features/structured-output-and-tools">Agent Wranglers AI features playbook</a>. In code you write, add a comment next to it with the same link.