Schema Validation
Checking data against a declared shape at runtime, and using the result as the typed value.
Schema validation is checking incoming data against a declared structure before trusting it. In typed languages the modern idiom is parse, don't validate: rather than asserting that an unknown value has a type, run it through a parser that returns a typed value or fails. The type then rests on an actual check rather than a claim.
That distinction matters because the alternative — a type assertion — is a promise the compiler accepts and never verifies. A cast asserting that a value conforms is exactly as strong as the author's belief, which is to say not at all. Where a value is already typed and merely needs re-expressing as the schema's type, running it through the parser is both safer and clearer than casting: the parser accepts unknown input by design, so no cast is needed, and permissive object schemas pass unrecognised fields through unchanged.
Two operational notes. A guard claiming a value is both A and B, backed by a check for only B, is unsound — it asserts the unchecked half. And where schemas grow large, keeping them in a dedicated module rather than inline keeps the module's actual exports readable.
Validation is the natural boundary for a system taking model output; see Structured Output.
See also7
Hand-picked in the note itself — the neighbours worth reading next.
JSON Schema
A vocabulary for describing the shape of JSON data, and the lingua franca of model tool interfaces.
Agents & Language Models9 connections
Structured Output
Constraining a model to emit data conforming to a declared schema rather than free text.
Agents & Language Models11 connections
Fail Fast
Crash at the point of misconfiguration rather than degrading quietly into a wrong state.
Method12 connections
Schema Drift
Divergence between a schema and the code, types, or documentation that describe it.
Data & Content9 connections
Constrained Decoding
Restricting a model's next-token choices to those a formal grammar permits.
Agents & Language Models9 connections
Tool Use
Giving a model a set of callable functions so it can act on the world rather than only describe it.
Agents & Language Models24 connections
Unreachable Code
Code no input can execute — usually a guard against a state the surrounding invariants forbid.
Testing & Verification10 connections
Related2
Nearby in the graph rather than deliberately chosen. Looser, sometimes surprising.
Linked from8
Notes elsewhere in the wiki that reach for this one.
- Constrained DecodingAgents & Language Models
Restricting a model's next-token choices to those a formal grammar permits.
- Defensive DefaultMethod
A substituted value that papers over a missing input and hides the misconfiguration that produced it.
- Goodhart's LawMethod
When a measure becomes a target, it stops being a good measure.
- JSON SchemaAgents & Language Models
A vocabulary for describing the shape of JSON data, and the lingua franca of model tool interfaces.
- Schema DriftData & Content
Divergence between a schema and the code, types, or documentation that describe it.
- Structured OutputAgents & Language Models
Constraining a model to emit data conforming to a declared schema rather than free text.
- Tool UseAgents & Language Models
Giving a model a set of callable functions so it can act on the world rather than only describe it.
- Unreachable CodeTesting & Verification
Code no input can execute — usually a guard against a state the surrounding invariants forbid.