Configuring error formatting (Prisma ORM v7) (/docs/orm/v7/prisma-client/setup-and-configuration/error-formatting)
For the complete Prisma documentation index, see llms.txt. A markdown version of any docs page is available by appending
.mdto its URL.
This page explains how to configure the formatting of errors when using Prisma Client
Location: ORM > v7 > Prisma Client > Setup and Configuration > Configuring error formatting
By default, Prisma Client uses ANSI escape characters to pretty print the error stack and give recommendations on how to fix a problem. While this is very useful when using Prisma Client from the terminal, in contexts like a GraphQL API, you only want the minimal error without any additional formatting.
This page explains how error formatting can be configured with Prisma Client.
Formatting levels
Section titled “Formatting levels”There are 3 error formatting levels:
- Pretty Error (default): Includes a full stack trace with colors, syntax highlighting of the code and extended error message with a possible solution for the problem.
- Colorless Error: Same as pretty errors, just without colors.
- Minimal Error: The raw error message.
In order to configure these different error formatting levels, there are two options:
- Setting the config options via environment variables
- Providing the config options to the
PrismaClientconstructor
Formatting via environment variables
Section titled “Formatting via environment variables”NO_COLOR: If this env var is provided, colors are stripped from the error messages. Therefore you end up with a colorless error. TheNO_COLORenvironment variable is a standard described in the NO_COLOR specification.NODE_ENV=production: If the env varNODE_ENVis set toproduction, only the minimal error will be printed. This allows for easier digestion of logs in production environments.
Formatting via the PrismaClient constructor
Section titled “Formatting via the PrismaClient constructor”Alternatively, use the PrismaClient errorFormat parameter to set the error format:
const prisma = new PrismaClient({
errorFormat: "pretty",
});Related pages
Section titled “Related pages”Custom model and field names: Learn how you can decouple the naming of Prisma models from database tables to improve the ergonomics of the generated Prisma Client APIDatabase connections: Learn how to manage database connections and configure connection poolsDatabase polyfills: Prisma Client provides features that are not achievable with relational databases. These features are referred to as "polyfills" and explained on this page.Generating Prisma Client: Learn when and how to run prisma generate, configure the generator output, and import the generated client in your app.Introduction to Prisma Client: Learn how to set up and configure Prisma Client in your project