# contract infer (/docs/cli/contract-infer) > For the complete Prisma documentation index, see [llms.txt](https://www.prisma.io/docs/llms.txt). A markdown version of any docs page is available by appending `.md` to its URL. Infer a starter contract from an existing database. Location: CLI > contract infer `contract infer` inspects a live database and writes a starter PSL contract. An existing file at the output path is overwritten, with a warning. Use it when you are adding Prisma ORM to an existing database and want an initial contract to review and edit. ## Usage [#usage] #### bun ```bash bunx prisma contract infer [--db "$DATABASE_URL"] ``` #### pnpm ```bash pnpm prisma contract infer [--db "$DATABASE_URL"] ``` #### yarn ```bash yarn prisma contract infer [--db "$DATABASE_URL"] ``` #### npm ```bash npx prisma contract infer [--db "$DATABASE_URL"] ``` ## Options [#options] | Option | What it does | | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | `--db ` | Connects to the database. Optional: without it the command uses `db.connection` from `prisma.config.ts`, and fails only when neither is set. | | `--output ` | Writes the inferred PSL contract to a specific path. | | `--config ` | Read this config file instead of `./prisma.config.ts`. | | `--json` | Prints a machine-readable result. | ## Examples [#examples] #### bun ```bash bunx prisma contract infer --db "$DATABASE_URL" bunx prisma contract infer --db "$DATABASE_URL" --output ./prisma/contract.prisma bunx prisma contract infer --db "$DATABASE_URL" --json ``` #### pnpm ```bash pnpm prisma contract infer --db "$DATABASE_URL" pnpm prisma contract infer --db "$DATABASE_URL" --output ./prisma/contract.prisma pnpm prisma contract infer --db "$DATABASE_URL" --json ``` #### yarn ```bash yarn prisma contract infer --db "$DATABASE_URL" yarn prisma contract infer --db "$DATABASE_URL" --output ./prisma/contract.prisma yarn prisma contract infer --db "$DATABASE_URL" --json ``` #### npm ```bash npx prisma contract infer --db "$DATABASE_URL" npx prisma contract infer --db "$DATABASE_URL" --output ./prisma/contract.prisma npx prisma contract infer --db "$DATABASE_URL" --json ``` ## Data lines [#data-lines] Without `--json`, standard output gets one line: the path of the PSL file the command wrote, relative to the working directory. [Global flags](https://www.prisma.io/docs/cli/global-flags#data-lines-of-prisma-orm-commands) lists the rules data lines follow. ## What to review [#what-to-review] Inference gives you a starting point, not a finished design. Review: * model and field names * relation names * mapped database names * defaults, indexes, and constraints * extension-backed column types The file starts with `// use prisma-8`, because `contract emit` reads only `.prisma` files that start with that line. Each model is named after its table, and gets `@@map` only when the table name differs from the model name: a table `User` becomes `model User`, and a table `user_profile` becomes `model UserProfile` with `@@map("user_profile")`. Every column default is written in a form `contract emit` accepts, so you can emit the file without editing it. [Default values](https://www.prisma.io/docs/orm/contract-authoring/psl-syntax#default-values) shows those forms. In a list column's type, a `?` means something different depending on where it is: * `Type[]?`, with `?` after the brackets: the column itself can be `NULL`. * `Type?[]`, with `?` before the brackets: the list can hold `NULL` elements. A list column that Prisma ORM migrations created cannot hold `NULL` elements, because the migration adds a check that stops it, so it gets no `?` before the brackets. Any other list column gets one. Each column gets a type such as `VarChar(20)`, `Bit(8)`, `VarBit(16)`, or `Interval(3)`, written with the fewest parameters that describe the column exactly. The types come from Prisma ORM's types for your database and from the extension packs listed under `extensions` in `prisma.config.ts`. An extension pack is the Prisma ORM package for a database extension, such as pgvector. When a column has a type that none of these provide, the command writes no file. It fails with `CONTRACT.INFER_COLUMN_TYPE_UNCLAIMED` and lists every such column, such as `public.doc.meta: hstore`. To get past the error, do one of the following for each listed column: * If the type comes from a database extension that has a Prisma ORM pack, add the pack to `extensions` in `prisma.config.ts` and run `contract infer` again. * Write the contract by hand, and declare the column's field as ``Raw(sql`hstore`)``. `Raw(...)` declares a field by the database's own name for its type, here the type the error lists. [Columns of any database type](https://www.prisma.io/docs/orm/contract-authoring/psl-syntax#columns-of-any-database-type) shows how. * Change the column's type, or remove the column from the database. Prisma ORM 7 read date and time columns as `DateTime` fields, which gave your application JavaScript `Date` objects. `contract infer` writes them as text types instead, so your application reads and writes them as strings. It also needs no `Temporal`, the newer JavaScript date and time API. A `timestamp(3)` column is written `TimestampString(3)`, `timestamptz(3)` is `TimestamptzString(3)`, `date` is `DateString`, and `time(3)` is `TimeString(3)`. A `timestamp` value reads as `"2026-09-14 10:00:00.123"`. To get `Temporal` values instead, change the types to `Timestamp(3)`, `Timestamptz(3)`, `Date`, and `Time(3)` in the inferred file. A `bytea` default is written as the hexadecimal text PostgreSQL prints, inside backticks with `bytea` in front, such as ``@default(bytea`\x68656c6c6f`)``. The word in front of the backticks names the type of the value. A contract inferred before `8.0.0-rc.15` keeps its types until you run `contract infer` again. When you do, the date and time fields and any `bytea` default change, and so does the storage hash: emit the contract, update the code that used `Temporal` values for these fields, then run `prisma db sign` for a database you keep with `db update`, or create an empty migration with [`migration new`](https://www.prisma.io/docs/cli/migration-new) and apply it when you use migrations. If you keep an inferred contract in version control, running `contract infer` again after an upgrade can write the same database differently, so review the diff before you commit it. The command stops at `contract.prisma`. Follow it with the emit and sign steps: #### bun ```bash bunx prisma contract emit bunx prisma db sign --db "$DATABASE_URL" bunx prisma db verify --db "$DATABASE_URL" ``` #### pnpm ```bash pnpm prisma contract emit pnpm prisma db sign --db "$DATABASE_URL" pnpm prisma db verify --db "$DATABASE_URL" ``` #### yarn ```bash yarn prisma contract emit yarn prisma db sign --db "$DATABASE_URL" yarn prisma db verify --db "$DATABASE_URL" ``` #### npm ```bash npx prisma contract emit npx prisma db sign --db "$DATABASE_URL" npx prisma db verify --db "$DATABASE_URL" ``` `db sign` is the handoff point where you record that the existing database matches the reviewed contract. ## Related pages - [`auth`](https://www.prisma.io/docs/cli/auth): Sign in to your Prisma account from the CLI, sign out, and manage workspace sessions. - [`branch`](https://www.prisma.io/docs/cli/branch): List platform branches for a project. - [`bucket`](https://www.prisma.io/docs/cli/bucket): Create and manage object-store buckets. - [`Configuration`](https://www.prisma.io/docs/cli/configuration): Configure Prisma ORM CLI commands with prisma.config.ts and global flags. - [`contract emit`](https://www.prisma.io/docs/cli/contract-emit): Emit Prisma ORM contract artifacts.