Validating and Repairing Structured Output
In this article
- Read a reply's stop reason first, and route a refused or cut-off reply without parsing it.
- Check a structured reply in order (parse, schema, the application's own rules) and name the first check it fails.
- Decide whether code, the model or a person repairs a failed reply, and say why.
- Cap the attempts for one item and log each failure so that every repair stays visible.
- Terms defined here: schema validation, semantic validation, output repair.
Overview
A reply can have the right form and still be wrong for its input, so code needs a rule for every reply, and a point at which to stop trying.
In the ticket sorter of Brightline, an invented home-internet provider, a model puts each support ticket in billing, technical, account or other and says whether a person must see it at once, and routing code, the part of the application that reads the reply, picks the team's queue and alerts a person when the ticket is escalated. Each reply is a structured output, a reply in a fixed form that code can read. Every reply must fit one schema, a written rule for which fields and values a reply may have. Both fields, category and escalation, are required and no others are allowed. The reply has the shape {"category": ..., "escalation": ...}. In JSON, a text format that stores each answer under its own name, the escalation field takes one of two forms, {"escalate": true, "reason": ...} for a yes with a reason or {"escalate": false} for a no. One rule lies outside that schema: a ticket with no text gets other and no escalation. Afterwards you can decide for any reply whether to accept it, correct it in code, ask the model again or hand the ticket to a person, and when to stop.
Sign in to keep reading
The rest of this article opens with an account. An account also keeps your progress and quiz results on every device, and lets you follow news for up to five topics.
Still to read in this article
- Fitting the schema is not enough
- Why the reply ended
- Three checks on the text
- Who repairs the reply
- The loop in code
- Worked example
- Sources
- Check yourself, 5 questions