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

Prisma · Function

Prisma.validator

Prisma.validator checks an object against a generated Prisma type and returns the type-safe object. It is commonly used to build reusable, schema-aware query parameters.

How it works

Prisma.validator is a type-level helper that receives a generated Prisma type and returns an object checked against that type. The resulting object can be reused as query arguments, such as a model selection, while preserving the generated field constraints.

Syntax

Prisma.validator<GeneratedType>({ args });

Parameters

NameTypeDescription
GeneratedTypegenerated Prisma typeGenerated Prisma type that constrains the object, such as Prisma.UserSelect.
argsobjectObject whose properties are checked against the generated type.

Returns

A type-safe object conforming to the supplied generated Prisma type.

Key points

  • It accepts a generated Prisma type and produces an object checked for type safety.
  • The resulting object follows the model fields represented by the generated type.
  • It is useful for defining reusable query parameters tied to schema models.
  • One documented approach supplies generated Prisma Client types through a generic parameter.
  • A second documented approach uses a selector associated with an existing Prisma Client instance.

Common mistakes

  • It is available only with the legacy prisma-client-js generator.
  • Projects using the new prisma-client generator cannot use this API.
  • Prefer TypeScript's satisfies operator when it provides the needed type-checking.

Example: Reusable UserSelect object

import { Prisma } from "@prisma/client";

const userEmail = Prisma.validator<Prisma.UserSelect>()({
  email: true,
});

// Use with a Prisma Client query:
const user = await prisma.user.findUnique({
  where: { id: 1 },
  select: userEmail,
});

Creates a reusable, type-checked selection object and passes it to a Prisma Client query.

When to use it

Reusable field selections

Define a reusable UserSelect object for multiple Prisma Client queries.

Payload type preparation

Create typed include or select arguments before deriving a payload type.

Schema-aligned query parameters

Validate query argument objects against generated model-specific types.

Interview questions

QWhat does Prisma.validator do?

Prisma.validator takes a generated Prisma type and checks an object against that type. For example, Prisma.validator<Prisma.UserSelect>()({ email: true }) creates a reusable, type-safe selection object.

Follow-up: How would you avoid this helper in modern TypeScript? Use the native satisfies operator to check an object against the generated Prisma type, when suitable.

QWhy use Prisma.validator?

It can define reusable query parameters while ensuring that selected or included fields match the generated model types. The returned object can then be supplied to a Prisma Client query.

Follow-up: What is another documented usage style? A selector can be created from an existing Prisma Client instance, rather than only from a generated type.

QWhat is its basic syntax?

The documented generic form is Prisma.validator<GeneratedType>({ args });, where GeneratedType is a generated Prisma type and args is the object being checked. A common example uses Prisma.UserSelect.

Follow-up: What limitation affects generator choice? The API is unavailable with the new prisma-client generator and is limited to prisma-client-js.

  • Prisma.UserSelect
  • Prisma.UserDefaultArgs
  • Prisma.UserGetPayload
  • TypeScript satisfies operator

Source: Prisma validator (Prisma ORM v6) | Prisma Documentation. Checked 2026-10-16.