zod

zod is a cursor rule for Cursor from kerlos/elysia-mcp. It costs 0 tokens per session (8,678 once invoked), scanned A, original, MIT.

A collection of Zod 4 guidance for TypeScript schemas. Zod is a library for describing and checking the shape of data, and these examples cover transformations and combining tagged alternatives.

In plain words
What is it for?
Use it when writing Zod 4 schemas with type-preserving transformations or nested discriminated unions, such as results that can contain several named error cases.
Why use it?
It explains how newer Zod features preserve schema types and allow complex result or error structures to be composed without losing inspection and method chaining.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/kerlos/elysia-mcp/zod
Clone the repo
git clone --depth 1 https://github.com/kerlos/elysia-mcp

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for zod

README.md
[![agentmods](https://agentmods.dev/badge/rules/kerlos/elysia-mcp/zod.svg)](https://agentmods.dev/rules/kerlos/elysia-mcp/zod)
Your own site
<a href="https://agentmods.dev/rules/kerlos/elysia-mcp/zod"><img src="https://agentmods.dev/badge/rules/kerlos/elysia-mcp/zod.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 8,678 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.08678
Opus 5 $0.00000 $0.04339
Sonnet 5 $0.00000 $0.01736
Haiku 4.5 $0.00000 $0.00868

Measured 5d ago against content hash cc58d5fda299, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

zod scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/zod.mdc · 1,075 lines

How it starts

The opening of the file, as written. The whole thing — 1,075 lines — stays where its author put it; the contents beside it link to each section on GitHub.

TITLE: Overwrite Transformations Retaining Schema Type in Zod 4 DESCRIPTION: Introduces the new .overwrite() method in Zod v4, designed for transformations that do not change the inferred type. This method returns an instance of the original schema class, allowing continued method chaining and retaining introspectability. SOURCE: https://zod.dev/v4/v4

LANGUAGE: TypeScript CODE:

z.number().overwrite(val => val ** 2).max(100);
// => ZodNumber

TITLE: Compose Discriminated Unions in Zod 4 DESCRIPTION: Demonstrates the new ability in Zod v4 to use one discriminated union schema (MyErrors) as a member within another discriminated union (MyResult), enabling powerful schema composition patterns. SOURCE: https://zod.dev/v4/v4

LANGUAGE: TypeScript CODE:

const BaseError = z.object({ status: z.literal("failed"), message: z.string() });
const MyErrors = z.discriminatedUnion("code", [
  BaseError.extend({ code: z.literal(400) }),
  BaseError.extend({ code: z.literal(401) }),
  BaseError.extend({ code: z.literal(500) })
]);

const MyResult = z.discriminatedUnion("status", [
  z.object({ status: z.literal("success"), data: z.string() }),
  MyErrors
]);

TITLE: Defining Synchronous Zod-Validated Functions in Zod v4 DESCRIPTION: Demonstrates the new API for defining Zod-validated functions using z.function() in Zod v4. It shows how to define input and output schemas upfront and implement the function logic synchronously using .implement(). SOURCE: https://zod.dev/v4/v4/changelog

LANGUAGE: TypeScript CODE:

const myFunction = z.function({
  input: [z.object({
    name: z.string(),
    age: z.number().int(),
  })],
  output: z.string(),
});

myFunction.implement((input) => {
  return `Hello ${input.name}, you are ${input.age} years old.`;
});

TITLE: Use Top-Level String Format Functions - Zod v4 - JavaScript DESCRIPTION: Lists the various string format validation functions (like email, uuid, url, etc.) that are now available directly as top-level methods on the z module in Zod v4. This change makes them more concise to use and improves tree-shaking. SOURCE: https://zod.dev/v4/v4

LANGUAGE: JavaScript CODE:

z.email();\nz.uuidv4();\nz.uuidv7();\nz.uuidv8();\nz.ipv4();\nz.ipv6();\nz.cidrv4();\nz.cidrv6();\nz.url();\nz.e164();\nz.base64();\nz.base64url();\nz.jwt();\nz.ascii();\nz.utf8();\nz.lowercase();\nz.iso.date();\nz.iso.datetime();\nz.iso.duration();\nz.iso.time();

TITLE: Zod 4: Using .check() in zod/v4-mini DESCRIPTION: Illustrates the use of the new .check() method available in zod/v4-mini, which allows composing multiple validations and transforms (referred to as 'checks') on a schema. SOURCE: https://zod.dev/v4/v4/changelog

LANGUAGE: TypeScript CODE:

import { z } from "zod/v4-mini";

z.string().check(
  z.minLength(10),
  z.maxLength(100),
  z.toLowerCase(),
  z.trim(),
);

TITLE: Customize Required and Invalid Type Errors with Zod 4 DESCRIPTION: Shows how Zod v4 replaces the separate required_error and invalid_type_error parameters with a single error function that receives an issue object, allowing conditional error messages based on the issue type (e.g., invalid_type or required). SOURCE: https://zod.dev/v4/v4

LANGUAGE: TypeScript CODE:

// Zod 3
- z.string({
-   required_error: "This field is required"
-   invalid_type_error: "Not a string",
- });

LANGUAGE: TypeScript CODE:

// Zod 4
+ z.string({ error: (issue) => issue.input === undefined ?
+  "This field is required" :
+  "Not a string"
+ });

TITLE: Customize Errors with Function Syntax in Zod 4 DESCRIPTION: Illustrates how Zod v4 replaces the errorMap function with the unified error function for more complex error customization, allowing access to the issue details to return specific messages based on validation failures like too_small. SOURCE: https://zod.dev/v4/v4

Read the full file on GitHub · 1,075 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 1,075 lines · 0 tokens per session scan A cc58d5fda299

Subscribe to this mod's changes

zod is a cursor rule published in the GitHub repository kerlos/elysia-mcp (47 stars, last pushed 2mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 8,678 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.