Agent Wranglers

Structured output and tools Required

Give the model a way to say it does not know

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

How to do it

Strict structured output always fills required fields. Without an escape value the model invents one, such as a date or an order number. Add unknown to enums and make fields nullable where the input may lack them. Treat unknown in code as "ask the user" or "send to a person". Put cases with missing information in the eval set and expect unknown there.

Example

const Invoice = z.object({
  invoiceNumber: z.string().nullable(),
  dueDate: z.iso.date().nullable(),
  currency: z.enum(['EUR', 'SEK', 'USD', 'unknown']),
});
class Invoice(BaseModel):
    invoice_number: str | None
    due_date: date | None
    currency: Literal["EUR", "SEK", "USD", "unknown"]

How to check

Run the eval cases that lack the needed information. Each returns unknown or null in the right field, and none returns an invented value.

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/allow-unknown.