Two rows, one payment ID
Here is a small problem that has cost me more evenings than I like to admit.
Two rows land in a payments table with the same payment ID. One says 112.31. The other says 62.31. A cleanup job deletes one of them, or these days an AI agent does. The duplicate alert clears. The dashboard goes green.
Which amount did it keep?
If nobody can answer that, the fix was a guess. I spent fifteen years moving data for banks, retailers and healthcare companies, and the bugs that hurt most were never the loud ones. They were the quiet fixes that made every check pass and left the wrong number behind.
In this tutorial we will plant that exact problem in a small table, along with two others, and use DataRanger, an open-source tool I built, to fix what can be proven and hand back what cannot. It runs on your laptop in about five minutes. You need Python and nothing else: no account, no API key, no warehouse.
The rule: prove it or page me
Most data-quality tools stop at telling you something is wrong. DataRanger tries to fix it, under one rule: apply a fix only when it can be proven against the source. Otherwise, call a person.
The proof comes from control totals. Your source system knows how many payments it sent each day and what they added up to. That small table of counts and sums is the referee.
For each problem it finds, DataRanger does four things:
- Tries each candidate fix on a copy of the data.
- Compares the result with the source's totals for that day.
- Applies the fix only if the totals match.
- Sends everything else to you, with the evidence attached. It never changes the tables you give it. The fixed version is written to a separate file.
See it in one minute
Install it and run the built-in demo:
pip install dataranger dataranger demo The demo patrols a sample payments table with planted problems. On version 0.9.0 it prints:
35 incidents: 18 fixed, 9 checked and left alone, 8 for you. Report: dataranger-demo/dashboard.html Open dataranger-demo/dashboard.html in a browser. That one line is the whole idea in miniature: some fixes were proven and applied, some alerts turned out to be nothing, and eight were handed to a person.
How to read the result
Every incident ends in one of three places.
| Outcome | What it means |
|---|---|
| Fixed | A fix was tried on a copy and the result matched the source's totals. |
| Checked and left alone | An alert fired, but the data already agrees with the source. No change was needed. |
| For you | Nothing could be proven. A person decides, with the evidence in the report. |
The report folder holds four files:
-
dashboard.html: the page you just opened. -
incidents.csv: one line per incident, with the decision. -
audit.jsonl: every fix that was considered, and why one was chosen or none was. -
fixed_version.csv: the proposed corrected table. Your original is untouched. ## Now break a table yourself
A demo you did not build is easy to distrust, so let's make our own. Save this as make_data.py. It creates a month of payments, then a second copy with three problems planted in it.
import numpy as np, pandas as pd rng = np.random.default_rng(7) days = pd.date_range("2026-11-01", periods=30, freq="D") customers = pd.DataFrame({"customer_id": [f"C{i:03d}" for i in range(50)]}) rows = [] for day in days: for _ in range(40): rows.append({ "payment_id": f"P{len(rows):05d}", "customer_id": rng.choice(customers["customer_id"]), "booking_date": day.date(), "channel": rng.choice(["web", "store"]), "category": rng.choice(["grocery", "fuel", "travel"]), "amount": round(float(rng.uniform(5, 200)), 2), }) source = pd.DataFrame(rows) # what the source system really holds loaded = source.copy() # what the pipeline loaded, with three problems def on(day): return loaded["booking_date"] == days[day - 1].date() # 1. Nov 12: one payment arrives twice, and the first copy has the wrong amount. bad = loaded[on(12)].head(1).copy() bad["amount"] += 50 loaded = pd.concat([bad, loaded], ignore_index=True) # 2. Nov 20: five payments are loaded twice, identical copies. loaded = pd.concat([loaded, loaded[on(20)].head(5)], ignore_index=True) # 3. Nov 25: three payments never arrive. loaded = loaded.drop(loaded[on(25)].head(3).index) customers.to_csv("customers.csv", index=False) source.to_csv("source_payments.csv", index=False) loaded.to_csv("payments.csv", index=False) print(len(source), "rows in the source,", len(loaded), "rows loaded") Run it:
python make_data.py 1200 rows in the source, 1203 rows loaded The first problem is the one from the opening. Payment P00440 is now in the table twice, once at 112.31 and once at 62.31. The wrong copy comes first, so a cleanup that keeps the first row it sees will keep the wrong amount.
Build the referee
Control totals come from the source, never from the table being checked. One command builds them:
dataranger totals --facts-file source_payments.csv --out control_totals.csv \ --date booking_date --segment channel --amount amount 90 control-total rows for 30 day(s) written to control_totals.csv. Use them with patrol's --manifest-file. Patrol the broken table
dataranger patrol --facts-file payments.csv --ref-file customers.csv \ --manifest-file control_totals.csv --key payment_id --reference customer_id \ --date booking_date --segment channel --category category --amount amount 3 incidents: 2 fixed, 0 checked and left alone, 1 for you. Report: dataranger-report/dashboard.html Three problems planted, three found. Here is what happened to each.
| Day | What we planted | Decision | Why |
|---|---|---|---|
| Nov 12 | Same payment twice, two amounts | Fixed | Keeping the second copy matches the source's total. Keeping the first does not. |
| Nov 20 | Five identical duplicates | Fixed | Removing the extra copies matches the source's count and total. |
| Nov 25 | Three payments missing | For you | The source says 40 payments and the table has 37. No fix can invent the missing rows, so a person is called. |
The part worth looking at
Nov 12 is the interesting one. Open the audit log and print the fixes DataRanger considered for that day:
import json for line in open("dataranger-report/audit.jsonl"): d = json.loads(line) if d["partition"] == "2026-11-12": for c in d["candidates"]: print(c["fix"], "| alert cleared:", c["monitors_quiet"], "| gap to source:", round(c["residual"], 4)) none() | alert cleared: False | gap to source: inf dedupe(key=txn_id) | alert cleared: True | gap to source: 0.0276 dedupe(keep=last, key=txn_id) | alert cleared: True | gap to source: 0.0 Read the middle line slowly. Keeping the first copy clears the duplicate alert. A monitor would call it fixed. It also leaves the day 2.76% away from what the source says, because it kept 112.31.
Keeping the last copy clears the same alert and lands exactly on the source's total. Both fixes look identical to a monitor. Only one of them is right, and the control totals are what tell them apart. That is the answer to "which amount did it keep?"
(The log says txn_id because DataRanger uses its own column names internally. It is your payment_id.)
Put it where the work happens
A check you have to remember to run is a check you will skip. Two places make it automatic.
In CI
DataRanger ships as a GitHub Action. This runs the same patrol after your pipeline step and fails the job when an incident needs a person:
- uses: akshaysharma1088/dataranger@v0.9.0 with: facts-file: payments.csv ref-file: customers.csv manifest-file: control_totals.csv key: payment_id reference: customer_id date: booking_date segment: channel category: category amount: amount The report folder is uploaded as a workflow artifact, so the dashboard and the audit log are attached to the run that produced them. The same action reads a DuckDB file, a Snowflake table or a dbt model if your data does not live in files.
From an AI agent
This is the case I care about most. Agents are now being handed write access to data, and an agent is very good at making an alert go away. DataRanger runs as an MCP server, so the agent can ask for a patrol instead of writing its own cleanup:
claude mcp add dataranger -- uvx dataranger mcp The agent gets back the incidents, the decision for each one, and the reason. The rule stays the same whoever is asking. A fix is applied only when the source agrees, and everything else comes back marked for a person.
Where it falls short
I would rather you hear this from me than find it out in production.
- It needs control totals. No totals from the source, no proof. If all you have is a raw copy of the source table,
dataranger totalsbuilds them for you, as we did above. - It cannot invent data. Missing rows are found and handed to you. They are never made up.
- It writes a corrected file, not your table. Today the patrol produces a fixed copy and a report. Applying a verified fix back to a warehouse table is being built in the open, and the design is in the issue tracker.
- Some duplicates still go to a person. If two copies differ only in a column the totals do not cover, such as a load timestamp, DataRanger cannot prove which one to keep and says so.
- The benchmark is synthetic. The numbers in the README come from injected faults with known answers. That is the only way to score a repair tool honestly, and it is still not your production data.
- It is version 0.9. Use it to review and to gate. Do not leave it alone with production yet. ## Try to break it
Go back to the two rows at the start. The alert cleared and the dashboard went green, and nothing in the tooling could tell a cleared alert from a correct table. DataRanger is my attempt at that difference: fix only what the source can confirm, and page a person for the rest.
It is open source under the MIT license.
- Code: github.com/akshaysharma1088/dataranger
- Docs: akshaysharma1088.github.io/dataranger
- Small first tasks: good first issues If the tutorial was useful, a star on the repo helps other data engineers find it.
One question for the comments, and I mean it: where would checking against control totals still let a wrong fix through? If you can think of a case, post it. The best ones become test cases.


