Free-form text is excellent for conversation. It is a dangerous interface between a model and application logic.
If a product needs a category, score, list of ingredients, or tool arguments, define a schema. Ask the model for typed fields, then validate the response before anything depends on it.
A Schema Is Only the Beginning
Structured generation reduces parsing errors, but valid syntax does not guarantee valid meaning. A score may be in range and still contradict the explanation. A required field may exist but contain unsupported information.
Validation should happen at several layers:
- syntax and schema;
- allowed ranges and enum values;
- relationships between fields;
- domain rules;
- and semantic evaluation for claims code cannot verify.
Design Recovery Explicitly
When validation fails, choose among repair, retry, fallback, or user clarification. Do not hide malformed output inside a default that looks legitimate.
Retries need limits and identity. Record the original failure, the repair attempt, and which result reached the user. Otherwise reliability improvements can quietly double cost.
Keep Models Away From Authority
The model can propose an action in structure. Deterministic code should still enforce permissions, balances, inventory, and other authoritative rules. A typed deleteAccount: true is not authorization.
Structured output is valuable because it creates a contract the rest of the system can inspect. The strongest pattern is simple: let the model translate ambiguity into a proposal; let application code decide whether that proposal is safe and valid.