prompt-eng

Output Validation

Output validation is the step that checks an LLM's response against explicit rules before your application acts on it — parsing the JSON, confirming required fields exist with the right types, enforcing enum and range constraints, and applying business rules — then retrying, repairing, or falling back when the check fails. Because models are non-deterministic and occasionally return malformed or invented data, treating raw output as trusted is a common source of production bugs. Validation is the safety net that turns "usually works" into "safe to ship." For SaaS builders, the standard pattern is: generate with a schema, parse into a typed object (libraries like Zod, Pydantic, or JSON Schema validators), and on failure either re-prompt with the specific error ("your last output was missing 'price'; return valid JSON") or degrade gracefully. Validate meaning as well as shape — a syntactically valid but semantically wrong value (a negative price, an out-of-catalog SKU) should also be caught. Log validation failures; a rising rate is an early signal of prompt drift or a model change.

Related terms

More Prompt Engineering terms