Zod

A TypeScript-first schema validation library that infers static types from schemas.

my take

Define a schema once, get runtime validation and a TypeScript type for free. It's everywhere for a reason — forms, API inputs, env vars. The content schema in this very site is Zod.

Zod is a TypeScript-first schema validation library. You describe the shape of your data once, and Zod gives you both a runtime validator and a static TypeScript type inferred from it — no duplication, no drift. It has become the default way to validate form input, API payloads, environment variables and more.

Start with this

ts
import { z } from 'zod';

const Tool = z.object({
  name: z.string(),
  price: z.enum(['free', 'freemium', 'paid']),
  tags: z.array(z.string()).default([]),
});

// one schema, two outputs:
type Tool = z.infer<typeof Tool>;   // the static type
const parsed = Tool.parse(input);   // runtime validation (throws if invalid)

The take, for AI builders

For AI builders, Zod is quietly one of the most useful libraries you can learn: it is the bridge between untrusted input (a form, an API response, an LLM's JSON output) and types you can trust. Define the schema and an agent can generate correct, validated handlers around it. This very site's content collection is validated with Zod. The only real trade-off is bundle size on the client — if that matters, Valibot does the same job in a fraction of the bytes.

When to reach for it

✓ Good fit

  • Validating form input, API payloads or environment variables
  • You want one schema to produce both runtime checks and a TypeScript type
  • Parsing and trusting an LLM's structured (JSON) output

✕ Not for

  • Client bundle size is critical (consider Valibot)
  • You're not using TypeScript and want nothing extra

Alternatives

  • The same schema-and-infer idea with a much smaller, modular bundle.

  • If your real need is forms specifically, a typed form library pairs with a validator like this.

Visit Zod

Related in State & data

State & data

date-fns

A modern, modular JavaScript date utility library with tree-shakeable functions.

Free
  • dates
  • utility
  • javascript
take

Date handling without dragging in a giant library — import just the functions you use. The sensible modern choice now that Moment is legacy.

Visit ↗
State & data

Day.js

A 2kB immutable date library with a Moment.js-compatible API.

Free
  • dates
  • lightweight
  • javascript
take

Moment's tiny successor — the same familiar API in 2kB. Pick it when you want Moment's ergonomics without Moment's weight.

Visit ↗
State & data

Jotai

An atomic state management library for React built around primitive atoms.

Free
  • react
  • state
  • atoms
take

Bottom-up, atomic state that scales from one value to a whole app without ceremony. Lovely when state is granular — a different mental model than stores, in a good way.

Visit ↗