Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 4 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

Zod

Check incoming data in TypeScript apps.

Forms, validation and schemasNPM

GitHubWebsite

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/LICENSE

From 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

89 / 100
Gid Score, #11 overall
471M
downloads a week, npm
44.4K
GitHub stars
1,582
agent projects use it
Zod: downloads per weeknpm, zod 470,598,451
Zod: GitHub starscolinhacks/zod 44,401

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

867 projects, 26.5%
719 projects, 29.4%
711 projects, 23.4%
137 projects, 28.9%
128 projects, 27.3%
97 projects, 28.3%
77 projects, 23.1%
75 projects, 26.9%

Often used with

In 93.5% of its projects
In 31.1% of its projects
In 47.9% of its projects
In 47.2% of its projects
In 32.5% of its projects
In 61.1% of its projects
In 48.2% of its projects
In 42.8% of its projects

Zod in practice

Strengths

The schema is the type

<code>z.infer&lt;typeof Schema&gt;</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.

Opt-in compiled fast path

<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.

Zod Mini for tight bundles

<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.

Lighter on the TypeScript compiler

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

Strict mode is mandatory

The docs require <code>"strict": true</code> in <code>tsconfig.json</code>. Only TypeScript v5.5 and later is officially supported.

Compilation needs new Function

<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.

Async schemas stay uncompiled

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

See all

Head to head
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

MITGid 89471M/wk

Pydantic

Pick Pydantic when your back end is written in Python; it checks data using Python type hints.

Ajv

Pick Ajv when your rules already exist as JSON Schema files that you check against at run time.

MITGid 78547M/wk

Valibot

Pick Valibot when you want a modular schema library built from small separate functions.

MITGid 6836M/wk

TypeBox

JSON Schema type builder with static type resolution for TypeScript validation.

MITGid 5817M/wk

Yup

Simple schema validation library for JavaScript with chainable API and error handling.

MITGid 6916.6M/wk

Compare Zod with another tool

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).”

  1. Add Zod to your project.

    npm install zod

    From zod.dev/

  2. 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

  3. Turn on strict mode in tsconfig.json; Zod expects it.

    {
      "compilerOptions": {
        "strict": true
      }
    }
    

    From zod.dev/

Rules for your agent

Paste into AGENTS.md or CLAUDE.md
## 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

z.string().email(), z.string().uuid(), z.string().url()
z.email(), z.uuid(), z.url()

In Zod 4 string formats moved to the top level; the old methods still run in 4.6.7 but are deprecated.

z.object({...}).strict() or .passthrough()
z.strictObject({...}) or z.looseObject({...})

Zod 4 deprecates the two methods in favour of top-level functions.

result.error.errors
result.error.issues

.errors was removed in Zod 4; in our run it was undefined while .issues held the problem.

z.object({ port: z.coerce.number() }) and expecting a missing key to pass
z.coerce.number().default(3000) when the key may be absent

In Zod 4 a missing key with a coerce field is an error, unlike Zod 3.

Calling z.compile() or importing "zod/compile" on a page with a strict Content Security Policy
Leave compilation off there, or set z.config({ jitless: true }) so global mode stands down

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.