zod-boundary-and-patch
Skill0 starsChanged 25 days agoMITView on GitHub
Validate at every boundary with Zod the right way — and never let a PATCH erase fields. Use when asked to "validate with Zod", "add a PATCH endpoint", "write the update schema", "parse the request body", or "migrate Zod v3 to v4". Encodes turbo's S-02 scenario + O-04 opinion + P-04/P-05 pitfalls — the 🔴 silent-data-loss class on partial updates.
In this repository33 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- llms.txtllms.txt
- agent-runtimeSkill
- frontend-designSkill
- architectSkill
- deep-thinkSkill
- design-systemsSkill
- ecosystem-referenceSkill
- fractal-delegationSkill
- harness-reviewSkill
- heartbeatSkill
- integrate-resourcesSkill
- llm-council-critiqueSkill
- loop-createSkill
- mcp-setupSkill
- memory-compressionSkill
- memorySkill
- model-routingSkill
- oss-project-scaffoldSkill
- playwright-cliSkill
- repo-scoutSkill
- self-improveSkill
- skill-creatorSkill
- skill-routingSkill
- sprintSkill
- test-visualSkill
- troubleshootSkill
- ux-auditSkill
- audit-serverless-stateSkill
- design-api-contractSkill
- scaffold-hono-serviceSkill
- sse-streaming-safelySkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 19
Parse, don't validate, at every boundary: Every route handler parses its input with Zod and returns a typed value (the energy law: Zod at …
- Very specific: line 45
if migrating: a checklist of the four P-05 breaks fixed, with the UUID-audit flag if z.uuid() is now strict
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
zod-boundary-and-patch
Encodes scenario S-02 (the PATCH that erased fields), opinion O-04 (always a dedicated no-default PATCH schema; always bind validators through Standard Schema), and pitfalls P-04 (Zod
.default()data loss on PATCH) + P-05 (the four mechanical Zod v3→v4 migration breaks). The 🔴 bug: reusing a create-schema to validate a PATCH silently overwrites omitted fields with their defaults.
Trigger
Invoke when the user (or a coding agent) asks to:
- "validate with Zod" / "parse the request body" / "add Zod at the boundary"
- "add a PATCH / update endpoint" / "write the update schema"
- "migrate Zod v3 → v4" / "we bumped Zod and things broke"
Steps
- Parse, don't validate, at every boundary. Every route handler parses its input with Zod and returns a typed value (the energy law: Zod at every boundary, no
any). The parsed object — not the raw body — flows downstream. - The PATCH rule (the load-bearing one). A PATCH/partial-update endpoint MUST use a dedicated schema with NO
.default()s — never the create-schema. In Zod 4,.default()fires onundefinedunconditionally, even under.partial()— soCreateSchema.partial()still resets every omitted defaulted field on save. Build the PATCH schema from a no-default base (or hand-author a distinct partial schema). The create schema keeps its defaults; the update schema has none.// create: defaults are correct here const CreatePet = z.object({ name: z.string(), status: z.enum([...]).default("available") }); // update: a DISTINCT schema, NO .default() — omitted fields stay unchanged const UpdatePet = z.object({ name: z.string().optional(), status: z.enum([...]).optional() }); - Verify with the detector (this guard is in the acceptance path itself):
Expect zero P-04 — the create-schema and patch-schema must be distinct objects and the patch schema must have noturbo audit <service-dir> --json.default(). - Prove the behavior: send a
PATCHomitting a defaulted field; assert the stored value is UNCHANGED (not reset to the default). - Bind through Standard Schema (O-04 second half). Use
@hono/standard-validatoragainst the~standardinterface so a Zod→Valibot swap is a package change with no route-code change — keep the validator choice open for when bundle size becomes binding. (Escape hatch: use the Zod-specific@hono/zod-validatorwhen you want Zod's richer ergonomics and don't need swappability;zod/miniONLY where edge bundle size is measured-critical.) - If migrating v3→v4 (P-05), fix the four mechanical breaks:
z.coerce.number()input type is nowunknown→ tighten the upstream type or acceptunknown(the new TS errors are correct).z.string().email()/.url()/.uuid()→z.email()/z.url()/z.uuid();z.uuid()is RFC-9562 strict and rejects non-canonical UUIDs v3 accepted → usez.guid()for permissive matching, and audit stored "UUIDs" that aren't canonical.message/invalid_type_error/required_error/errorMapcollapsed into oneerrorparam; usez.prettifyError()for display..merge()removed →.extend()or{ ...A.shape, ...B.shape }; ensurezod-validation-error ≥ v5.0.0.
Output
- the distinct create-schema vs patch-schema (patch has no
.default()) turbo auditP-04 count (must be 0)- the PATCH-omits-defaulted-field behavior result (value unchanged)
- if migrating: a checklist of the four P-05 breaks fixed, with the UUID-audit flag if
z.uuid()is now strict - the boundary note: validator bound via Standard Schema (swappable) unless Zod-specific ergonomics were deliberately chosen
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

