# Zod — card for AI agents

TypeScript-first schema validation library with static type inference.

Category: Forms, validation and schemas · npm package `zod` · latest version 4.6.7 (checked 2026-11-01)
Install: `npm install zod`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (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` (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()`.

## Docs written for agents
- [llms.txt (index of the docs)](https://zod.dev/llms.txt)

## What it is
- Zod is a TypeScript-first validation library. You define a schema, call `.parse()` on untrusted data, and get back a strongly typed, validated result. If the data is invalid, it throws a `ZodError` with a list of issues. The same schema yields a static type through `z.infer<>`, so the type and the check come from one definition. The repository was created in March 2020, is MIT licensed, and the latest release is v4.6.5.
- Zod 4 is the current major version. The maintainer says it is faster and slimmer than Zod 3, and its migration guide lists breaking changes. The `zod/mini` entry point offers a functional API with wrapper functions instead of methods, aimed at projects with tight bundle budgets. `z.compile()` builds a faster path for schemas you validate often.
- The docs say Zod is tested against TypeScript v5.5 and later and requires `"strict": true`. The README says it also works with plain JS, in Node.js and in all modern browsers. For coding agents, the site offers an MCP server for searching the docs and an `llms.txt` file.

## Caveats
- Strict mode is mandatory: The docs require `"strict": true` in `tsconfig.json`. Only TypeScript v5.5 and later is officially supported.
- Compilation needs new Function: `z.compile()` relies on `new Function`. Global compile mode switches off when `z.config({ jitless: true })` 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 `{ strict: true }` if you want an error thrown instead.
- Refinements can run twice: On a compiled schema, invalid input goes through the fast path and then the fallback. Side effects in refinements or transforms may fire twice.
- Zod 3 code can break on upgrade: The migration guide lists many behavior changes. One example: an object with a missing `z.coerce.*` field used to get a default value and now errors. Others: `z.number()` rejects infinite values, and `.int()` accepts only safe integers.

## Numbers (AgentGid data)
- Gid Score: 89.2 (#11 of all tools, 1 of 63 in its category)
- Used in 1,582 public projects set up for AI coding agents (25.3%)
- Downloads last week: 470,598,451 (as of 2026-11-24), +38.9% over 4 weeks
- GitHub stars: 44,401 (as of 2026-11-24)
- Last push: 2026-11-22

## Often used with
TypeScript 93.5%, React Hook Form Resolvers 31.1%, clsx 47.9%, Tailwind Merge 47.2%, React Hook Form 32.5%, React 61.1%

## Checked alternatives (same job)
- Ajv: https://agentgid.com/tools/ajv/agent.md
- Valibot: https://agentgid.com/tools/valibot/agent.md
- TypeBox: https://agentgid.com/tools/sinclair-typebox/agent.md
- Yup: https://agentgid.com/tools/yup/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/zod/
- Homepage: https://zod.dev
- Repository: https://github.com/colinhacks/zod
- Source: https://github.com/colinhacks/zod#readme
- Source: https://github.com/colinhacks/zod
- Source: https://github.com/colinhacks/zod/releases
- Source: https://zod.dev
- Source: https://zod.dev/?id=introduction
- Source: https://zod.dev/v4/changelog
- Source: https://zod.dev/v4?id=why-a-new-major-version


## Zod: check incoming data in TypeScript apps

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.

### Where to use 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: Your app reads its port and database address at start-up and stops with a clear message if one is missing or wrong. (idea, not from the official pages)
- Check replies from other services: Before your app saves data fetched from a payment or shipping service, make sure the fields you rely on are really there. (idea, not from the official pages)

### How to start
- Add Zod to your project.

```
npm install zod
```

- 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 });
```

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

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


### License
Free to use in any project, paid or not, under the MIT license. Keep the license notice when you ship Zod's own files; no credit on screen is needed.

### Good to know
- It has no other packages inside and runs both on servers and in modern browsers.
- Version 4 changed many names and behaviours from version 3, and older tutorials still show the old ones.
- The full check reports every problem, so a huge bad input means a huge error list; cap sizes or use the yes-or-no check.
- Some rules cannot be written out as JSON Schema, for example dates, maps and custom transforms.

Checked 2026-11-10 against: https://zod.dev/, https://zod.dev/basics, https://zod.dev/api, https://zod.dev/v4, https://zod.dev/v4/changelog, https://zod.dev/error-formatting, https://zod.dev/error-customization, https://zod.dev/json-schema, https://zod.dev/compile, https://zod.dev/library-authors, https://zod.dev/blog/zod-4-6, https://zod.dev/llms.txt, https://github.com/colinhacks/zod/blob/main/packages/zod/README.md, https://github.com/colinhacks/zod/blob/main/LICENSE, https://registry.npmjs.org/zod

### Mistakes to avoid
- Don't: z.string().email(), z.string().uuid(), z.string().url() → Do: 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.)
- Don't: z.object({...}).strict() or .passthrough() → Do: z.strictObject({...}) or z.looseObject({...}) (Zod 4 deprecates the two methods in favour of top-level functions.)
- Don't: result.error.errors → Do: result.error.issues (.errors was removed in Zod 4; in our run it was undefined while .issues held the problem.)
- Don't: z.object({ port: z.coerce.number() }) and expecting a missing key to pass → Do: 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.)
- Don't: Calling z.compile() or importing "zod/compile" on a page with a strict Content Security Policy → Do: 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.

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
