Skip to content

zod

Use when working with Zod for schema validation — form validation, API input parsing, environment variable validation, or TypeScript type inference from schemas. Also use when choosing a validation library or debugging Zod type errors.

ModelSource
sonnetpack: forms
Full Reference

┏━ 🔧 zod ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Use when working with Zod for schema validatio… ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

Zod v4 is a TypeScript-first schema validation library with static type inference. v4 (released July 2025) ships 14x faster string parsing, a ~57% smaller bundle vs v3, and top-level format validators like z.email() and z.url(). v3 is still available at the "zod": "^3" package root; v4 is the new default.

ItemValue
Current Version4.3.6 (stable, February 2026)
Installnpm install zod
Importimport { z } from "zod"
v4 subpathimport { z } from "zod/v4"
Mini (tree-shakable)npm install @zod/mini (~1.9 KB gz)
TypeScript requirementv5+ recommended
Docshttps://zod.dev
I want to…File
Define primitives, objects, arrays, enums, and composition patternsreference/schemas.md
Parse and validate data, infer types, or validate env vars and API inputsreference/parsing.md
Handle ZodError, format errors, or write custom error messagesreference/error-handling.md
Transform, refine, pipe, or coerce valuesreference/transforms.md
Use unions, discriminated unions, recursive schemas, branded types, or migrate from v3reference/advanced-types.md

Usage: Read the reference file matching your current task from the index above. Each file is self-contained with code examples and inline gotchas.