1. License
“Permission is hereby granted, free of charge, to any person obtaining a copy”
MIT allows use in paid and closed-source products.
github.com/colinhacks/zod/blob/main/LICENSE3. Used by agents' projects
Dependency in 1,582 public GitHub projects set up for AI coding agents that we scanned (25.3%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
zod.dev/llms.txtFrom the package registry and GitHub, checked daily; card checked Nov 10, 2026. Tap a verdict to see its source.How we checkedReport an error
What Zod does
Zod is a free TypeScript library that checks data before your app trusts it, such as form fields, settings or replies from other services. You describe once what the data must look like, and Zod either hands back clean data or says exactly which field is wrong. It runs on the server and in the browser.
What people build with it
Check sign-up forms on the server
A visitor sends an email, an age and a plan; your server accepts the request only when every field fits the rules.
Show the error next to each field
When a form is wrong, your page shows "Invalid email address" under the email box instead of one vague message.
Tell an AI model what to return
Describe the answer you want from a language model once, send that description with the request, then check the reply before you use it.
Quick yes-or-no check on big uploads
When a large file or request only needs a pass or fail answer, a cheaper check skips building the full list of problems.
Refuse to start with broken settings Idea
Your app reads its port and database address at start-up and stops with a clear message if one is missing or wrong.
Check replies from other services Idea
Before your app saves data fetched from a payment or shipping service, make sure the fields you rely on are really there.
Zod popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How Zod is used
- Zod is a dependency in 1,582 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (32.5% of the 4,867 JavaScript/TypeScript ones), #1 of 63 in forms, validation and schemas.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 5,755; those are left out of every share on this page.
- The most used alternative in our scan is Ajv (154 projects).
- Projects that use it most often also use TypeScript (93.5%), React Hook Form Resolvers (31.1%), clsx (47.9%).
By coding agent
Often used with
Zod in practice
Strengths
<code>z.infer<typeof Schema></code> extracts a static type from a schema, so you don't write the type twice. When a <code>.transform()</code> changes the type, <code>z.input</code> and <code>z.output</code> give you each side separately.
<code>z.compile(schema)</code> returns a clone with an ahead-of-time compiled path for valid inputs. Invalid inputs fall back to the regular parser, so error output stays the same. The README reports a median 2.4x speedup across a 55-schema benchmark. It says gains grow with how much work each parse does, and a bare <code>z.string()</code> gains nothing.
<code>zod/mini</code> maps one-to-one to the main API but uses wrapper functions such as <code>z.optional(z.string())</code> instead of methods. The maintainer says this makes it easier for bundlers to drop the parts you don't use.
The release notes give a sample file that produced more than 25000 type instantiations under Zod 3 and about 175 under Zod 4. In the same notes, a long chain of <code>.extend()</code> and <code>.omit()</code> calls compiled in 400ms, down from 4000ms.
Watch out for
The docs require <code>"strict": true</code> in <code>tsconfig.json</code>. Only TypeScript v5.5 and later is officially supported.
<code>z.compile()</code> relies on <code>new Function</code>. Global compile mode switches off when <code>z.config({ jitless: true })</code> is set, for example in CSP environments.
Schemas with async refinements or transforms are handed back unchanged and keep using the regular parser. Pass <code>{ strict: true }</code> if you want an error thrown instead.
Infer a type from a schema
const Player = z.object({
username: z.string(),
xp: z.number(),
});
// extract the inferred type
type Player = z.infer<typeof Player>;
// use it in your code
const player: Player = { username: "billie", xp: 100 };More about Zod
Funding
- GitHub Sponsors: https://github.com/colinhacks
- 58 GitHub sponsors
Head to head
- Zod vs Ajv used together in 79 projects
Packages around it
- class-variance-authority: Component variant classes
- tailwind-merge: Tailwind class conflict merging
- clsx: Conditional className strings
- react-hook-form: Hook-based form state
- @radix-ui: Unstyled UI primitives
- typescript: Typed JavaScript
More in Forms, validation and schemas
Alternatives
Zod This page
Pick Pydantic when your back end is written in Python; it checks data using Python type hints.
Pick Ajv when your rules already exist as JSON Schema files that you check against at run time.
Pick Valibot when you want a modular schema library built from small separate functions.
JSON Schema type builder with static type resolution for TypeScript validation.
Simple schema validation library for JavaScript with chainable API and error handling.
Get started
Tell your AI assistant
“Use Zod (pin zod@4.6.7, TypeScript 5.5+ with strict mode) to validate every request body and form in this app with safeParse, show per-field messages from z.flattenError, and use the Zod 4 API (z.email(), z.strictObject(), error.issues).”
Describe the data once, then parse incoming data with it. Valid data comes back typed; bad data throws an error that lists every problem.
import * as z from "zod"; const Player = z.object({ username: z.string(), xp: z.number() }); Player.parse({ username: "billie", xp: 100 });From zod.dev/basics
Turn on strict mode in tsconfig.json; Zod expects it.
{ "compilerOptions": { "strict": true } }From zod.dev/
Rules for your agent
## Zod
- Set `"strict": true` in `tsconfig.json` and target TypeScript v5.5 or later.
- Derive types with `z.infer<typeof Schema>` (or `z.input` / `z.output` when a `.transform()` changes the type) instead of writing them by hand.
- Use `.safeParse()` to get a result object instead of wrapping `.parse()` in `try/catch`. Switch to `.parseAsync()` / `.safeParseAsync()` when a schema has async refinements or transforms.
- In Zod 4, prefer top-level formats like `z.email()`, `z.uuid()` and `z.ipv4()` over the deprecated `z.string().email()` method forms.
- In Zod 4, customize errors with the `error` param, not `message`. Use `z.treeifyError()` instead of the deprecated `.format()` / `.flatten()`.
- When using `z.compile()`, compile the final schema. Calling `.refine()`, `.extend()` and similar on a compiled schema returns an uncompiled one.
- For apps with strict bundle-size limits, import from `zod/mini` and add checks with `.check()`.
Mistakes to avoid
In Zod 4 string formats moved to the top level; the old methods still run in 4.6.7 but are deprecated.
Zod 4 deprecates the two methods in favour of top-level functions.
.errors was removed in Zod 4; in our run it was undefined while .issues held the problem.
In Zod 4 a missing key with a coerce field is an error, unlike Zod 3.
Compilation builds code with new Function, which strict CSP pages block.
Questions
Do I need TypeScript to use it?
No. It works with TypeScript and with plain JavaScript; with TypeScript it also gives you the data's type for free.
Which TypeScript version does it need?
Zod is tested with TypeScript 5.5 and later, with strict mode turned on.
Can I turn my rules into JSON Schema for an AI model or an API description?
Yes, z.toJSONSchema() converts a schema; a few kinds of rules have no JSON Schema equivalent.
Is Zod 3 still maintained?
The docs call Zod 3 functionally end-of-life with no new features; new projects should use version 4.