Kelly Mears

Schema Validation

Checking data against a declared shape at runtime, and using the result as the typed value.

Agents & Language Models2 min read208 words14 out · 19 in
also calledRuntime validationParsing not validating

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 unrecognized 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 also13

JSON Schema

A vocabulary for describing the shape of JSON data, and the lingua franca of model tool interfaces.

Agents & Language Models14 connections

Fail Fast

Crash at the point of misconfiguration rather than degrading quietly into a wrong state.

Method27 connections

Schema Drift

Divergence between a schema and the code, types, or documentation that describe it.

Data & Content16 connections

Constrained Decoding

Restricting a model's next-token choices to those a formal grammar permits.

Agents & Language Models11 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 Models27 connections

Unreachable Code

Code no input can execute — usually a guard against a state the surrounding invariants forbid.

Testing & Verification11 connections

Prompt Engineering

Shaping a model's input to make the desired behavior reliable rather than occasional.

Agents & Language Models22 connections

Large Language Model

A neural network trained to predict text, used as a general-purpose instruction-following system.

Agents & Language Models38 connections

Design by Contract

Specifying what each function requires and guarantees, as checkable preconditions, postconditions, and invariants, so a violation says exactly whose bug it is.

Testing & Verification12 connections

Form Validation

Checking what people type into a web form before accepting it, done in the browser for fast feedback and on the server for safety, and harder than it looks because real names, addresses, and numbers break simple rules.

Web Platform11 connections

SQL Injection

An attack in which user input is pasted into a database query and gets run as code, prevented by keeping the query and its data in separate channels.

Data & Content15 connections

Type System

The rules a language uses to classify values and reject operations that don't fit, checked before the program runs or as it runs, and the cheapest form of verification most programmers use every day.

Testing & Verification12 connections

Prototype Pollution

A JavaScript vulnerability where attacker-controlled keys like "__proto__" modify the prototype every object inherits from, silently adding properties everywhere, and how merge utilities and parsers let it in.

Web Platform10 connections

Linked from19