Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Zod · Module

.shape

.shape exposes the individual field schemas inside a Zod object schema. Use it to retrieve a validator for a specific key, such as Dog.shape.name.

How it works

For a Zod object schema, .shape exposes the schema assigned to each declared key. Access a property such as Dog.shape.name to retrieve that field's validator and use it independently or inspect its definition.

Syntax

objectSchema.shape.key

Returns

The schema associated with the selected object key.

Key points

  • Use .shape on a Zod object schema when you need the validators for its individual fields.
  • Dog.shape.name returns the string schema declared for the name property.
  • Dog.shape.age returns the number schema declared for the age property.
  • The feature applies to object schemas created with Zod's object-schema constructor.

Common mistakes

  • Accessing .shape returns schemas, not parsed values or the object's runtime data.

Example: .shape example

import { z } from "zod";

const Dog = z.object({
  name: z.string(),
  age: z.number(),
});

const nameSchema = Dog.shape.name;
const ageSchema = Dog.shape.age;

console.log(nameSchema.parse("Rex"));
console.log(ageSchema.parse(4));

The shape exposes each field's schema, which can then be inspected or used independently for validation.

When to use it

Field-level validation

Validate one property independently without parsing the complete object.

Schema inspection and reuse

Inspect or reuse a field validator while building related schemas.

Interview questions

QWhat does .shape do on a Zod object schema?

The .shape property provides access to the individual schemas inside a Zod object schema. For example, Dog.shape.name returns the schema used to validate the name field.

Follow-up: How would you validate only the name field? Retrieve Dog.shape.name and call its parse or safeParse method with the candidate value.

QWhat is returned by Dog.shape.age?

It lets code address a field schema by its key, such as Dog.shape.age. The result is a Zod schema for that field rather than the field's value.

Follow-up: What happens if the key is not declared in the object shape? TypeScript generally reports an invalid property access, while dynamically computed keys require appropriate type handling.

QWhy might you use .shape instead of validating the whole object?

A field schema obtained through .shape can be reused for focused validation or further schema operations. The documentation illustrates accessing the internal schemas for named object fields.

Follow-up: How could this support schema composition? Use the retrieved field schema as an input to another Zod schema or composition method, depending on the desired structure.

  • z.object
  • z.string
  • z.number
  • parse
  • safeParse

Source: Defining schemas | Zod. Checked 2026-10-15.