# 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 8 to an existing database and want an initial contract to review and edit.

## Usage [#usage]

  

#### bun

```bash
bunx prisma@latest contract infer --db "$DATABASE_URL"
```

#### pnpm

```bash
pnpm dlx prisma@latest contract infer --db "$DATABASE_URL"
```

#### yarn

```bash
yarn dlx prisma@latest contract infer --db "$DATABASE_URL"
```

#### npm

```bash
npx prisma@latest contract infer --db "$DATABASE_URL"
```

## Options [#options]

| Option            | What it does                                           |
| ----------------- | ------------------------------------------------------ |
| `--db <url>`      | Connects to the database.                              |
| `--output <path>` | Writes the inferred PSL contract to a specific path.   |
| `--config <path>` | Read this config file instead of `./prisma.config.ts`. |
| `--json`          | Prints a machine-readable result.                      |

## Examples [#examples]

  

#### bun

```bash
bunx prisma@latest contract infer --db "$DATABASE_URL"
bunx prisma@latest contract infer --db "$DATABASE_URL" --output ./prisma/contract.prisma
bunx prisma@latest contract infer --db "$DATABASE_URL" --json
```

#### pnpm

```bash
pnpm dlx prisma@latest contract infer --db "$DATABASE_URL"
pnpm dlx prisma@latest contract infer --db "$DATABASE_URL" --output ./prisma/contract.prisma
pnpm dlx prisma@latest contract infer --db "$DATABASE_URL" --json
```

#### yarn

```bash
yarn dlx prisma@latest contract infer --db "$DATABASE_URL"
yarn dlx prisma@latest contract infer --db "$DATABASE_URL" --output ./prisma/contract.prisma
yarn dlx prisma@latest contract infer --db "$DATABASE_URL" --json
```

#### npm

```bash
npx prisma@latest contract infer --db "$DATABASE_URL"
npx prisma@latest contract infer --db "$DATABASE_URL" --output ./prisma/contract.prisma
npx prisma@latest contract infer --db "$DATABASE_URL" --json
```

## 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 command stops at `contract.prisma`. Follow it with the emit and sign steps:

  

#### bun

```bash
bunx prisma@latest contract emit
bunx prisma@latest db sign --db "$DATABASE_URL"
bunx prisma@latest db verify --db "$DATABASE_URL"
```

#### pnpm

```bash
pnpm dlx prisma@latest contract emit
pnpm dlx prisma@latest db sign --db "$DATABASE_URL"
pnpm dlx prisma@latest db verify --db "$DATABASE_URL"
```

#### yarn

```bash
yarn dlx prisma@latest contract emit
yarn dlx prisma@latest db sign --db "$DATABASE_URL"
yarn dlx prisma@latest db verify --db "$DATABASE_URL"
```

#### npm

```bash
npx prisma@latest contract emit
npx prisma@latest db sign --db "$DATABASE_URL"
npx prisma@latest 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 8 CLI commands with prisma.config.ts and global flags.
- [`contract emit`](https://www.prisma.io/docs/cli/contract-emit): Emit Prisma 8 contract artifacts.