zod-v3

Document Zod v3 schema validation APIs for TypeScript runtime checks.

1|Updated Mar 6, 2026
One-click install
npx skills add https://github.com/zenbuapps/zenbu-powers --skill zod-v3
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: zod-v3
Source: https://github.com/zenbuapps/zenbu-powers/tree/main/skills/zod-v3
Command: npx skills add https://github.com/zenbuapps/zenbu-powers --skill zod-v3

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Zod v3 完整 TypeScript schema 驗證參考。涵蓋所有 API、型別定義、程式碼範例。適用版本 zod ^3.x(本專案 ^3.24.2),不適用於 v4(v4 已發布 API 有顯著差異)。當程式碼涉及 zod、z.object、z.string、z.number、z.infer、ZodError、 safeParse、z.union、z.enum、z.discriminatedUnion、z.refine、z.transform、z.coerce、parseAsync、ZodType、z.nativeEnum、runtime validation 時,必須使用此 skill。Zod v4 已發布但本專案用 v3,API 不同。

Core Features & Use Cases

  • Comprehensive API reference: literals, objects, arrays, unions, enums, records, maps, sets, discriminated unions, etc.
  • Guidance on TypeScript inference, error handling, safeParse, parseAsync, and real-world validation patterns across API payloads, forms, and runtime data.
  • Notes on v3 vs v4 differences and how to adapt existing codebases to v3 constraints.

Quick Start

Practice validating a sample payload with zod v3 to see real-time error messages and inferred types.

Frequently Asked Questions about zod-v3

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

FAQPage Schema
How do I validate API payloads with Zod v3?

Validate form inputs in Zod v3 by defining schemas for expected fields and parsing user submissions. safeParse catches invalid entries and returns structured ZodError messages, allowing you to map validation issues back to specific form fields safely.

What is the difference between Zod v3 and v4?

Zod v3 and v4 differ significantly in their APIs. Zod v4 introduces breaking changes to schema definitions and methods. This reference specifically targets the ^3.x scope, like ^3.24.2, ensuring codebases still using v3 can implement correct runtime validation without migration.

How do I use safeParse for runtime validation in TypeScript?

Use safeParse for TypeScript runtime validation by calling it on a defined Zod schema. Unlike parse, safeParse returns a result object containing either a success property with inferred data or an error property with a detailed ZodError, preventing application crashes.

Can I use z.discriminatedUnion and z.refine together in Zod v3?

Yes, you can use z.discriminatedUnion and z.refine together in Zod v3. Define a discriminated union to handle complex object variants based on a specific field, then apply z.refine to add custom validation rules across the inferred TypeScript types.

Why does my Zod schema throw an error instead of returning validation results?

Your Zod schema throws an error because the parse method throws a ZodError on invalid data. To receive validation results instead, switch to safeParse, which safely returns an object containing the error details without halting execution.

How do I transform data types during validation in Zod v3?

Transform data types during Zod v3 validation by using z.transform or z.coerce. z.coerce attempts automatic type conversion for inputs, while z.transform lets you explicitly modify the parsed output, ensuring the inferred TypeScript type matches the transformed structure.