# Compare two CSV files by key from an AI agent

You have two versions of a table and need to know which rows were added, removed or changed, matched by a key column rather than by line position.

**Use `csv-row-diff@1.0.0`.** It is free and needs no key or sign-up. Compare two CSV documents with identical headers by unique key tuples and report added, removed, and changed rows.

## Why call a tool for this

Row-by-row comparison in a model response gets harder to check as the table grows. This tool returns the three groups and their counts, so the agent can report them without retyping the data.

## Call it over HTTP

```sh
curl -X POST https://computefirst.net/v1/tools/csv-row-diff/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"left":"id,name,city\n1,Ada,London\n2,Lin,Paris\n3,Zoe,Berlin\n","right":"id,name,city\n1,Ada,London\n2,Lin,Rome\n4,Bob,Oslo\n","keys":["id"]}'
```

Response:

```json
{
  "result": {
    "added": "id,name,city\n4,Bob,Oslo\n",
    "removed": "id,name,city\n3,Zoe,Berlin\n",
    "changed": "id,name,city\n2,Lin,Rome\n",
    "counts": {
      "added": 1,
      "removed": 1,
      "changed": 1,
      "unchanged": 1
    }
  }
}
```

## Call it over MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "csv-row-diff",
  "version": "1.0.0",
  "input": {
    "left": "id,name,city\n1,Ada,London\n2,Lin,Paris\n3,Zoe,Berlin\n",
    "right": "id,name,city\n1,Ada,London\n2,Lin,Rome\n4,Bob,Oslo\n",
    "keys": [
      "id"
    ]
  }
}
```

## Check the result

Both inputs need identical headers in the same order, and each key value (or combination of key columns) must appear only once in each input. Pass the CSV text, not a file path. Rows on the left equal removed + changed + unchanged; rows on the right equal added + changed + unchanged.

Full contract, limits and unsupported cases: [CSV row diff](/tools/csv-row-diff).

## Related tools

- [CSV reconcile](/tools/csv-reconcile)
- [CSV to JSON](/tools/csv-to-json)
