# Contract review

> Pull the same clause fields out of every new contract, as JSON your product already stores.

A legal agent reads a new contract and fills in the same fields every time: governing law, term, renewal, notice period, and liability cap. The contract changes each time, but the fields don't, so it's a good fit for a Compiled Agent Model.

![A new contract in, the same clause fields back](/docs/figures/cookbook-contract-review.svg)

## The job

- **New each run:** the contract text, the counterparty, and the values in each clause.
- **Same each run:** the fields you extract, the definitions you apply, and the JSON shape your product stores.

## The call

```python
import json
from openai import OpenAI

client = OpenAI(api_key="YOUR_KEY", base_url="https://api.inferenceindex.com/v1")

FIELDS = """Return JSON with exactly these keys:
governing_law (string), term_months (integer), auto_renewal (boolean),
termination_notice_days (integer), liability_cap (string, or null if none).
Use null when the contract is silent."""

def review(contract_text: str) -> dict:
    response = client.chat.completions.create(
        model="workflow/auto",
        messages=[
            {"role": "system", "content": "You review commercial contracts. " + FIELDS},
            {"role": "user", "content": contract_text},
        ],
    )
    return json.loads(response.choices[0].message.content)
```

## What comes back

An example reply for a master services agreement:

```json
{
  "governing_law": "Delaware",
  "term_months": 24,
  "auto_renewal": true,
  "termination_notice_days": 60,
  "liability_cap": "12 months of fees"
}
```

## In production

- Keep the system prompt and field list fixed. That fixed definition is what makes it the same job each time.
- Validate the JSON before you store it, the same way you do today.
- A contract type your agent has never handled goes to your [fallback model](/docs/fallback-models), so you get today's answer at today's price.

## Related

- [Cookbook](/docs/use-cases)
- [Invoice reconciliation](/docs/cookbook/invoice-reconciliation)
