How it works
You define a schema such as z.object({ name: z.string(), age: z.number().min(18) }) and call parse or safeParse on incoming data. Zod returns the checked data or a list of clear errors, and z.infer turns the same schema into a TypeScript type, so the type and the runtime check never drift apart.
It runs in browsers and on servers alike: checking form input with React Hook Form, request bodies in API routes, environment variables at start-up and structured output from AI models. Version 4 made it faster and smaller and added JSON Schema conversion. Libraries that follow the Standard Schema spec accept Zod, Valibot or ArkType interchangeably.
Zod pros and cons
Pros
- One schema gives both a runtime check and a TypeScript type
- Readable, chainable API with clear error messages
- Works the same in the browser and on the server
- Wide ecosystem support: tRPC, React Hook Form, AI SDKs
Cons
- Larger bundle than lighter options such as Valibot
- Very large schemas can slow TypeScript down in the editor
When to use Zod
Pick it when
- Validating anything from outside: forms, API requests, webhooks, files
- Sharing one set of rules between frontend and backend
- Checking environment variables and AI model output
Skip it when
- Bundle size is critical and a lighter library such as Valibot will do
Zod pricing
Related terms
More in Frontend
Forms and validation