AIF-14Recommended
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. Show the answer to the user as Say so when nothing relevant was found says.
Examples
TypeScript example
const Invoice = z.object({
invoiceNumber: z.string().nullable(),
dueDate: z.iso.date().nullable(),
currency: z.enum(['EUR', 'SEK', 'USD', 'unknown']),
});
Python example
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.
Sources
Related rules
- AIF-23 Say so when nothing relevant was found in AI features
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/allow-unknown">Agent Wranglers AI features playbook</a>. In code you write, add a comment next to it with the same link.