Agent skill
Zod Validation
Input validation patterns with Zod in LivestockAI server functions
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/zod-validation-captjay98-gemini-livestockai
SKILL.md
Zod Validation
LivestockAI uses Zod for runtime input validation in server functions.
Server Function Validation
ALWAYS use Zod validators, not identity functions:
import { createServerFn } from '@tanstack/react-start'
import { z } from 'zod'
// ✅ Correct - Zod validation
export const createBatchFn = createServerFn({ method: 'POST' })
.inputValidator(
z.object({
farmId: z.string().uuid(),
species: z.string().min(1).max(100),
quantity: z.number().int().positive(),
}),
)
.handler(async ({ data }) => {
// data is fully typed and validated
})
// ❌ Wrong - No validation
.inputValidator((data: { farmId: string }) => data)
Common Patterns
UUIDs
farmId: z.string().uuid()
farmId: z.string().uuid().optional()
Enums
status: z.enum(['active', 'depleted', 'sold'])
livestockType: z.enum(['poultry', 'fish', 'cattle', 'goats', 'sheep', 'bees'])
Numbers
page: z.number().int().positive()
quantity: z.number().int().positive()
amount: z.number().nonnegative()
percentage: z.number().min(0).max(100)
Dates
date: z.coerce.date()
targetDate: z.coerce.date().optional()
Strings
name: z.string().min(1).max(100)
email: z.string().email()
notes: z.string().max(500).nullish()
Nullable/Optional
// Optional (can be undefined)
notes: z.string().optional()
// Nullable (can be null)
notes: z.string().nullable()
// Both (can be undefined or null)
notes: z.string().nullish()
Complete Schema Example
const createBatchSchema = z.object({
farmId: z.string().uuid(),
livestockType: z.enum([
'poultry',
'fish',
'cattle',
'goats',
'sheep',
'bees',
]),
species: z.string().min(1).max(100),
breedId: z.string().uuid().nullish(),
initialQuantity: z.number().int().positive(),
acquisitionDate: z.coerce.date(),
costPerUnit: z.number().nonnegative(),
batchName: z.string().max(100).nullish(),
targetHarvestDate: z.coerce.date().nullish(),
notes: z.string().max(500).nullish(),
})
Pagination Schema
const paginatedQuerySchema = z.object({
page: z.number().int().positive().optional().default(1),
pageSize: z.number().int().positive().max(100).optional().default(10),
sortBy: z.string().optional(),
sortOrder: z.enum(['asc', 'desc']).optional(),
search: z.string().optional(),
})
Related Skills
tanstack-start- Server function patternserror-handling- Validation error handling
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?