Registry / database / prisma-zod-generator

prisma-zod-generator

JSON →
library2.1.4jsnpmunverified

Prisma Zod Generator (v2.1.4) is a Prisma generator that emits Zod schemas from your Prisma schema, enabling end-to-end validation with Zod. It supports both ESM and CJS, requires Node >=20.19.0 and Zod >=3.25.0 <5. Key differentiators include multiple generation modes (minimal, full, custom), schema variants, decimal handling, DateTime support, naming patterns, selective generation, and a paid Pro tier with additional features like policy guardrails and Drift Guard. Active development with frequent releases.

npm install prisma-zod-generator
INSTALL
IMPORT
SIG · PRISMA-ZOD-GENERAT
P
prisma-zod-generator
databasejavascriptv2.1.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Generated schemas
✓ import { UserSchema, UserCreateInputSchema } from './generated/zod'
✗ const { UserSchema } = require('./generated/zod')
Generated files are typically in a 'zod' subdirectory under the output path. Use named imports for specific model schemas.
Default export from generated file
✓ import schemas from './generated/zod'
✗ const schemas = require('./generated/zod')
The generated index file has a default export containing all schemas as an object. Available since v2.
Prisma client usage
✓ import { PrismaClient } from '@prisma/client'
Prisma Zod Generator only generates Zod schemas; Prisma Client is still needed for database operations.

Install and configure Prisma Zod Generator, then validate Prisma model input using the generated Zod schema.

// 1. Install dependencies npm install prisma-zod-generator zod // 2. Add to Prisma schema (schema.prisma) generator zod { provider = "prisma-zod-generator" output = "./generated/zod" } // 3. Run Prisma generate // npx prisma generate // 4. Use generated schemas in your code import { UserCreateInputSchema } from './generated/zod'; const result = UserCreateInputSchema.safeParse({ email: 'user@example.com', name: 'John Doe' }); if (!result.success) { console.error(result.error); } // Full mode also exports ObjectSchemas (e.g., UserSchema) for validation of full objects
Debug
Known issues
gotchaGenerator output path is relative to the project root, not the schema file location. Misconfiguration leads to 'Cannot find module' errors.
fix
Use an absolute path or a path relative to the project root, e.g., output = "./src/generated/zod"
affects: >=1.0.0
deprecatedIn v1, the generator produced schemas with 'Zod' prefix (e.g., ZodUser). v2 dropped the 'Zod' prefix to simplify imports.
fix
Migrate to v2 by removing 'Zod' prefix from import names. For example, 'ZodUser' becomes 'UserSchema'.
affects: <2.0.0
breakingNode.js version requirement was bumped from >=14 to >=20.19.0 in v2, breaking compatibility with older Node releases.
fix
Update Node.js to v20.19.0 or later.
affects: >=2.0.0
deprecatedThe 'custom' mode configuration option has been renamed to 'default' in v2.1. Using 'custom' will still work but logs a deprecation warning.
fix
Rename mode from 'custom' to 'default' in Prisma schema generator config.
affects: >=2.1.0
gotchaWhen using TypeScript, the generated Zod schemas may require specific tsconfig paths or include patterns to be resolved correctly.
fix
Ensure that 'compilerOptions.paths' or 'include' in tsconfig.json covers the output directory of the generated schemas.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module './generated/zod'
Generator output path is misconfigured or Prisma generate hasn't been run.
fix
Check that the 'output' path in schema.prisma is correct and run 'npx prisma generate'.
TypeError: UserCreateInputSchema.safeParse is not a function
Importing a wrong export or the generated schema is not a Zod object.
fix
Ensure you are importing the correct named export (e.g., UserCreateInputSchema) and that the generator ran successfully.
Error: Unknown type: Decimal
Prisma Decimal type is not handled by default; need to configure custom Zod types.
fix
Update to v1.5.0+ which includes Decimal handling, or configure a custom Zod type mapping.
Upgrade
Version history
2.1.4latest on npm
Audit
Dependencies
zodrequiredPeer dependency: Zod is required for schema generation and validation
Agent activity
8 hits · last 30 days
node
8
Resources
prisma-zod-generator — npm install prisma-zod-generator · libregistry