pattern

Output Validation Layer

A deterministic check applied to model output before it is used, treating the model as an untrusted component.

The architectural principle that makes LLM systems safe to operate: the model's output is untrusted input to everything downstream. It may be malformed, wrong, unsafe, or shaped by an injected instruction — and it must be validated before it reaches a user, a database or a tool.

Validation in layers, cheapest first:

Schema validation — the output parses and contains the required fields. Free, unambiguous, and it catches the largest share of failures.

Business rule validation — the values are in range, the referenced entities exist, the proposed action is permitted for this user.

Content checks — prohibited claims, personal data leakage, unsafe content.

Grounding verification for retrieval-based answers — do the assertions appear in the retrieved sources? This is the strongest available defence against confident fabrication, and it is the check most often omitted.

Model-based checks for quality, when the cheaper layers cannot express the requirement.

The design decisions that surround it: what happens on failure — retry, fall back to a stronger model, degrade to a safe response, or escalate to a human, decided per case rather than left to a generic handler; and failing closed for consequential outputs, because a wrong answer delivered confidently is worse than an apology.

Input guardrails matter too, but output validation is the one that bounds the damage.