Agent skill
Zod Schema Management
Create and modify Zod schemas for runtime validation with proper type inference.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/zod-carrot-foundation-methodology-rules-2
SKILL.md
-
Define schemas with specificity: Prefer concrete schema methods over loose ones.
- Use
z.string().min(1)instead of barez.string()for required non-empty strings - Use
z.number().int().nonnegative()instead of barez.number()when appropriate - Use
z.enum()for known string unions - Use
z.literal()for exact values
- Use
-
Derive types from schemas: Always use
z.infer<typeof Schema>to derive TypeScript types from Zod schemas. Do not define the type separately and the schema separately — the schema is the source of truth.typescriptconst MySchema = z.object({ name: z.string().min(1), count: z.number().int().nonnegative(), }); type My = z.infer<typeof MySchema>; -
Choose the right parse method:
.safeParse()for external or untrusted input (API payloads, user input, parsed documents) — check.successbefore using.data.parse()for internal guaranteed data where a thrown error indicates a programming bug
-
Colocate schema with type: Place the Zod schema in the same file as the type it defines. Export both the schema and the inferred type.
-
Test stubs: Use
zockerwithcreateStubFromSchema()from@carrot-fndn/shared/testingto generate test data from schemas. This ensures stubs always match the schema definition. -
Schema composition: Use
.extend(),.merge(),.pick(),.omit(), and.partial()to compose schemas from existing ones rather than duplicating field definitions. -
Optional fields: Use
z.optional()or.optional()for truly optional fields. Remember thatexactOptionalPropertyTypesis enabled in tsconfig, so optional fields must be explicitly marked.
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?