/zod-4:validating-string-formatsfrom zod-4
Guide to Zod v4 new features including top-level string formats, string transformations, codecs, and stringbool
Ships in zod-4. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Comprehensive guide to new features introduced in Zod v4 that improve developer experience, performance, and type safety.
Zod v4 moved string format validations to top-level functions for 14x faster parsing.
All optimized formats:
z.email() - Email validationz.uuid() - UUID validationz.iso.datetime() - ISO datetimez.url() - URL validationz.ipv4() / z.ipv6() - IP addressesz.jwt() - JWT tokensz.base64() - Base64 stringsz.hash('sha256') - Hash stringsQuick example:
const emailSchema = z.email().trim().toLowerCase();
const uuidSchema = z.uuid();
const datetimeSchema = z.iso.datetime();
With custom error:
const emailSchema = z.email({
error: "Please enter a valid email address"
});
z.string().trim() // Remove whitespace
z.string().toLowerCase() // Convert to lowercase
z.string().toUpperCase() // Convert to uppercase
Chaining:
const emailSchema = z.email().trim().toLowerCase();
Execution order: Transformations execute left-to-right.
Parse string representations of booleans:
const boolSchema = z.stringbool();
boolSchema.parse('true'); // true
boolSchema.parse('false'); // false
boolSchema.parse('1'); // true
boolSchema.parse('0'); // false
Use case: Query parameters and form data
const querySchema = z.object({
active: z.stringbool(),
verified: z.stringbool()
});
Bidirectional transformations for encode/decode:
const dateCodec = z.codec({
decode: z.string().transform(s => new Date(s)),
encode: z.date().transform(d => d.toISOString())
});
const decoded = dateCodec.parse('2024-01-01T00:00:00Z');
const encoded = dateCodec.encode(new Date());
Safe operations:
const result = dateCodec.safeDecode('invalid-date');
if (!result.success) {
console.error(result.error);
}
const arraySchema = z.array(itemSchema);
const items = arraySchema.parse([...]);
const schema = z.object({
id: z.string()
}).passthrough(); // 10-20% faster, keeps extra fields
z.email() // ✅ 14x faster
z.string().email() // ❌ Deprecated
z.email().trim().toLowerCase() // ✅ Declarative
z.stringbool() // ✅ For "true"/"false" strings
z.boolean() // ✅ For actual booleans
z.string().brand<'UserId'>()
z.string().brand<'OrderId'>()
const dateCodec = z.codec({
decode: z.iso.datetime().transform(s => new Date(s)),
encode: z.date().transform(d => d.toISOString())
});
String Formats:
z.email() // ✅ v4
z.string().email() // ❌ v3
Error Customization:
z.string({ error: "Required" }) // ✅ v4
z.string({ message: "Required" }) // ❌ v3
Schema Composition:
schemaA.extend(schemaB.shape) // ✅ v4
schemaA.merge(schemaB) // ❌ v3
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub djankies/claude-configs --plugin zod-49 skills in this plugin
/customizing-errorsHandle Zod validation errors with unified error API, custom messages, error formatting, and user-friendly display/integrating-zod-frameworksIntegrate Zod v4 with React Hook Form, Next.js, Express, tRPC, and other frameworks for type-safe validation/migrating-v3-to-v4Complete migration guide from Zod v3 to v4 covering all breaking changes and upgrade patterns/optimizing-performanceOptimize Zod validation performance with safeParse, bulk array validation, schema reuse, and passthrough patterns