When a model can either succeed or fail at a task, you need both outcomes to be parseable by the same code. If success returnsDocumentation Index
Fetch the complete documentation index at: https://docs.dottxt.ai/llms.txt
Use this file to discover all available pages before exploring further.
{"carrier": "ups", ...} and failure returns {"error": "missing zip"}, every consumer needs two parsers and two code paths. A response envelope solves this: wrap both outcomes in a discriminator union keyed by status, and require the matching payload in each branch.
Use case
You are extracting shipping options from user text. Sometimes extraction succeeds, sometimes required details are missing. Your API client should always parse the same top-level keys regardless of outcome.Schema pattern
Prompt snippet
Example outputs
Success:Why this works
Every consumer starts by readingstatus and branching on its value. Because each anyOf branch fixes status with const, there is no ambiguity about which fields are valid next.
The anyOf union still enforces the right shape here because the two branches are mutually exclusive: status: "success" requires data, and status: "error" requires error. This means your application never receives a success response with missing data, or an error response without an error code.