Zod

Zod

TypeScript-first schema declaration and runtime data validation library with automatic static type inference and zero dependencies.

★ 44.6K

Validate untrusted runtime JSON and infer static TypeScript types from one schema

TypeScript’s type annotations disappear completely at compile time, leaving your production server wide open when an external webhook, user form, or LLM structured output sends malformed JSON at runtime. Maintaining a separate TypeScript `interface` alongside a manual validation function guarantees the two will drift apart. Zod lets you declare a single runtime validator and extract the exact static TypeScript type via `z.infer`. With 44.6K GitHub stars and 2,400 forks under the MIT license, it is a core pillar of the TypeScript ecosystem.

Why Zod appears in almost every modern TypeScript stack

  • Single-source-of-truth schemas eliminate duplicate type definitions across form validators, API controllers, environment parsers, and AI tool calls.
  • Composable chaining methods (`z.string().email().trim()`, `.refine()`, `.transform()`) coerce and sanitize messy inputs cleanly in one pass.
  • Safe parsing (`safeParse`) returns structured, path-indexed error objects instead of throwing uncaught exceptions on invalid user input.
  • Native compatibility powers OpenAI and Anthropic structured outputs, LangChain tools, tRPC inputs, Astro Content Collections, and React Hook Form.

Performance considerations at scale

Deeply nested Zod schemas instantiated inside tight loops can add minor CPU and bundle overhead, so declare schemas at module scope and reuse them across requests. Install `zod` today and replace your first unsafe `JSON.parse() as MyType` cast with a verified schema check.

Ready to try Zod?

Experience the full capabilities on their official website.

Visit Official Website