Zod v4 Schema Validation

VerifiedSafe

Best practices for Zod v4: schema annotations, metadata, and common pitfalls.

Sby Skills Guide Bot
DevelopmentIntermediate
8/13/2026
Claude CodeCursorWindsurfCopilotCodex
#zod#typescript#schema-validation#type-inference#metadata

Recommended for

Automated summary

This skill provides Zod v4 TypeScript schema validation patterns and best practices, with a focus on attaching metadata annotations to schemas.

Strengths

  • Enforces the chain-order rule: .meta()/.describe() must be called last or metadata is silently lost
  • Lists concrete v4 gotchas such as top-level z.email(), deprecated .merge(), and z.object() stripping unknown keys
  • Shows how to annotate object properties with structured metadata like label, description, and placeholder
  • Points to the official references for the API, metadata registries, and the v3 → v4 migration

Limitations

  • Covers Zod v4 only, so guidance is partial for projects still on v3
  • Does not address framework or form-library integration, nor performance considerations
  • Content is mostly rules and snippets rather than complete end-to-end schema examples
When to use it

Use it when writing or refactoring Zod v4 schemas, adding metadata annotations, or migrating away from v3 patterns.

When not to use it

Avoid it if the project is still on Zod v3 or if the task is really about wiring schemas into a form library or framework.

Security analysis

Safe
Quality score88/100

The skill is pure documentation with TypeScript examples and reference links. It declares no tools, executes no commands, accesses no secrets, and contains no destructive, exfiltrating, or obfuscated instructions.

No concerns found

How this analysis is made

Examples

Annotate a signup schema
Create a Zod v4 signup schema with email, password, and age fields, and add .meta() annotations with labels, descriptions, and placeholders for each field.
Fix lost metadata
My Zod schema loses its description after I call .optional() — review this code and fix the metadata chain order.
Migrate v3 to v4
We're upgrading from Zod v3 to v4 — update this file to use top-level z.email() and replace .merge() with .extend().

name: zod description: Zod v4 TypeScript schema validation patterns and best practices. Use when writing or modifying Zod schemas, adding schema annotations/metadata, or validating data with Zod. license: AGPL-3.0 metadata: triggers: type: domain enforcement: suggest priority: medium keywords: - zod - z.object - z.string - z.number - z.array - schema validation - z.infer intent-patterns: - "\b(validate|create|define|add)\b.*?\b(schema|zod)\b" - "\bzod\s+(v4|version|migration)\b"

Zod v4 Schema Validation

TypeScript-first schema validation library with static type inference. This skill covers v4 patterns including the metadata registry system.

Schema Annotations

Zod v4 stores metadata in registries (primarily z.globalRegistry). Use .meta() as the primary API and .describe() as shorthand for description-only cases.

IMPORTANT: Always call .meta()/.describe() last in the method chain. Methods like .min(), .optional(), .extend() return new schema instances, so metadata must be attached at the end.

// ✅ Correct - .meta() at end of chain
z.string()
  .min(1)
  .max(100)
  .meta({ description: "User's full name", label: "Name" });

// ✅ Correct - .describe() shorthand for description only
z.string().email().describe("Primary email address");

// ❌ Wrong - metadata lost because .optional() creates new instance
z.string().meta({ description: "Lost!" }).optional();

Annotating object properties:

const userSchema = z.object({
  email: z.string().email().meta({
    description: "Used for login",
    label: "Email Address",
    placeholder: "you@example.com",
  }),
  age: z.number().min(0).describe("User's age in years"),
});

API guidance:

  • Use .meta(obj) for structured metadata (title, description, examples, UI hints)
  • Use .describe(text) as shorthand when only a description string is needed
  • Read .description for backwards compatibility with v3 tooling
  • Never mutate .description directly—always use .meta()/.describe() to set

Gotchas

  • Metadata chain order: .meta()/.describe() MUST be called last—schema methods return new instances
  • Don't mutate .description: Read .description for v3 compatibility, but always set via .meta() or .describe()
  • .email(), .uuid(), etc. are top-level: Use z.email() not z.string().email() (latter deprecated)
  • z.object() strips unknown keys: Use z.strictObject() to reject unknown keys
  • .merge() deprecated: Use .extend() instead

References

  • Complete API reference: https://zod.dev/llms.txt
  • Schema types: https://zod.dev/api
  • Metadata/registries: https://zod.dev/metadata
  • JSON Schema conversion: https://zod.dev/json-schema
  • v3 → v4 migration: https://zod.dev/v4/changelog

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/zod-v4-schema-validation-msr1u7e1/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/zod-v4-schema-validation-msr1u7e1' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/zod-v4-schema-validation-msr1u7e1/download' --output '.skill-downloads/zod-v4-schema-validation-msr1u7e1/SKILL.md.part' && mv '.skill-downloads/zod-v4-schema-validation-msr1u7e1/SKILL.md.part' '.skill-downloads/zod-v4-schema-validation-msr1u7e1/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/zod-v4-schema-validation-msr1u7e1/SKILL.md' && test -s '.skill-downloads/zod-v4-schema-validation-msr1u7e1/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/zod' && cp -R '.skill-downloads/zod-v4-schema-validation-msr1u7e1' '.claude/skills/zod'

Cursor
test -f '.skill-downloads/zod-v4-schema-validation-msr1u7e1/SKILL.md' && test -s '.skill-downloads/zod-v4-schema-validation-msr1u7e1/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/zod' && cp -R '.skill-downloads/zod-v4-schema-validation-msr1u7e1' '.cursor/skills/zod'

Codex
test -f '.skill-downloads/zod-v4-schema-validation-msr1u7e1/SKILL.md' && test -s '.skill-downloads/zod-v4-schema-validation-msr1u7e1/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/zod' && cp -R '.skill-downloads/zod-v4-schema-validation-msr1u7e1' '.agents/skills/zod'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/zod-v4-schema-validation-msr1u7e1'

openskills read 'zod-v4-schema-validation-msr1u7e1'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/zod-v4-schema-validation-msr1u7e1/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills