# Pull every redline from a contract

> Redlined contracts are exactly the long-tail complexity that breaks template-based pipelines. Reducto reads every strikethrough, underline, and annotation as structured tags, so your team surfaces all 500+ revisions in code instead of page by page.

Canonical: https://reducto.ai/cookbooks/reducto-parse-redlined-legal-contracts

Contract negotiations leave a long trail of edits, and somewhere in 165 pages of redlines is every change that actually matters. Reading them by hand is slow and easy to get wrong. This cookbook hands that work to Reducto: [parse](https://reducto.ai/parse) a redlined contract once and get back every insertion, deletion, and replacement as a structured list your code can sort, count, and route.

## What you'll build

```markdown
Redlined contract (PDF or DOCX)
        → Reducto Parse with change_tracking
        → Output tagged with <change>, <s>, <u>
        → A structured list of every revision
```

## Setup

Grab an API key from [studio.reducto.ai](https://studio.reducto.ai) → **API Keys** → **Create new API key**, then set it and install the SDK:

```bash
export REDUCTO_API_KEY="your-api-key-here"
pip install reducto   # Python
npm install reducto   # JavaScript
```

Reducto handles both Word docs (native track-changes metadata, most accurate) and PDFs (visual detection of underlines and strikethroughs), with no templates or per-document setup. Need a sample? Use this [165-page union labor agreement](https://static1.squarespace.com/static/5cee0f8eb1a76b0001ca1d78/t/5e45817fe03fd3048a4b1792/1581613498729/Redline+Contract+with+Annotation.pdf) with extensive redlines.

## Step 1: Parse with change tracking

The one setting that matters is `formatting.include: ["change_tracking"]`. It tells Reducto to wrap revisions in HTML tags instead of returning flat text.

```python
from pathlib import Path
from reducto import Reducto

client = Reducto()

upload = client.upload(file=Path("redlined_contract.pdf"))

result = client.parse.run(
    input=upload.file_id,
    formatting={"include": ["change_tracking"]},
)
```

```javascript
import Reducto from "reducto";
import fs from "fs";

const client = new Reducto();

const upload = await client.upload({
  file: fs.createReadStream("redlined_contract.pdf"),
});

const result = await client.parse.run({
  input: upload.file_id,
  formatting: { include: ["change_tracking"] },
});
```

Large documents come back as a result URL to keep responses light. Fetch it and stitch the chunks together:

```python
import requests

if result.result.type == "url":
    data = requests.get(result.result.url).json()
    full_content = "\n".join(c.get("content", "") for c in data.get("chunks", []))
else:
    full_content = "\n".join(c.content for c in result.result.chunks)
```

```javascript
let fullContent;
if (result.result.type === "url") {
  const data = await (await fetch(result.result.url)).json();
  fullContent = (data.chunks || []).map((c) => c.content || "").join("\n");
} else {
  fullContent = result.result.chunks.map((c) => c.content).join("\n");
}
```

## Step 2: Read the tags

Every revision shows up as simple, predictable markup:

<Table html={"<table>\n  <thead>\n    <tr><th>Tag</th><th>Meaning</th><th>Example</th></tr>\n  </thead>\n  <tbody>\n    <tr><td><code>&lt;s&gt;</code></td><td>Deletion</td><td><code>&lt;change&gt;&lt;s&gt;forty-eight (48)&lt;/s&gt;&lt;/change&gt;</code></td></tr>\n    <tr><td><code>&lt;u&gt;</code></td><td>Insertion</td><td><code>&lt;change&gt;&lt;u&gt;and any PEOPLE deduction&lt;/u&gt;&lt;/change&gt;</code></td></tr>\n    <tr><td><code>&lt;change&gt;</code></td><td>Revision group</td><td><code>&lt;change&gt;&lt;s&gt;forty-eight (48)&lt;/s&gt; &lt;u&gt;fifty (50)&lt;/u&gt;&lt;/change&gt;</code></td></tr>\n  </tbody>\n</table>"} />

A single `<change>` block can hold a deletion, an insertion, or both (a replacement).

## Step 3: Extract changes in code

Parse the tags into a structured list of deletions and insertions:

```python
import re

def extract_changes(content):
    changes = []
    for match in re.finditer(r"<change>(.*?)</change>", content, re.DOTALL):
        block = match.group(1)
        changes.append({
            "deleted": re.findall(r"<s>(.*?)</s>", block, re.DOTALL),
            "inserted": re.findall(r"<u>(.*?)</u>", block, re.DOTALL),
        })
    return changes
```

```javascript
function extractChanges(content) {
  const changes = [];
  const blocks = content.matchAll(/<change>([\s\S]*?)<\/change>/g);
  for (const [, block] of blocks) {
    changes.push({
      deleted: [...block.matchAll(/<s>([\s\S]*?)<\/s>/g)].map((m) => m[1]),
      inserted: [...block.matchAll(/<u>([\s\S]*?)<\/u>/g)].map((m) => m[1]),
    });
  }
  return changes;
}
```

Then categorize to prioritize review. Replacements usually need the closest look:

```python
changes = extract_changes(full_content)

deletions  = sum(1 for c in changes if c["deleted"] and not c["inserted"])
insertions = sum(1 for c in changes if c["inserted"] and not c["deleted"])
replacements = sum(1 for c in changes if c["deleted"] and c["inserted"])

print(f"{len(changes)} revisions: {deletions} deletions, "
      f"{insertions} insertions, {replacements} replacements")
```

On the sample contract that's **555 revisions** across 165 pages (191 deletions, 270 insertions, and 94 replacements), from a single Parse call, zero-shot, with no template to maintain.

## Try it with curl

The same job as one request, tested on a sample file (a synthetic redlined MSA):

```bash
# 1. Upload the file (or pass a public URL as "input" and skip this step)
curl -s https://platform.reducto.ai/upload \
  -H "Authorization: Bearer $REDUCTO_API_KEY" \
  -F file=@contract.docx
# => {"file_id": "reducto://..."}

# 2. Run parse
curl -s https://platform.reducto.ai/parse \
  -H "Authorization: Bearer $REDUCTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "input": "reducto://FILE_ID",
  "settings": {"model": "r-1"},
  "formatting": {"include": ["change_tracking", "comments"]}
}'
```

The part of the response that matters for this job:

```html
<change><u>within 45 days of receipt</u><s>within 60 days of
receipt</s></change>
<change><u>1% per month</u><s>1.5% per month</s></change>
<change><u>two times the Fees paid in the
twelve months before the claim</u><s>the Fees paid in the twelve months before the claim</s></change>
```

[Full response format ->](https://docs.reducto.ai/parse/response-format)

## Prefer no code?

Do the same thing in [Reducto Studio](https://studio.reducto.ai): upload your contract, open **Configurations → Advanced → Formatting**, check `change_tracking`, and **Run**. The output shows the `<change>`, `<s>`, and `<u>` tags inline. Export as JSON or deploy the config for repeated use.

## Where this goes next

Change tracking is one task on one platform. Once the revisions are structured, chain the rest of the toolkit onto the same pipeline:

- **Pair with&#xA0;**[**Extract**](https://docs.reducto.ai/extract/overview)**:** pull grounded, cited fields (dates, amounts, parties) straight from the changed clauses.
- **Route by clause type:** use [Classify](https://docs.reducto.ai/classify/overview) to send indemnification changes to [legal](https://reducto.ai/industries/legal), pricing to finance.
- **Build approval queues:** accept or reject each revision, with human-in-the-loop where it matters.
- **Summarize negotiations:** brief stakeholders without making them read all 165 pages.

Try it on one contract first, free and without signup: the [redline to change list tool](/tools/redline-to-change-list) turns tracked changes in a DOCX or PDF into a list.
