Guides & concepts

Validation

Three schemas, two protocols, one invariant.

SchemaValidatesRuns
pathParamsSchemaBound path parametersBefore the URL is built
requestSchemaThe request body or query paramsBefore the request is sent
responseSchemaThe response bodyAfter the response arrives

Two protocols, checked in order

hapi accepts anything with safeParse and anything implementing Standard Schema V1. safeParse is tested first, because Zod satisfies both and that path is always synchronous.

Issues are not normalised

failure.issues is typed unknown on purpose. A ZodError and a Standard Schema issue array both reach you intact — flattening them would lose information only the originating library can interpret.

Deferring response validation

For a large response where parsing would block a render, declare the schema as async. The data resolves immediately and validation runs in a detached promise, reporting failures through onResponseValidationError without throwing.

responseSchema: { schema: bigSchema, mode: 'async' }