Install any skill in seconds. Free to start, no credit card required.
Get Started Free →This skill provides comprehensive patterns for using Zod validation library in TypeScript applications. It ensures input validation is done correctly, securely, and consistently across the codebase.
.claude/skills/aiskillstore-zod-validation-patterns/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 89% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 62% | 0% |
| case-15 | ✗→✓ | ▲ Improved | 71% | 0% |
| case-20 | ✓→✓ | = Same ✓ | 112% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 118% | 0% |
Use this skill when: Working with user input validation, API request validation, form data validation, or data transformation in Quetrex.
This skill provides comprehensive patterns for using Zod validation library in TypeScript applications. It ensures input validation is done correctly, securely, and consistently across the codebase.
typescriptimport { z } from 'zod' // Define schema const userSchema = z.object({ email: z.string().email(), age: z.number().int().positive(), role: z.enum(['admin', 'user']) }) // Parse data (throws on error) const user = userSchema.parse(data) // Safe parse (returns result object) const result = userSchema.safeParse(data) if (result.success) { console.log(result.data) } else { console.error(result.error) }
typescript// Extract TypeScript type from schema type User = z.infer<typeof userSchema> // { email: string; age: number; role: 'admin' | 'user' }
typescript// src/app/api/users/route.ts import { NextRequest, NextResponse } from 'next/server' import { z } from 'zod' const createUserSchema = z.object({ email: z.string().email(), password: z.string().min(8) }) export async function POST(request: NextRequest) { const body = await request.json() const result = createUserSchema.safeParse(body) if (!result.success) { return NextResponse.json( { error: 'Validation failed', details: result.error.format() }, { status: 400 } ) } // Process validated data const { email, password } = result.data // ... }
safeParse() over parse() for better error handlingcommon-schemas.mdz.infer<typeof schema> for TypeScript typestypescriptconst configSchema = z.object({ timeout: z.number().int().positive().default(30), retries: z.number().int().min(0).default(3), debug: z.boolean().optional() })
typescriptconst addressSchema = z.object({ country: z.string(), state: z.string().optional() }).refine( data => data.country === 'US' ? !!data.state : true, { message: 'State is required for US addresses', path: ['state'] } )
typescriptconst emailSchema = z.string() .trim() .toLowerCase() .email()
typescriptconst eventSchema = z.discriminatedUnion('type', [ z.object({ type: z.literal('click'), x: z.number(), y: z.number() }), z.object({ type: z.literal('keypress'), key: z.string() }) ])
typescriptconst usernameSchema = z.string() .min(3) .max(20) .regex(/^[a-zA-Z0-9_-]+$/) .refine(async (username) => { const existing = await db.user.findUnique({ where: { username } }) return !existing }, { message: 'Username already taken' })
All schemas must work with TypeScript strict mode:
any types@ts-ignore commentsz.inferValidation logic requires comprehensive tests:
typescript'use server' import { z } from 'zod' const createProjectSchema = z.object({ name: z.string().min(1).max(100), description: z.string().optional() }) export async function createProject(formData: FormData) { const result = createProjectSchema.safeParse({ name: formData.get('name'), description: formData.get('description') }) if (!result.success) { return { error: result.error.format() } } // Process validated data return { success: true, data: result.data } }
Start with:
Then explore:
Last updated: 2025-11-23 | Zod v4.1.12
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-20 | pass→pass | 28,325 | 17,368 | -39% | 1 | 1 | 0% | 2,154 | 4,557 | +112% | 0 | 0 | — |
case-01 | fail→pass | 9,968 | 13,533 | +36% | 1 | 1 | 0% | 2,007 | 3,801 | +89% | 0 | 0 | — |
case-02 | fail→pass | 10,762 | 11,938 | +11% | 1 | 1 | 0% | 2,147 | 3,475 | +62% | 0 | 0 | — |
case-03 | pass→pass | 13,855 | 13,446 | -3% | 1 | 1 | 0% | 1,808 | 3,946 | +118% | 0 | 0 | — |
case-04 | pass→pass | 12,316 | 13,528 | +10% | 1 | 1 | 0% | 1,384 | 2,931 | +112% | 0 | 0 | — |
case-05 | pass→pass | 18,534 | 23,409 | +26% | 1 | 1 | 0% | 2,407 | 4,026 | +67% | 0 | 0 | — |
case-06 | fail→fail | 15,084 | 10,757 | -29% | 1 | 1 | 0% | 2,233 | 4,347 | +95% | 0 | 0 | — |
case-07 | pass→pass | 20,141 | 5,391 | -73% | 1 | 1 | 0% | 2,144 | 3,148 | +47% | 0 | 0 | — |
case-08 | pass→pass | 7,081 | 8,328 | +18% | 1 | 1 | 0% | 1,145 | 2,674 | +134% | 0 | 0 | — |
case-09 | pass→pass | 15,779 | 20,645 | +31% | 1 | 1 | 0% | 3,209 | 5,324 | +66% | 0 | 0 | — |
case-10 | pass→pass | 12,347 | 3,738 | -70% | 1 | 1 | 0% | 1,101 | 2,723 | +147% | 0 | 0 | — |
case-11 | pass→pass | 20,337 | 19,298 | -5% | 1 | 1 | 0% | 3,021 | 4,956 | +64% | 0 | 0 | — |
case-12 | pass→pass | 15,884 | 17,129 | +8% | 1 | 1 | 0% | 2,102 | 4,112 | +96% | 0 | 0 | — |
case-13 | pass→pass | 18,021 | 9,512 | -47% | 1 | 1 | 0% | 2,491 | 3,583 | +44% | 0 | 0 | — |
case-14 | pass→pass | 19,322 | 5,770 | -70% | 1 | 1 | 0% | 2,578 | 3,324 | +29% | 0 | 0 | — |
case-15 | fail→pass | 15,963 | 7,964 | -50% | 1 | 1 | 0% | 2,106 | 3,597 | +71% | 0 | 0 | — |
case-16 | pass→pass | 16,180 | 19,605 | +21% | 1 | 1 | 0% | 2,062 | 3,541 | +72% | 0 | 0 | — |
case-17 | pass→pass | 19,780 | 9,095 | -54% | 1 | 1 | 0% | 2,933 | 3,817 | +30% | 0 | 0 | — |
case-18 | pass→pass | 16,149 | 13,578 | -16% | 1 | 1 | 0% | 1,891 | 3,404 | +80% | 0 | 0 | — |
case-19 | pass→pass | 33,977 | 32,515 | -4% | 1 | 1 | 0% | 2,098 | 3,796 | +81% | 0 | 0 | — |
case-21 | pass→pass | 30,781 | 14,390 | -53% | 1 | 1 | 0% | 2,415 | 3,898 | +61% | 0 | 0 | — |
case-22 | pass→pass | 18,322 | 36,396 | +99% | 1 | 1 | 0% | 2,232 | 4,631 | +107% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +14 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.