Last Updated: 3/12/2026
Metadata
Attach custom metadata to schemas for documentation, code generation, or runtime introspection.
Descriptions
Add human-readable descriptions:
import * as z from "zod";
const User = z.object({
email: z.string().email().describe("User's primary email address"),
age: z.number().int().describe("Age in years"),
});
const emailSchema = User.shape.email;
emailSchema.description; // "User's primary email address"Custom Metadata
Store arbitrary metadata using the global registry:
const Password = z.string()
.min(8)
.meta({
label: "Password",
placeholder: "Enter your password",
sensitive: true,
});
const metadata = Password.meta();
// { label: "Password", placeholder: "...", sensitive: true }Use Cases
Metadata is useful for:
- Form generation (labels, placeholders, help text)
- API documentation (descriptions, examples)
- Code generation (hints for code generators)
- Custom tooling (schema introspection)
Accessing Metadata
schema.description; // Get description
schema.meta(); // Get all metadata
schema.meta(data); // Set metadata (returns new instance)What’s Next
- JSON Schema — Export schemas with descriptions
- Defining Schemas — Learn schema basics