zod

Validate TypeScript data against Zod v4 schemas with metadata annotations.

1.6k|123|Updated Jul 15, 2019
One-click install
npx skills add https://github.com/hashintel/hash --skill zod-hashintel
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: zod
Source: https://github.com/hashintel/hash/tree/main/.codex/skills/zod
Command: npx skills add https://github.com/hashintel/hash --skill zod-hashintel

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Zod provides TypeScript-first schema validation patterns and best practices for writing robust schemas, annotations, and data validation.

Core Features & Use Cases

  • Schema Annotations: Use .meta() and .describe() to attach metadata to schemas for UI hints and tooling.
  • Type Inference & Validation: Leverage z.infer, z.object, z.string, z.number, and z.array for strong typing and runtime validation.
  • API Guidance & Gotchas: Follow recommended chaining order; avoid mutating descriptions; handle object shapes and strict object mode.
  • Examples: Annotate a user object with property-level metadata for UI forms.

Quick Start

Create a simple user schema and validate a sample payload, e.g., z.object({ name: z.string() }).parse({ name: "Amy" }).

Frequently Asked Questions about zod

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate TypeScript data against a schema at runtime?

Schema validation in TypeScript uses Zod to define type-safe schemas and parse data at runtime. Create a schema with `z.object()`, `z.string()`, or other type constructors, then call `.parse()` to validate incoming data and throw errors on mismatch.

What's the best way to add metadata and descriptions to Zod schemas?

Attach metadata to Zod schemas using `.meta()` and `.describe()` methods at the end of schema chains. This enables UI hints, tooling integration, and labeled metadata storage via global registries for complex object annotations.

How do I infer TypeScript types from Zod schemas?

Use `z.infer<typeof schema>` to extract a TypeScript type directly from your Zod schema definition. This ensures your runtime validation schema and static types stay synchronized automatically.

Can I validate complex nested objects and arrays with Zod?

Zod supports nested validation through `z.object()` for complex shapes and `z.array()` for collections. Combine these with `z.string()`, `z.number()`, and other primitives to build deeply nested, type-safe schemas.

What's the difference between z.object() and z.strictObject() in Zod?

Both define object schemas, but `z.strictObject()` rejects unknown properties during validation, while `z.object()` allows them by default. Choose strict mode when you need to enforce exact shape matching.

How do I extend and reuse existing Zod schemas?

Extend schemas using the `.extend()` method to add or override properties on existing `z.object()` definitions. This enables schema composition and reduces duplication across TypeScript validation logic.