InnerVault

Zod Schema Validation taste

Indexedprompts.chat (CC0 prompt collection), f

# 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…

Open the source (opens github.com) https://github.com/f/prompts.chat

What it is

Prompts from f.

The problem it solves and who it suits haven't been reviewed by InnerVault. The description above is the source's own.

The prompt

# 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

Written by the prompts.chat (CC0 prompt collection) community (f). Not tested by InnerVault.

How to get it

Setup steps: not applicable.

Related

  1. # Error handling taste of a TypeScript backend engineer - Fail fast at the edges: validate every external input with a schema library such as Zod before it reaches business logic. Confidence: 0.90 - Separate expected…

    Indexed f · via prompts.chat (CC0 prompt collection) CC0-1.0

  2. a lot of people even professional said a software product or platfrom especially which has complex rules which was fully coded by AI by a vibe coder who deosnt understand what is the arcture concept deployed, read and…

    Indexed hussen.sepa@gmail.com · via prompts.chat (CC0 prompt collection) CC0-1.0

  3. code-hacker

    Prompts

    Code Hacker - VS Code Custom Agent + Web + TUI

    Stale hackerlibs · via GitHub 55 ★MITUpdated 20 days ago

    Source for code-hacker (opens github.com) git clone https://github.com/hackerlibs/code-hacker.git
  4. builder prompts which can be sent to builders like cursor, bolt.diy, bolt.new, trae, project idx, Claude code, lovable.dev, llmacoder, geminicoder, windsurf, deepseek-artifact, cline, aider etc

    Stale KingLeoJr · via GitHub 278 ★MITUpdated 2 months ago

    Source for awesome-vibe-coding-prompt-code-templates (opens github.com) git clone https://github.com/KingLeoJr/awesome-vibe-coding-prompt-code-templates.git
  5. Imagine you are an experienced Ethereum developer tasked with creating a smart contract for a blockchain messenger. The objective is to save messages on the blockchain, making them readable (public) to everyone…

    Indexed ameya-2003 · via prompts.chat (CC0 prompt collection) 177.9k ★CC0-1.0

  6. Manim Code

    Prompts

    Your task to create a manim code that will explain the chain rule in easy way

    Indexed industry5designers@gmail.com · via prompts.chat (CC0 prompt collection) CC0-1.0