I've been wondering about how to implement this as well, and bafflingly the issues linked in @Ryan's post are over two years old, and still unresolved. I came up with a temporary workaround, which is to implement a middleware function for the Prisma client which removes the password field manually after each call.

import { PrismaClient } from '@prisma/client'

async function excludePasswordMiddleware(params, next) {
  const result = await next(params)
  if (params?.model === 'User' && params?.args?.select?.password !== true) {
    delete result.password
  }
  return result
}

const prisma = new PrismaClient()
prisma.$use(excludePasswordMiddlware)

This will check if the model being queried is a User, and it will not delete the field if you explicitly include the password using a select query. This should allow you to still get the password when needed, like when you need to authenticate a user who is signing in:

async validateUser(email: string, password: string) {
  const user = await this.prisma.user.findUnique({
    where: { email },
    select: {
      emailVerified: true,
      password: true,
    },
  })
  // Continue to validate user, compare passwords, etc.
  return isValid
}
Answer from Alex Wohlbruck on Stack Overflow
🌐
Prisma
prisma.io › blog › introducing-global-omit-for-model-fields-in-prisma-orm-5-16-0
Prisma ORM 5.16.0 allows global or local omitted fields in Prisma Client
June 25, 2024 - With the omitApi Preview feature, originally released with Prisma ORM 5.13.0, you can now omit fields from your queries alongside the existing select functionality or on Prisma Client initialization. You can choose to omit fields globally, such as user passwords, or define fields to omit on a per-query basis, such as fields that aren’t necessary in all views.
🌐
Prisma
prisma.io › home › excluding fields › excluding fields › excluding fields › excluding fields
Excluding fields | Prisma Documentation
Use omit when you want Prisma Client to return the normal result shape except for a few specific fields.
Discussions

