Zod schema builder

Build a Zod object schema in a form — string formats, numeric and length bounds, enums, literals, arrays, records, nested objects, defaults — and copy the schema module with the TypeScript type z.infer derives from it. Zod 4 or Zod 3 spellings. No account, nothing leaves your browser.

Schema

Zod version
Unknown keys

strip drops keys the schema does not declare (Zod’s default), strict rejects them, loose keeps them. Zod 4 spells these z.strictObject and z.looseObject; Zod 3 chains .strict() and .passthrough().

Fields (11)
  • Type
    Format
  • Type
    Format
  • Type
    Format
  • Type
  • Type
  • Type
    Items
  • Type
    Fields
    • Type
      Format
    • Type
      Format
    • Type
      Format
  • Type
import { z } from "zod"

/** A registered user as the API returns it. */
export const userSchema = z.object({
  id: z.uuid().describe("Stable identifier."),
  email: z.email(),
  name: z.string().min(1).max(80),
  age: z.number().int().min(0).optional(),
  role: z.enum(["admin", "member", "guest"]).default("member"),
  tags: z.array(z.string()).default([]),
  address: z.object({
    street: z.string(),
    city: z.string(),
    postcode: z.string().regex(/^[A-Z0-9 ]{3,10}$/),
  }).optional(),
  createdAt: z.date(),
})

export type User = z.infer<typeof userSchema>

Drop the file into your project, npm install zod, and call .parse() or .safeParse(). The type is exported beneath the schema so nothing has to be declared twice.

One declaration, two uses

The file exports userSchema for .parse() at runtime and User for the compiler, and the second is derived from the first — so the preview's “Inferred type” tab is what your editor will show, not a second thing to maintain.

Nothing is auto-fixed

A min above its max, a default outside the enum, a regex that does not compile — each is reported beside the field and left out of the preview. A key that is not an identifier is quoted, never renamed.

Both Zod majors

One switch flips between z.email() and z.string().email(), z.strictObject and .strict() — the spellings that actually differ between Zod 4 and Zod 3.

How to build a Zod schema

Three steps from an empty form to a file you can import. The preview rebuilds on every keystroke, so the schema is never out of step with the form.

  1. Name the schema and pick the spelling

    The name becomes the const (userSchema) and the type (User). Choose Zod 4 unless the codebase is still on 3, and decide what the root does with keys it does not declare.

  2. Add fields

    Each field has a type, and the controls that type reads: a format and pattern for strings, integer and bounds for numbers, members for an enum, an item type for arrays and records. Object fields, and object items, open a nested list.

  3. Copy the schema, or the type

    The schema tab is the module — import, exported schema, exported inferred type. The type tab is that type written out, for reading the shape or pasting somewhere Zod is not.

What the download contains

<name>.schema.ts
import { z } from "zod", the exported schema with every field's constraints, description and modifiers, and export type <Name> = z.infer<typeof <name>Schema>.
<name>.types.ts
The inferred type alone, from the type tab — the same shape without the runtime dependency.

Zod schemas, answered

The longer version is in the guide Zod schemas: optional vs nullable vs default, z.infer and Zod 4. This is an unofficial tool built against the public Zod API — the library itself, and the last word on anything below, lives at zod.dev.

Where the schema goes next

A Zod shape is what a model reads before it calls a tool. The MCP server generator takes one as a tool's input and output schema, and the Claude Agent SDK, OpenAI Agents SDK and Vercel Eve generators each type their tools the same way. In the Nodlume workspace the data model you draw becomes the types the generated code is built on.

We'd like to use Google cookies to understand how Nodlume is used and to measure our advertising. Nothing loads until you choose, and declining does not affect anything in the app.