Prompt Buddy logoPrompt Buddy

zod · Zod Docs

Zod Defining schemas

Teaches how to create data validation schemas using Zod primitives and coercion methods to represent various data types.

Import to Prompt Buddy

Derived skill

Files assembled from official documentation

Viewing SKILL.md

Zod Defining schemas

Teaches how to create data validation schemas using Zod primitives and coercion methods to represent various data types.

When To Use

Use when you need to define validation rules for primitive types or implement type coercion for incoming data in a TypeScript or JavaScript application.

Reference Files

FileContainsUse For
SKILL.mdEntry point: scope, routing table, and workflow.Start here.
docs/zod-defining-schemas-workflow-guide.mdA guide explaining how to define Zod schemas using primitive types and the coercion mechanism to transform input data.Questions about a guide explaining how to define Zod schemas using primitive types and the coercion mechanism to transform input data.
examples/zod-defining-schemas-zod-defining-primitive-schemas.textA collection of Zod primitive type schema definitions including string, number, bigint, boolean, symbol, undefined, and null.Exact payloads, commands, or snippets shown in A collection of Zod primitive type schema definitions including string, number, bigint, boolean, symbol, undefined, a...
examples/zod-defining-schemas-zod-coerce-examples.textExamples demonstrating the use of z.coerce for converting input types to strings, numbers, booleans, and bigints within Zod schemas.Exact payloads, commands, or snippets shown in Examples demonstrating the use of z.coerce for converting input types to strings, numbers, booleans, and bigints with...
examples/zod-defining-schemas-zod-coerce-string.textA code example demonstrating how to use zod's coerce method to transform various input types into strings.Exact payloads, commands, or snippets shown in A code example demonstrating how to use zod's coerce method to transform various input types into strings.
examples/zod-defining-schemas-zod-coerce-number-definition.textA code example demonstrating the use of z.coerce.number() to define a schema and the resulting input types.Exact payloads, commands, or snippets shown in A code example demonstrating the use of z.coerce.number() to define a schema and the resulting input types.
examples/zod-defining-schemas-zod-literal-definitions.textExamples of defining Zod schemas using the literal method for strings, numbers, bigints, and booleans.Exact payloads, commands, or snippets shown in Examples of defining Zod schemas using the literal method for strings, numbers, bigints, and booleans.
examples/zod-defining-schemas-null-undefined-void-examples.textCode examples demonstrating the usage of z.null(), z.undefined(), and z.void() within Zod schema definitions.Exact payloads, commands, or snippets shown in Code examples demonstrating the usage of z.null(), z.undefined(), and z.void() within Zod schema definitions.
examples/zod-defining-schemas-zod-literal-definition.textA code example demonstrating how to define and validate a schema using the zod literal method.Exact payloads, commands, or snippets shown in A code example demonstrating how to define and validate a schema using the zod literal method.
examples/zod-defining-schemas-enum-values.textAn example demonstrating how to access the values of a Zod enum as a TypeScript set.Exact payloads, commands, or snippets shown in An example demonstrating how to access the values of a Zod enum as a TypeScript set.
examples/zod-defining-schemas-zod-string-validation-methods-examples.textA collection of Zod string validation methods including max, min, length, regex, startsWith, endsWith, includes, uppercase, and lowercase.Exact payloads, commands, or snippets shown in A collection of Zod string validation methods including max, min, length, regex, startsWith, endsWith, includes, uppe...
examples/zod-defining-schemas-zod-string-transformation-methods-examples.textExamples demonstrating string transformation methods in Zod including trim, toLowerCase, toUpperCase, and normalize.Exact payloads, commands, or snippets shown in Examples demonstrating string transformation methods in Zod including trim, toLowerCase, toUpperCase, and normalize.
examples/zod-defining-schemas-zod-api-string-validation-examples.textA collection of Zod string validation methods including email, uuid, url, and ipv4 patterns.Exact payloads, commands, or snippets shown in A collection of Zod string validation methods including email, uuid, url, and ipv4 patterns.
examples/zod-defining-schemas-email-validation.textA text example demonstrating the usage of the z.email() method to define an email validation schema in Zod.Exact payloads, commands, or snippets shown in A text example demonstrating the usage of the z.email() method to define an email validation schema in Zod.
examples/zod-defining-schemas-regex-validation.textA text example demonstrating how to define a Zod schema using a regular expression for email validation.Exact payloads, commands, or snippets shown in A text example demonstrating how to define a Zod schema using a regular expression for email validation.
examples/zod-defining-schemas-zod-email-regex-pattern.textA code example demonstrating how to use the z.email method with a custom regex pattern in Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the z.email method with a custom regex pattern in Zod.
examples/zod-defining-schemas-zod-email-regex-validation-examples.textExamples demonstrating different regex patterns for email validation using the zod email method.Exact payloads, commands, or snippets shown in Examples demonstrating different regex patterns for email validation using the zod email method.
examples/zod-defining-schemas-zod-uuid-definition.textA code example demonstrating how to define a UUID schema using the z.uuid() method in Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a UUID schema using the z.uuid() method in Zod.
examples/zod-defining-schemas-zod-uuid-definitions.textExamples demonstrating how to define UUID schemas for different versions including v4, v6, and v7 using Zod.Exact payloads, commands, or snippets shown in Examples demonstrating how to define UUID schemas for different versions including v4, v6, and v7 using Zod.
examples/zod-defining-schemas-guid.textA text example demonstrating the usage of the z.guid() method to define a schema for GUID strings.Exact payloads, commands, or snippets shown in A text example demonstrating the usage of the z.guid() method to define a schema for GUID strings.
examples/zod-defining-schemas-zod-url-definition.textA code example demonstrating how to define and validate a URL schema using Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to define and validate a URL schema using Zod.
examples/zod-defining-schemas-zod-url-hostname-regex.textA code example demonstrating how to define a Zod URL schema with a custom hostname regular expression validation.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod URL schema with a custom hostname regular expression validation.
examples/zod-defining-schemas-zod-url-definition-2.textA code example demonstrating how to define a Zod URL schema with a specific protocol constraint.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod URL schema with a specific protocol constraint.
examples/zod-defining-schemas-zod-define-url-validation.textA code example demonstrating how to define a Zod schema for validating a URL with specific protocol and hostname constraints.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod schema for validating a URL with specific protocol and hostname cons...
examples/zod-defining-schemas-regex-validation-2.textA text example demonstrating how to define a Zod schema using regular expressions for email and domain validation.Exact payloads, commands, or snippets shown in A text example demonstrating how to define a Zod schema using regular expressions for email and domain validation.
examples/zod-defining-schemas-zod-url-parsing.textA Zod schema example demonstrating how to parse and validate a URL string.Exact payloads, commands, or snippets shown in A Zod schema example demonstrating how to parse and validate a URL string.
examples/zod-defining-schemas-zod-e164-phone-validation.textA code example demonstrating how to define and use the e164 phone number schema in Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to define and use the e164 phone number schema in Zod.
examples/zod-defining-schemas-zod-iso-datetime-validation.textA code example demonstrating the usage and validation rules of the zod iso datetime schema method.Exact payloads, commands, or snippets shown in A code example demonstrating the usage and validation rules of the zod iso datetime schema method.
examples/zod-defining-schemas-zod-iso-datetime-offset-validation.textA code example demonstrating how to define and validate ISO datetime strings with timezone offsets using Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to define and validate ISO datetime strings with timezone offsets using Zod.
examples/zod-defining-schemas-zod-iso-datetime-definition.textA code example demonstrating how to define and parse an ISO datetime schema with optional seconds using Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to define and parse an ISO datetime schema with optional seconds using Zod.
examples/zod-defining-schemas-zod-iso-datetime-validation-2.textExamples demonstrating how to define and validate ISO 8601 datetime schemas with varying precision using Zod.Exact payloads, commands, or snippets shown in Examples demonstrating how to define and validate ISO 8601 datetime schemas with varying precision using Zod.
examples/zod-defining-schemas-zod-iso-date-definition.textA code example demonstrating the usage of z.iso.date() to define and validate ISO 8601 date strings.Exact payloads, commands, or snippets shown in A code example demonstrating the usage of z.iso.date() to define and validate ISO 8601 date strings.
examples/zod-defining-schemas-zod-iso-time-definition.textA code example demonstrating how to define and parse an ISO time schema using Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to define and parse an ISO time schema using Zod.
examples/zod-defining-schemas-time-parsing-limitations.textA text example demonstrating that Zod's time parsing does not support Z suffixes or timezone offsets.Exact payloads, commands, or snippets shown in A text example demonstrating that Zod's time parsing does not support Z suffixes or timezone offsets.
examples/zod-defining-schemas-zod-iso-time-precision-examples.textExamples demonstrating how to use the z.iso.time method with different precision settings in Zod.Exact payloads, commands, or snippets shown in Examples demonstrating how to use the z.iso.time method with different precision settings in Zod.
examples/zod-defining-schemas-zod-ipv4-ipv6-validation-examples.textCode examples demonstrating how to define and validate IPv4 and IPv6 address schemas using Zod.Exact payloads, commands, or snippets shown in Code examples demonstrating how to define and validate IPv4 and IPv6 address schemas using Zod.
examples/zod-defining-schemas-zod-cidrv4-cidrv6-examples.textCode examples demonstrating the usage of zod cidrv4 and cidrv6 schema definitions for validating IP network addresses.Exact payloads, commands, or snippets shown in Code examples demonstrating the usage of zod cidrv4 and cidrv6 schema definitions for validating IP network addresses.
examples/zod-defining-schemas-zod-mac-address-definition.textA code example demonstrating how to define and validate MAC address schemas using Zod, including custom delimiter configurations.Exact payloads, commands, or snippets shown in A code example demonstrating how to define and validate MAC address schemas using Zod, including custom delimiter con...
examples/zod-defining-schemas-zod-jwt-definition.textA text example demonstrating how to define a JWT schema using the z.jwt method in Zod.Exact payloads, commands, or snippets shown in A text example demonstrating how to define a JWT schema using the z.jwt method in Zod.
examples/zod-defining-schemas-zod-hash-definitions.textExamples of defining schema objects using the zod hash method for various hashing algorithms.Exact payloads, commands, or snippets shown in Examples of defining schema objects using the zod hash method for various hashing algorithms.
examples/zod-defining-schemas-zod-hash-definition-examples.textCode examples demonstrating how to define Zod schemas using the hash method with different encoding options.Exact payloads, commands, or snippets shown in Code examples demonstrating how to define Zod schemas using the hash method with different encoding options.
examples/zod-defining-schemas-zod-stringformat-custom-validation.textA code example demonstrating how to use the z.stringFormat method with a custom validation function and a regular expression in Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the z.stringFormat method with a custom validation function and a regular exp...
examples/zod-defining-schemas-parse-error.textAn example demonstrating a ZodError output when a string fails to match a custom format during parsing.Exact payloads, commands, or snippets shown in An example demonstrating a ZodError output when a string fails to match a custom format during parsing.
examples/zod-defining-schemas-zod-template-literal-definition.textA code example demonstrating how to define a schema using the template literal method in Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a schema using the template literal method in Zod.
examples/zod-defining-schemas-zod-template-literal-examples.textCode examples demonstrating the usage of z.templateLiteral for defining complex string patterns in Zod schemas.Exact payloads, commands, or snippets shown in Code examples demonstrating the usage of z.templateLiteral for defining complex string patterns in Zod schemas.
examples/zod-defining-schemas-number-validation.textA code example demonstrating how to define a Zod number schema and validate numeric inputs including edge cases like NaN and Infinity.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod number schema and validate numeric inputs including edge cases like...
examples/zod-defining-schemas-zod-number-validation-constraints.textExamples of Zod number validation methods including greater than, less than, positive, negative, and multiple of constraints.Exact payloads, commands, or snippets shown in Examples of Zod number validation methods including greater than, less than, positive, negative, and multiple of cons...
examples/zod-defining-schemas-zod-nan-validation.textA code example demonstrating how to use z.nan() to validate NaN values using Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to use z.nan() to validate NaN values using Zod.
examples/zod-defining-schemas-integer-validation-examples.textCode examples demonstrating how to use z.int() and z.int32() to restrict schema validation to specific integer ranges.Exact payloads, commands, or snippets shown in Code examples demonstrating how to use z.int() and z.int32() to restrict schema validation to specific integer ranges.
examples/zod-defining-schemas-zod-bigint-definition.textA code example demonstrating how to define a schema for bigint values using the zod library.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a schema for bigint values using the zod library.
examples/zod-defining-schemas-zod-bigint-validation-examples.textExamples demonstrating bigint schema validation methods including greater than, less than, positive, and multiple of constraints.Exact payloads, commands, or snippets shown in Examples demonstrating bigint schema validation methods including greater than, less than, positive, and multiple of...
examples/zod-defining-schemas-boolean-parse.textA text example demonstrating how to define a boolean schema and use the parse method in Zod.Exact payloads, commands, or snippets shown in A text example demonstrating how to define a boolean schema and use the parse method in Zod.
examples/zod-defining-schemas-zod-date-safe-parse.textA code example demonstrating how to use z.date().safeParse() to validate date objects and invalid date strings using Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to use z.date().safeParse() to validate date objects and invalid date strings using...
examples/zod-defining-schemas-zod-date-definition.textA code example demonstrating how to define a Zod date schema with custom error messages for required and invalid date inputs.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod date schema with custom error messages for required and invalid date...
examples/zod-defining-schemas-zod-date-min-max-validation.textA Zod schema demonstrating date validation using min and max constraints with custom error messages.Exact payloads, commands, or snippets shown in A Zod schema demonstrating date validation using min and max constraints with custom error messages.
examples/zod-defining-schemas-zod-enum-definition.textA code example demonstrating how to define and parse a schema using the zod enum method.Exact payloads, commands, or snippets shown in A code example demonstrating how to define and parse a schema using the zod enum method.
examples/zod-defining-schemas-zod-define-enum.textA code example demonstrating how to define a Zod enum schema from a constant array of strings.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod enum schema from a constant array of strings.
examples/zod-defining-schemas-zod-define-enum-2.textA code example demonstrating how to define a Zod enum schema using a constant array and infer the resulting type.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod enum schema using a constant array and infer the resulting type.
examples/zod-defining-schemas-zod-define-enum-3.textA code example demonstrating how to define a Zod enum schema using a constant object.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod enum schema using a constant object.
examples/zod-defining-schemas-enum.textA text example demonstrating how to define and parse an enum schema using Zod.Exact payloads, commands, or snippets shown in A text example demonstrating how to define and parse an enum schema using Zod.
examples/zod-defining-schemas-zod-define-enum-4.textA code example demonstrating how to define a Zod schema using a TypeScript enum.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod schema using a TypeScript enum.
examples/zod-defining-schemas-enum-2.textA code example demonstrating how to define and access an enum schema using Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to define and access an enum schema using Zod.
examples/zod-defining-schemas-enum-exclude.textA code example demonstrating how to define a Zod enum and use the exclude method to create a new schema from it.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod enum and use the exclude method to create a new schema from it.
examples/zod-defining-schemas-zod-define-enum-and-extract.textA code example demonstrating how to define a Zod enum and use the extract method to create a subset of that enum.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod enum and use the extract method to create a subset of that enum.
examples/zod-defining-schemas-zod-stringbool-definition.textA code example demonstrating the usage of the zod stringbool schema method to parse various truthy and falsy string values.Exact payloads, commands, or snippets shown in A code example demonstrating the usage of the zod stringbool schema method to parse various truthy and falsy string v...
examples/zod-defining-schemas-zod-define-boolean-truthy-falsy-defaults.textA code example demonstrating how to define a Zod boolean schema with custom truthy and falsy string values.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod boolean schema with custom truthy and falsy string values.
examples/zod-defining-schemas.textA text-based example demonstrating the syntax for defining schemas using the Zod library.Exact payloads, commands, or snippets shown in A text-based example demonstrating the syntax for defining schemas using the Zod library.
examples/zod-defining-schemas-optional-literal.textA code example demonstrating how to use the z.optional method with a z.literal schema in Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the z.optional method with a z.literal schema in Zod.
examples/zod-defining-schemas-literal-unwrap.textA code example demonstrating how to use the unwrap method on a ZodLiteral type.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the unwrap method on a ZodLiteral type.
examples/zod-defining-schemas-nullable-literal.textA code example demonstrating how to use the nullable method with a literal type in Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the nullable method with a literal type in Zod.
examples/zod-defining-schemas-unwrap-literal.textA code example demonstrating how to use the unwrap method on a nullable Zod schema to retrieve the underlying ZodLiteral.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the unwrap method on a nullable Zod schema to retrieve the underlying ZodLite...
examples/zod-defining-schemas-nullish-literal.textA code example demonstrating the use of the z.nullish method combined with a z.literal schema in Zod.Exact payloads, commands, or snippets shown in A code example demonstrating the use of the z.nullish method combined with a z.literal schema in Zod.
examples/zod-defining-schemas-any-unknown-examples.textCode examples demonstrating the usage of z.any() and z.unknown() for defining permissive schemas in Zod.Exact payloads, commands, or snippets shown in Code examples demonstrating the usage of z.any() and z.unknown() for defining permissive schemas in Zod.
examples/zod-defining-schemas-z-never.textA code example demonstrating the usage of the z.never() method to define a schema that never matches any value.Exact payloads, commands, or snippets shown in A code example demonstrating the usage of the z.never() method to define a schema that never matches any value.
examples/zod-defining-schemas-zod-define-object-typescript.textA TypeScript code example demonstrating how to define a basic object schema using z.object and infer the resulting type.Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to define a basic object schema using z.object and infer the resulting type.
examples/zod-defining-schemas-zod-define-object.textA code example demonstrating how to define a Zod object schema with string and optional number properties and parse a valid object.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod object schema with string and optional number properties and parse a...
examples/zod-defining-schemas-parse-extra-keys.textAn example demonstrating how Zod's parse method handles objects containing keys not defined in the schema.Exact payloads, commands, or snippets shown in An example demonstrating how Zod's parse method handles objects containing keys not defined in the schema.
examples/zod-defining-schemas-zod-strict-object-definition.textA code example demonstrating how to define and use a strict object schema in Zod that throws an error when encountering unknown keys.Exact payloads, commands, or snippets shown in A code example demonstrating how to define and use a strict object schema in Zod that throws an error when encounteri...
examples/zod-defining-schemas-loose-object.textA code example demonstrating how to define a schema using the looseObject method in Zod to allow extra keys.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a schema using the looseObject method in Zod to allow extra keys.
examples/zod-defining-schemas-object-catchall.textA code example demonstrating how to define a Zod object schema with a catchall requirement for additional string properties.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod object schema with a catchall requirement for additional string prop...
examples/zod-defining-schemas-shape-access.textAn example demonstrating how to access individual property schemas from an existing object shape using Zod.Exact payloads, commands, or snippets shown in An example demonstrating how to access individual property schemas from an existing object shape using Zod.
examples/zod-defining-schemas-keyof.textA code example demonstrating the use of the keyof method to derive a schema from the keys of an existing Zod object.Exact payloads, commands, or snippets shown in A code example demonstrating the use of the keyof method to derive a schema from the keys of an existing Zod object.
examples/zod-defining-schemas-zod-extend.textA code example demonstrating how to use the extend method to create a new schema from an existing Zod schema.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the extend method to create a new schema from an existing Zod schema.
examples/zod-defining-schemas-object-extension.textA code example demonstrating how to extend an existing Zod object schema using the shape property.Exact payloads, commands, or snippets shown in A code example demonstrating how to extend an existing Zod object schema using the shape property.
examples/zod-defining-schemas-object-composition.textA code example demonstrating how to define a Zod schema by composing multiple object shapes using the spread operator.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod schema by composing multiple object shapes using the spread operator.
examples/zod-defining-schemas-zod-safeextend-examples.textCode examples demonstrating the usage of the safeExtend method to extend Zod object schemas.Exact payloads, commands, or snippets shown in Code examples demonstrating the usage of the safeExtend method to extend Zod object schemas.
examples/zod-defining-schemas-zod-definition-refinement-extension.textA code example demonstrating how to define a Zod object schema with refinements and extend it using safeExtend.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod object schema with refinements and extend it using safeExtend.
examples/zod-defining-schemas-zod-define-object-2.textA code example demonstrating how to define a Zod object schema with string and array types.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod object schema with string and array types.
examples/zod-defining-schemas-zod-pick-method.textA code example demonstrating how to use the pick method to create a new schema by selecting specific properties from an existing Zod schema.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the pick method to create a new schema by selecting specific properties from...
examples/zod-defining-schemas-zod-omit.textA code example demonstrating how to use the omit method to create a new schema by excluding specific keys from an existing Zod schema.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the omit method to create a new schema by excluding specific keys from an exi...
examples/zod-defining-schemas-zod-partial-method.textA code example demonstrating how to use the partial method to make all properties in a Zod schema optional.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the partial method to make all properties in a Zod schema optional.
examples/zod-defining-schemas-zod-partial-method-2.textA code example demonstrating how to use the partial method to make all properties in a Zod schema optional.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the partial method to make all properties in a Zod schema optional.
examples/zod-defining-schemas-required-method.textA code example demonstrating how to use the required method to make all properties in a Zod schema mandatory.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the required method to make all properties in a Zod schema mandatory.
examples/zod-defining-schemas-required-property.textA code example demonstrating how to use the required method to make specific properties in a Zod schema mandatory.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the required method to make specific properties in a Zod schema mandatory.
examples/zod-defining-schemas-recursive-object.textA code example demonstrating how to define a recursive schema using a getter in Zod to allow an object to contain an array of its own type.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a recursive schema using a getter in Zod to allow an object to contain an...
examples/zod-defining-schemas-object-composition-2.textA code example demonstrating how to define complex Zod schemas using object composition and nested properties.Exact payloads, commands, or snippets shown in A code example demonstrating how to define complex Zod schemas using object composition and nested properties.
examples/zod-defining-schemas-recursive-object-2.textA TypeScript code example demonstrating how to define a recursive schema using a getter in Zod to handle self-referencing object structures.Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to define a recursive schema using a getter in Zod to handle self-referen...
examples/zod-defining-schemas-recursive-object-3.textA code example demonstrating how to define a recursive schema using a getter for self-referencing object properties in Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a recursive schema using a getter for self-referencing object properties i...
examples/zod-defining-schemas-zod-define-array.textA code example demonstrating how to define an array schema using both z.array() and the .array() method in Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to define an array schema using both z.array() and the .array() method in Zod.
examples/zod-defining-schemas-unwrap-string-array.textA code example demonstrating how to use the unwrap method to extract a schema from a Zod array.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the unwrap method to extract a schema from a Zod array.
examples/zod-defining-schemas-array-constraints-examples.textExamples demonstrating how to use min, max, and length constraints when defining array schemas in Zod.Exact payloads, commands, or snippets shown in Examples demonstrating how to use min, max, and length constraints when defining array schemas in Zod.
examples/zod-defining-schemas-tuple.textA code example demonstrating how to define a tuple schema using z.tuple and infer its type using z.infer.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a tuple schema using z.tuple and infer its type using z.infer.
examples/zod-defining-schemas-variadic-tuple.textA code example demonstrating how to define a variadic tuple schema using zod.tuple.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a variadic tuple schema using zod.tuple.
examples/zod-defining-schemas-zod-union-definition.textA code example demonstrating how to define a Zod schema using the union method to allow multiple types.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod schema using the union method to allow multiple types.
examples/zod-defining-schemas-options-property.textA code example demonstrating how to access the options property of a Zod schema to retrieve its constituent types.Exact payloads, commands, or snippets shown in A code example demonstrating how to access the options property of a Zod schema to retrieve its constituent types.
examples/zod-defining-schemas-zod-xor-definition.textA code example demonstrating the usage of the zod xor method to define a schema that requires exactly one of the provided types to match.Exact payloads, commands, or snippets shown in A code example demonstrating the usage of the zod xor method to define a schema that requires exactly one of the prov...
examples/zod-defining-schemas-zod-define-xor-validation.textA code example demonstrating how to use the z.xor method in Zod to ensure exactly one schema in a union matches the input.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the z.xor method in Zod to ensure exactly one schema in a union matches the i...
examples/zod-defining-schemas-zod-xor-definition-2.textA code example demonstrating the use of the z.xor method to define a schema that requires exactly one of the provided types to match.Exact payloads, commands, or snippets shown in A code example demonstrating the use of the z.xor method to define a schema that requires exactly one of the provided...
examples/zod-defining-schemas-typescript-discriminated-union.textA TypeScript code example demonstrating how to define a discriminated union schema using Zod.Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to define a discriminated union schema using Zod.
examples/zod-defining-schemas-zod-discriminated-union-definition.textA code example demonstrating how to define a discriminated union schema using z.discriminatedUnion in Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a discriminated union schema using z.discriminatedUnion in Zod.
examples/zod-defining-schemas-zod-union-intersection-examples.textCode examples demonstrating how to define Zod schemas using union and intersection operations.Exact payloads, commands, or snippets shown in Code examples demonstrating how to define Zod schemas using union and intersection operations.
examples/zod-defining-schemas-zod-intersection.textA code example demonstrating how to create a new schema by intersecting two existing Zod object schemas.Exact payloads, commands, or snippets shown in A code example demonstrating how to create a new schema by intersecting two existing Zod object schemas.
examples/zod-defining-schemas-zod-define-record.textA code example demonstrating how to define a Zod record schema using z.record with string keys and values.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod record schema using z.record with string keys and values.
examples/zod-defining-schemas-union-and-record.textA code example demonstrating how to define Zod schemas using z.union and z.record to create complex object structures.Exact payloads, commands, or snippets shown in A code example demonstrating how to define Zod schemas using z.union and z.record to create complex object structures.
examples/zod-defining-schemas-enum-and-record.textA code example demonstrating how to define a schema using z.enum and z.record to create a typed object with specific keys.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a schema using z.enum and z.record to create a typed object with specific...
examples/zod-defining-schemas-zod-record-definition.textA code example demonstrating how to define and validate a Zod record schema with numeric keys and string values.Exact payloads, commands, or snippets shown in A code example demonstrating how to define and validate a Zod record schema with numeric keys and string values.
examples/zod-defining-schemas-record.textA code example demonstrating how to define a Zod schema for a record type with specific keys.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod schema for a record type with specific keys.
examples/zod-defining-schemas-enum-partial-record.textA code example demonstrating how to use z.enum and z.partialRecord to define a schema with specific keys and optional string values.Exact payloads, commands, or snippets shown in A code example demonstrating how to use z.enum and z.partialRecord to define a schema with specific keys and optional...
examples/zod-defining-schemas-object-and-loose-record.textA code example demonstrating how to define a Zod schema using object composition with the .and() method and loose records.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod schema using object composition with the .and() method and loose rec...
examples/zod-defining-schemas-zod-map-definition.textA code example demonstrating how to define a schema for a Map object using z.map() in Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a schema for a Map object using z.map() in Zod.
examples/zod-defining-schemas-zod-set-definition-typescript.textA TypeScript code example demonstrating how to define and parse a schema for a Set of numbers using Zod.Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to define and parse a schema for a Set of numbers using Zod.
examples/zod-defining-schemas-string-constraints.textA text example demonstrating how to use min, max, and size constraints on a Zod string schema.Exact payloads, commands, or snippets shown in A text example demonstrating how to use min, max, and size constraints on a Zod string schema.
examples/zod-defining-schemas-zod-definition.textA code example demonstrating how to define a Zod schema for file validation including size and MIME type constraints.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod schema for file validation including size and MIME type constraints.
examples/zod-defining-schemas-zod-instanceof-class.textA code example demonstrating how to use z.instanceof() to define a schema for a specific class.Exact payloads, commands, or snippets shown in A code example demonstrating how to use z.instanceof() to define a schema for a specific class.
examples/zod-defining-schemas-instanceof-url-validation.textA code example demonstrating how to use z.instanceof() with a custom check to validate that a URL object uses the HTTPS protocol.Exact payloads, commands, or snippets shown in A code example demonstrating how to use z.instanceof() with a custom check to validate that a URL object uses the HTT...
examples/zod-defining-schemas-zod-definition-string-refinement.textA code example demonstrating how to define a Zod schema for a string with custom length refinements using the check method.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a Zod schema for a string with custom length refinements using the check m...
examples/zod-defining-schemas-zod-define-refine-string-length.textA code example demonstrating how to use the refine method to enforce a maximum string length in a Zod schema.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the refine method to enforce a maximum string length in a Zod schema.
examples/zod-defining-schemas-zod-define-refine-validation.textA code example demonstrating how to use the refine method in Zod to implement custom validation logic for a string schema.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the refine method in Zod to implement custom validation logic for a string sc...
examples/zod-defining-schemas-zod-string-refine-validation.textA code example demonstrating how to use the refine method in Zod to apply custom validation rules to a string schema.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the refine method in Zod to apply custom validation rules to a string schema.
examples/zod-defining-schemas-zod-string-refine-validation-2.textA code example demonstrating how to use the refine method on a Zod string schema to implement custom validation rules.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the refine method on a Zod string schema to implement custom validation rules.
examples/zod-defining-schemas-zod-object-refine-password-validation.textA Zod schema example demonstrating how to use the refine method to validate that two password fields match.Exact payloads, commands, or snippets shown in A Zod schema example demonstrating how to use the refine method to validate that two password fields match.
examples/zod-defining-schemas-safe-parse-validation-error.textA text example demonstrating how zod's safeParse method returns validation error issues when schema constraints are not met.Exact payloads, commands, or snippets shown in A text example demonstrating how zod's safeParse method returns validation error issues when schema constraints are n...
examples/zod-defining-schemas-zod-string-refine-async-validation.textAn example demonstrating how to use the refine method with an asynchronous function to perform custom validation on a Zod string schema.Exact payloads, commands, or snippets shown in An example demonstrating how to use the refine method with an asynchronous function to perform custom validation on a...
examples/zod-defining-schemas-zod-parseasync-definition.textA code example demonstrating the use of the parseAsync method to validate a schema in Zod.Exact payloads, commands, or snippets shown in A code example demonstrating the use of the parseAsync method to validate a schema in Zod.
examples/zod-defining-schemas-zod-string-refine-validation-3.textA code example demonstrating how to use the refine method on a Zod string schema to implement custom validation logic.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the refine method on a Zod string schema to implement custom validation logic.
examples/zod-defining-schemas-zod-define-with-refine-validation.textA Zod schema definition using the refine method to validate that two password fields match.Exact payloads, commands, or snippets shown in A Zod schema definition using the refine method to validate that two password fields match.
examples/zod-defining-schemas-zod-object-refine-password-match.textA Zod schema implementation using the refine method to validate that two password fields are identical.Exact payloads, commands, or snippets shown in A Zod schema implementation using the refine method to validate that two password fields are identical.
examples/zod-defining-schemas-zod-array-superrefine-unique-string.textA Zod schema implementation using superRefine to enforce a maximum array length and ensure all string elements are unique.Exact payloads, commands, or snippets shown in A Zod schema implementation using superRefine to enforce a maximum array length and ensure all string elements are un...
examples/zod-defining-schemas-zod-define-codec.textA code example demonstrating how to use the z.codec method to transform an ISO date string into a Date object within a Zod schema.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the z.codec method to transform an ISO date string into a Date object within...
examples/zod-defining-schemas-zod-string-to-date-parsing.textA code example demonstrating how to use Zod to parse an ISO string into a JavaScript Date object.Exact payloads, commands, or snippets shown in A code example demonstrating how to use Zod to parse an ISO string into a JavaScript Date object.
examples/zod-defining-schemas-zod-api-string-to-date-decode.textA code example demonstrating how to use Zod to decode a date string into a JavaScript Date object.Exact payloads, commands, or snippets shown in A code example demonstrating how to use Zod to decode a date string into a JavaScript Date object.
examples/zod-defining-schemas-zod-define-encode.textA code example demonstrating the use of the z.encode method to transform a string into a Date object within a Zod schema.Exact payloads, commands, or snippets shown in A code example demonstrating the use of the z.encode method to transform a string into a Date object within a Zod sch...
examples/zod-defining-schemas-zod-invert-codec-date-string.textA code example demonstrating the use of z.invertCodec to transform between Date objects and ISO strings.Exact payloads, commands, or snippets shown in A code example demonstrating the use of z.invertCodec to transform between Date objects and ISO strings.
examples/zod-defining-schemas-zod-string-pipe-transform-length.textA code example demonstrating how to use the pipe method to transform a Zod string schema into its length value.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the pipe method to transform a Zod string schema into its length value.
examples/zod-defining-schemas-zod-transform.textA code example demonstrating how to use the z.transform method to cast various input types to a string.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the z.transform method to cast various input types to a string.
examples/zod-defining-schemas-zod-transform-custom-error-handling.textA code example demonstrating how to use z.transform to parse integers and manually push custom issues to the context.Exact payloads, commands, or snippets shown in A code example demonstrating how to use z.transform to parse integers and manually push custom issues to the context.
examples/zod-defining-schemas-zod-define-transform-string-to-length.textA Zod schema example demonstrating how to use the transform method to convert a string into its character length.Exact payloads, commands, or snippets shown in A Zod schema example demonstrating how to use the transform method to convert a string into its character length.
examples/zod-defining-schemas-zod-string-transform-async.textA Zod schema example demonstrating how to use the transform method to perform an asynchronous database lookup from a string input.Exact payloads, commands, or snippets shown in A Zod schema example demonstrating how to use the transform method to perform an asynchronous database lookup from a...
examples/zod-defining-schemas-zod-preprocess-integer-coercion.textA code example demonstrating how to use z.preprocess to convert string inputs into integers within a Zod schema.Exact payloads, commands, or snippets shown in A code example demonstrating how to use z.preprocess to convert string inputs into integers within a Zod schema.
examples/zod-defining-schemas-zod-preprocess-string-trim.textA code example demonstrating how to use z.preprocess to trim string values and handle null or undefined inputs in a Zod schema.Exact payloads, commands, or snippets shown in A code example demonstrating how to use z.preprocess to trim string values and handle null or undefined inputs in a Z...
examples/zod-defining-schemas-zod-define-default-value.textA code example demonstrating how to use the .default() method to assign a fallback value to a Zod schema when parsing undefined input.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the .default() method to assign a fallback value to a Zod schema when parsing...
examples/zod-defining-schemas-zod-define-with-default-value.textA code example demonstrating how to use the .default() method in Zod to assign a dynamic value to a schema when the input is undefined.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the .default() method in Zod to assign a dynamic value to a schema when the i...
examples/zod-defining-schemas-string-transform-default.textA code example demonstrating how to use the transform and default methods to process a string schema in Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the transform and default methods to process a string schema in Zod.
examples/zod-defining-schemas-zod-string-transform-prefault.textA Zod schema demonstrating the use of string transformation and the prefault method to handle undefined input.Exact payloads, commands, or snippets shown in A Zod schema demonstrating the use of string transformation and the prefault method to handle undefined input.
examples/zod-defining-schemas-string-transformations.textA code example demonstrating Zod string transformations using trim, toUpperCase, and default values.Exact payloads, commands, or snippets shown in A code example demonstrating Zod string transformations using trim, toUpperCase, and default values.
examples/zod-defining-schemas-zod-number-catch.textA code example demonstrating how to use the catch method in Zod to provide a fallback value when number parsing fails.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the catch method in Zod to provide a fallback value when number parsing fails.
examples/zod-defining-schemas-zod-number-catch-error-handling.textA code example demonstrating how to use the catch method on a Zod number schema to provide a fallback value when parsing fails.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the catch method on a Zod number schema to provide a fallback value when pars...
examples/zod-defining-schemas-type-inference.textA text example demonstrating how Zod schemas can be used to infer TypeScript types for object definitions.Exact payloads, commands, or snippets shown in A text example demonstrating how Zod schemas can be used to infer TypeScript types for object definitions.
examples/zod-defining-schemas-zod-branding.textA code example demonstrating how to use the brand method in Zod to create branded types for enhanced type safety.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the brand method in Zod to create branded types for enhanced type safety.
examples/zod-defining-schemas-branding.textA code example demonstrating how to use the brand method in Zod to create branded types for schema validation.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the brand method in Zod to create branded types for schema validation.
examples/zod-defining-schemas-branding-2.textA code example demonstrating how to use the brand method in Zod to create branded types for string validation.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the brand method in Zod to create branded types for string validation.
examples/zod-defining-schemas-zod-branding-string-examples.textCode examples demonstrating how to use the brand method in Zod to create branded string schemas for input, output, or both.Exact payloads, commands, or snippets shown in Code examples demonstrating how to use the brand method in Zod to create branded string schemas for input, output, or...
examples/zod-defining-schemas-zod-readonly-object-definition.textA code example demonstrating how to use the readonly method to create a read-only object schema in Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the readonly method to create a read-only object schema in Zod.
examples/zod-defining-schemas-readonly-examples.textCode examples demonstrating how to use the readonly method to create immutable object, array, tuple, map, and set schemas in Zod.Exact payloads, commands, or snippets shown in Code examples demonstrating how to use the readonly method to create immutable object, array, tuple, map, and set sch...
examples/zod-defining-schemas-readonly-parse.textA code example demonstrating how Zod's parse method enforces read-only properties on a schema object.Exact payloads, commands, or snippets shown in A code example demonstrating how Zod's parse method enforces read-only properties on a schema object.
examples/zod-defining-schemas-json.textA text example demonstrating how to define a JSON schema using the Zod library.Exact payloads, commands, or snippets shown in A text example demonstrating how to define a JSON schema using the Zod library.
examples/zod-defining-schemas-lazy-recursive-json.textA recursive Zod schema definition using z.lazy to represent a JSON structure containing strings, numbers, booleans, nulls, arrays, and records.Exact payloads, commands, or snippets shown in A recursive Zod schema definition using z.lazy to represent a JSON structure containing strings, numbers, booleans, n...
examples/zod-defining-schemas-zod-define-function.textA code example demonstrating how to use z.function() to define input parameters and return types in Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to use z.function() to define input parameters and return types in Zod.
examples/zod-defining-schemas-typescript-implementation.textA TypeScript code example demonstrating how to implement a function using Zod for type inference and schema definition.Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to implement a function using Zod for type inference and schema definition.
examples/zod-defining-schemas-error-handling.textA text example demonstrating how Zod throws a ZodError when a schema validation fails.Exact payloads, commands, or snippets shown in A text example demonstrating how Zod throws a ZodError when a schema validation fails.
examples/zod-defining-schemas-zod-define-function-2.textA code example demonstrating how to define a function schema using z.function() in Zod.Exact payloads, commands, or snippets shown in A code example demonstrating how to define a function schema using z.function() in Zod.
examples/zod-defining-schemas-2.textA code example demonstrating how to define schemas using the Zod library.Exact payloads, commands, or snippets shown in A code example demonstrating how to define schemas using the Zod library.
examples/zod-defining-schemas-zod-custom-decimal.textA code example demonstrating how to use z.custom to define a Zod schema for decimal.js Decimal objects.Exact payloads, commands, or snippets shown in A code example demonstrating how to use z.custom to define a Zod schema for decimal.js Decimal objects.
examples/zod-defining-schemas-zod-custom-type-definition.textA code example demonstrating how to use z.custom to define a schema with a custom type argument without validation.Exact payloads, commands, or snippets shown in A code example demonstrating how to use z.custom to define a schema with a custom type argument without validation.
examples/zod-defining-schemas-zod-custom-validation.textA code example demonstrating how to use the z.custom method to define a schema with a custom validation function and error message.Exact payloads, commands, or snippets shown in A code example demonstrating how to use the z.custom method to define a schema with a custom validation function and...
examples/zod-defining-schemas-typescript-custom-number-checks.textA TypeScript example demonstrating how to extend Zod number schemas using a generic function to apply common constraints like min and max.Exact payloads, commands, or snippets shown in A TypeScript example demonstrating how to extend Zod number schemas using a generic function to apply common constrai...

What This Skill Covers

  • To validate data, you must first define a schema . Schemas represent types , from simple primitive values to complex nested objects and arrays.
  • Main sections: Primitives, Coercion, How coercion works in Zod, Customizing the input type, Literals.

Workflow

  1. Open the most relevant file under docs/ for the exact documented workflow and wording.
  2. Open schemas/ files for exact structured contracts.
  3. Open examples/ files for concrete requests, commands, snippets, and manifests.
  4. Do not add behavior or configuration that is not present in the attached source files.

Canonical source: https://zod.dev/api