Add `omit` option for field selection
Problem I've discovered a common issue where you want to select all the fields on a model except for one or few. For example, on a User model, I always want to omit the hashedPassword field, bu... More on github.com
🌐 github.com
1
August 8, 2020
node.js - Exclude user's password from query with Prisma 2 - Stack Overflow
There has been a longstanding feature request (prisma/prisma#5042). As of Prisma ORM 5.16.0, excluding fields globally and locally is supported via the omitApi Preview feature. More on stackoverflow.com
🌐 stackoverflow.com
node.js - Does the prisma global omit option affect the create method? - Stack Overflow
As expected it does not prevent the omitted field from being created or updated, only from being read. ... Sign up to request clarification or add additional context in comments. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... 2 Authentication failed against database server at `localhost`, the provided database credentials for `root` are not valid - Nextjs & Prisma... More on stackoverflow.com
🌐 stackoverflow.com
The "omit" field type is not generated for Prisma client - v6.2.0
I'm seeing the typescript error of, Object literal may only specify known properties, and 'omit' does not exist in type 'Subset'Object literal may only specify known properties, and 'omit' does not exist in type 'Subset More on answeroverflow.com
🌐 answeroverflow.com
January 7, 2025
🌐
Prisma
prisma.io › home › select fields › select fields › select fields › select fields
Select fields | Prisma Documentation
Use select and include to make the result smaller, clearer, and more intentional. If you do not pass select, include, or omit, Prisma Client returns all scalar fields for the model and excludes relations from the result.
🌐
Typegraphql
prisma.typegraphql.com › advanced › hiding model fields
Hiding Prisma model field in GraphQL schema | TypeGraphQL Prisma
Basically, there are two options you can set in - omitInputFieldsByDefault and omitOutputFieldsByDefault. They both accept an array of field names: generator typegraphql { provider = "typegraphql-prisma" omitInputFieldsByDefault = ["createdAt", "updatedAt"] omitOutputFieldsByDefault = ["password"] }
🌐
Goprisma
goprisma.org › docs › walkthrough › fields
Field selection and omission – Prisma Client Go
users, err := client.User.FindMany( User.Name.Equals("a"), ).Omit( User.ID.Field(), User.Password.Field(), User.Age.Field(), User.Name.Field(), ).Exec(ctx) if err != nil { panic(err) }
🌐
GitHub
github.com › prisma › prisma › discussions › 23924
Preview feature feedback: `omitApi`, exclude fields from Prisma Client query results · prisma/prisma · Discussion #23924
I'm also facing this same issue with prisma & prisma client versions as 5.19.1. Beta Was this translation helpful? Give feedback. ... There was an error while loading. Please reload this page. Something went wrong. There was an error while loading. Please reload this page. ... const omitConfig = { firstModel: { secret: true, }, secondModel: { secret: true, }, } as const; new PrismaClient({ omit: omitConfig, });
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 3246
Add `omit` option for field selection · Issue #3246 · prisma/prisma
August 8, 2020 - In addition to the select parameter, I would like an omit parameter to be added. const result = await prisma.user.findOne({ where: { id: 1 }, omit: { hashedPassword: true, }, }) Reactions are currently unavailable · No one assigned · No labels · No labels ·
Author   prisma
🌐
Medium
medium.com › @aliammariraq › prisma-exclude-with-typesafety-8484ea6d0c42
Prisma Exclude With TypeSafety. Prisma, a powerful Node.js/TypeScript… | by Ali Ammar | Medium
June 24, 2023 - When we need to exclude a specific field while selecting all others in Prisma, the conventional approach requires us to explicitly list all the desired fields and omit the unwanted one. This can become cumbersome and error-prone, especially when dealing with models that have numerous fields.
Find elsewhere
Top answer
1 of 12
9

I've been wondering about how to implement this as well, and bafflingly the issues linked in @Ryan's post are over two years old, and still unresolved. I came up with a temporary workaround, which is to implement a middleware function for the Prisma client which removes the password field manually after each call.

import { PrismaClient } from '@prisma/client'

async function excludePasswordMiddleware(params, next) {
  const result = await next(params)
  if (params?.model === 'User' && params?.args?.select?.password !== true) {
    delete result.password
  }
  return result
}

const prisma = new PrismaClient()
prisma.$use(excludePasswordMiddlware)

This will check if the model being queried is a User, and it will not delete the field if you explicitly include the password using a select query. This should allow you to still get the password when needed, like when you need to authenticate a user who is signing in:

async validateUser(email: string, password: string) {
  const user = await this.prisma.user.findUnique({
    where: { email },
    select: {
      emailVerified: true,
      password: true,
    },
  })
  // Continue to validate user, compare passwords, etc.
  return isValid
}
2 of 12
6

The only legit way is adding column: true to the columns you want to include. There are requests for excluding columns here so it would be great if you could add a 👍 to the request relevant to you so that we can look at the priority.

https://github.com/prisma/prisma/issues/5042 https://github.com/prisma/prisma/issues/7380 https://github.com/prisma/prisma/issues/3796

🌐
YouTube
youtube.com › watch
How to omit fields from query results in Prisma ORM - YouTube
Learn how you can omit fields from query results when querying your database with Prisma ORM. Omitting fields on a per-query level initially has been release...
Published   July 8, 2024
🌐
Prisma
prisma.io › home › null and undefined › null and undefined › null and undefined › null and undefined
Null and undefined in Prisma Client (Reference) | Prisma Documentation
// This will throw an error prisma.user.create({ data: { name: "Alice", email: undefined, // Error: Cannot explicitly use undefined here }, }); // Use `Prisma.skip` (a symbol provided by Prisma) to omit a field prisma.user.create({ data: { name: ...
🌐
Answer Overflow
answeroverflow.com › m › 1326260053124055135
The "omit" field type is not generated for Prisma client - v6.2.0
January 7, 2025 - The functionality can be used without specifying it as a preview feature.Preview feature "omitApi" is deprecated. The functionality can be used without specifying it as a preview feature.. Am I doing something wrong, or is this just a bug? ... Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB - prisma/prisma
🌐
Prisma
prisma.io › home › prisma client api › prisma client api › prisma client api
Prisma Client API | Prisma Documentation
const result = await prisma.user.findMany({ omit: { password: true, }, }); [ { id: 1, email: "jenny@prisma.io", name: "Jenny", }, { id: 2, email: "rose@prisma.io", name: "Rose", }, ]; const results = await prisma.user.findMany({ omit: { password: true, }, include: { posts: { omit: { title: true, }, }, }, }); [ { id: 1, email: "jenny@prisma.io", name: "Jenny", posts: [ { id: 1, author: { id: 1, email: "jenny@prisma.io", name: "Jenny", }, authorId: 1, }, ], }, { id: 2, email: "rose@prisma.io", name: "Rose", posts: [ { id: 2, author: { id: 2, email: "rose@prisma.io", name: "Rose", }, authorId: 2, }, ], }, ]; The following example demonstrates how to use TypeScript's satisfies operator with omit: const omitPassword = { password: true } satisfies Prisma.UserOmit; relationLoadStrategy specifies how a relation should be loaded from the database.
🌐
GitHub
github.com › prisma › prisma › issues › 24835
Incorrect type inferred when using omit + include inside of an include. · Issue #24835 · prisma/prisma
July 19, 2024 - The resultant inferred type generated should not include the omitted fields. generator client { provider = "prisma-client-js" previewFeatures = ["omitApi"] } datasource db { provider = "postgresql" url = env("DATABASE_URL") } model A { id Int @id @default(autoincrement()) model_b B[] } model B { id Int @id @default(autoincrement()) a_id Int a A @relation(fields: [a_id], references: [id]) private_field String c_id Int c C @relation(fields: [c_id], references: [id]) } model C { id Int @id @default(autoincrement()) public_field String B B[] }
Author   prisma
🌐
Answer Overflow
answeroverflow.com › m › 1306279384960733265
Omit type for creating - Prisma
November 14, 2024 - However, I can use delete user.password. Is there a way to omit the password when creating a new user? ```.tsx async create(dto: CreateUserDto) { const user = await this.prismaService.instance.user.create({ data: { ...dto, }, }); return user; }```
🌐
GitHub
github.com › prisma › prisma › issues › 5042
Add way to exclude fields via query arguments or globally · Issue #5042 · prisma/prisma
April 13, 2020 - await prisma.user.findMany({ omit: { password: true, }, }) Use query and list all the fields you want · Schema annotation · Manual omission via lodash or something !? https://github.com/prisma/prisma/issues/2170 · Add omit option for field selection #3246 ·
Author   prisma
🌐
Tsnc
prismaphp.tsnc.tech › docs
omit fields - Prisma PHP
The omit parameter allows you to exclude specific fields from the result set.
🌐
Medium
medium.com › @hala.s.salim › enhancing-security-in-nestjs-with-prisma-excluding-sensitive-fields-86d9789c0823
Enhancing Security in NestJS with Prisma: Excluding Sensitive Fields | by Hala S. A. Abu Salim | Medium
January 10, 2024 - The _.omit function, in particular, allows for the exclusion of specified fields from an object, aligning with our objective of securing sensitive information. This custom Prisma solution provides a flexible and elegant way to exclude sensitive ...
🌐
Prisma
prisma.io › home › best practices › best practices › best practices
Best practices | Prisma Documentation
import { PrismaClient } from '../generated/prisma/client' import { PrismaPg } from '@prisma/adapter-pg' const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }) // Global exclusion const prisma = new PrismaClient({ adapter, omit: { user: { secretValue: true } } }) // Per-query exclusion const user = await prisma.user.findUnique({ where: { id: 1 }, omit: { secretValue: true } })