Skip to main content

Special Type Mapping

PrismaZod (I/O)Pure Models DefaultNotes
Stringz.string()sameoptional + .nullable() when optional string input variant
Intz.number().int()same
Floatz.number()same
Booleanz.boolean()same
DateTimez.date()same(strategy: date)
Jsonz.unknown() + optional refinementssameOptional depth/length validations
Bytesz.instanceof(Uint8Array)z.string() (base64)Override to Uint8Array by useBase64:false
BigIntz.bigint()same
Decimalz.instanceof(Prisma.Decimal)sameFull Decimal.js support (configurable via decimalMode)
Enums<Enum>Schema<Enum>SchemaGenerated enum schemas

Bytes: adds size constraints & base64 regex or length refinements depending on representation.

JSON: Can enforce serializability, depth, and length; adds descriptive comments in generated file.

Decimal Type Support

The Decimal type in Prisma is mapped to Zod schemas based on the decimalMode configuration option. This feature provides full compatibility with zod-prisma-types for seamless migration.

Configuration Options

Configure decimal handling via the decimalMode option in your config file:

{
"decimalMode": "decimal" // "decimal" | "number" | "string"
}

Modes

Full Decimal.js support matching zod-prisma-types implementation:

  • Pure Models: z.instanceof(Prisma.Decimal) with descriptive error messages
  • Input Types: Union of number | string | Prisma.Decimal | Decimal (if decimal.js installed) with runtime validation
  • Imports: Automatically imports Prisma from @prisma/client (non-type import for instanceof checks)

Example Output:

// Pure model schema
export const ProductSchema = z.object({
id: z.number().int(),
price: z.instanceof(Prisma.Decimal, {
message: "Field 'price' must be a Decimal. Location: ['Models', 'Product']",
}),
});

number

Legacy mode for backward compatibility:

  • Maps Decimal fields to z.number()
  • Warning: May lose precision for large decimal values
  • Use when you don't need exact decimal precision

string

String-based validation with regex patterns:

  • Maps Decimal fields to z.string() with decimal format validation
  • Includes precision-aware regex patterns
  • Preserves decimal precision as string representation

Migration from zod-prisma-types

If you're migrating from zod-prisma-types, use decimalMode: "decimal" (the default) for drop-in compatibility. The generator will:

  1. Generate z.instanceof(Prisma.Decimal) for model schemas
  2. Create proper import statements for Prisma
  3. Match the validation patterns from zod-prisma-types

Decimal.js Installation

While decimal.js is not required, installing it provides enhanced type safety:

pnpm add decimal.js

When decimal.js is installed, input schemas will also accept Decimal instances in the validation union.