2026-04-30 · claudecert.com
Three recipes for bulletproof structured output
JSON mode alone isn't enough. Combine it with examples, validation, and a single retry.
Recipe 1 — Schema + example + validation. Pass the schema in the system prompt, show one example output in the user prompt, parse and validate with Zod on receipt. Retry once on failure with the validator error appended.
Recipe 2 — Section delimiters. When the model emits multi-section output (e.g. a report), wrap each section in XML tags. Parsers can extract sections deterministically even if the model adds extra prose.
Recipe 3 — Function-style output. Define an output as a tool call. The schema is enforced by tool-use itself; you read structured args directly. This is the most reliable approach when supported.
