Zod Schema Validation Preferences

Zod Schema Validation Preferences

Gives a coding agent a list of preferences for validating data with Zod at trust boundaries, from schema-first types to safeParse, env checks and branded IDs.

Zod Schema Validation taste of a TypeScript developer who trusts nothing from the outside

  • Validate every input that crosses a trust boundary with Zod: request bodies, query strings, env vars, webhooks and third-party API responses. Confidence: 0.95
  • Define the schema first and infer the TypeScript type with z.infer, instead of writing the type and the schema twice. Confidence: 0.90
  • Use safeParse at API boundaries and turn errors into a clean 400 response; use parse only where a failure is truly a bug. Confidence: 0.85
  • Validate environment variables once at startup and exit early with a clear message when something is missing. Confidence: 0.90
  • Keep schemas in a shared module so the client and server use the same contract. Confidence: 0.80
  • Use z.coerce only for query strings and form data, where every value arrives as a string. Confidence: 0.80
  • Prefer z.discriminatedUnion over plain unions for tagged objects; errors are clearer and parsing is faster. Confidence: 0.80
  • Use .strict() on input schemas where unknown keys usually mean a client bug. Confidence: 0.70
  • Keep transforms small and pure; heavy business logic does not belong inside a schema. Confidence: 0.80
  • Put refinements that check more than one field on the object with .superRefine and a clear path. Confidence: 0.75
  • Write error messages for humans in schemas used by forms, and keep the default messages for internal APIs. Confidence: 0.70
  • Use branded types like z.string().uuid().brand<"UserId">() for IDs that must never be mixed up. Confidence: 0.65
  • Do not validate the same data again deep inside the app; parse once at the edge and pass typed values inward. Confidence: 0.85
  • Make dates explicit: accept ISO strings at the boundary and convert to Date objects in one place. Confidence: 0.75
  • Generate OpenAPI or JSON Schema from Zod schemas when the API is public, instead of keeping docs by hand. Confidence: 0.70
  • Avoid z.any() and z.unknown() in public schemas except for fields that are truly free-form. Confidence: 0.80
  • Use .default() for optional settings so the code after parsing never needs undefined checks. Confidence: 0.75
  • Test schemas with both valid and invalid fixtures, especially for edge cases like empty strings and nulls. Confidence: 0.80
  • Log validation failures from third-party APIs with the failing path, because they warn you about silent contract changes. Confidence: 0.80
  • Keep schema names consistent, like CreateUserInput and UserResponse, so the direction of data is clear. Confidence: 0.65

Public domain (CC0 1.0) · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 13,223 prompts

More by @OpenSourceBuffGuy

See all
Shrink-Wrapped Logo Relief prompt image

Shrink-Wrapped Logo Relief

Renders a brand logo wrapped in one layer of shrink wrap so only its relief shows, in a single monochrome color matched to the brand, with staged lighting rules.

image-prompt, gpt-image, placeholders, logo, poster, product-photography, branding, 3d-render, photorealistic, soft-lighting, film-grain, limited-palette, minimalist, text-rendering, mockup, packaging-design, for-designers, for-marketers, graphic-design, structured-output, step-by-step-guide, long-form

Stand-up comedian in a multi-camera club special prompt image

Stand-up comedian in a multi-camera club special

Generates a 15-second stand-up comedy special in five timed camera shots, with scripted jokes about AI and audience laughs that land only after each punchline.

video-prompt, hailuo, comedy, talking-head, timed-beats, multi-shot, camera-movement, lip-sync, cinematic, humorous, guardrails, close-up, wide-shot, medium-shot, character-consistency, photorealistic, scene-transitions, for-filmmakers

Code Review Expert prompt image

Code Review Expert

Makes the AI a senior code reviewer that gives prioritized, actionable feedback on correctness, security, performance and maintainability, explaining why each issue matters.

system-prompt, act-as, code-review, security-review, performance-optimization, clean-code, best-practices, application-security, debugging, expert-advice, for-developers, xml-tags, structured-output, guardrails, step-by-step-guide, critique, report, prioritization, advanced, long-form, coding, objective, empathetic

Reviews

Loading reviews…

Discussion

Loading comments…