prisma schema to zod

Prisma Schema to Zod

Convert Prisma schema models and enums into Zod validation schemas, map scalar and relation fields, and decide between an online converter and the zod-prisma-types generator.

Open Prisma to Zod

Quick answer: how do I convert a Prisma schema to Zod?

Paste your Prisma model and enum definitions into the Prisma to Zod converter and it generates Zod schema starters with inferred TypeScript types. Scalars map to base Zod types, enums become `z.enum`, and relations are generated as optional lazy references for selected payloads.

Map scalar fields

Prisma scalar types map to the closest Zod starter. Generated schemas are intentionally permissive, so tighten them with format and range checks that match your database columns and API contract.

  • String, Int, Float, Boolean, and DateTime map to base Zod types.
  • Decimal, BigInt, Json, and Bytes need review for transport format and precision.
  • Nullable fields use `.nullable()` and list fields use `z.array(...)`.

Handle enums and relations

Prisma enum blocks become reusable `z.enum` schemas. Relation fields are generated as optional because Prisma only returns related records when a query includes or selects them.

  • Reuse generated enum schemas across request and response validators.
  • Keep relations optional unless your query always includes them.
  • Model create and update input schemas separately from output models.

Online converter vs zod-prisma-types

The zod-prisma-types npm package is a Prisma generator that regenerates full Zod schemas, including relations and input types, on every build. The online converter is faster for one-off review and keeps the schema private. Use the package for repo-owned, always-in-sync schemas and the tool for quick conversion.

Prisma field to Zod mapping

Prisma fieldZod starterReview note
`String``z.string()`Add `.email()`, `.uuid()`, `.url()`, or length checks for known formats.
`Int` / `Float``z.number()`Add `.int()`, `.min()`, or `.max()` to match column constraints.
`DateTime``z.string().datetime()`Confirm whether the API sends ISO strings or Date objects.
`enum``z.enum([...])`Reusable enum schema generated from the Prisma enum block.
relation`z.lazy(() => ...).optional()`Optional because relations are only present when selected or included.

Use FrameworkKit to generate the starter code, then review the output before shipping it in production.

Generate with Prisma to Zod

Prisma to Zod resources

FAQ

How do I generate Zod schemas from a Prisma schema?

Paste your Prisma models and enums into the Prisma to Zod converter. It maps scalar fields, enums, nullable fields, list fields, and relations into Zod schema starters with inferred TypeScript types, all in the browser.

Is this the same as zod-prisma-types?

No. zod-prisma-types is an npm package and Prisma generator that produces full Zod schemas on every build. This converter is a fast, private, browser-only tool for one-off conversion and review without installing a generator.

How are Prisma relations converted to Zod?

Relations are generated as optional lazy references because Prisma only returns related records when a query includes or selects them. Make a relation required only when your query always includes it.

Related comparisons

Related tools