# Dataset Dedupe by Rules: URL, E-mail, Phone + Review (`bardach_technologies/dataset-dedupe-match-rules`) Actor

Remove duplicates from Apify datasets and JSON, JSONL or CSV files with ordered rules: exact, text, URL, domain, phone, e-mail and number tolerance. See which rule matched. Fuzzy matches are never merged: they go to a review list with score and reason.

- **URL**: https://apify.com/bardach_technologies/dataset-dedupe-match-rules.md
- **Developed by:** [Bardach Technologies](https://apify.com/bardach_technologies) (community)
- **Categories:** Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.30 / 1,000 compared rows

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

**Dataset Dedupe by Rules** removes duplicates from your scraped data using rules you can read and change: exact values, normalised text, URL, domain, phone, e-mail and number tolerance. Give it Apify datasets or links to JSON, JSONL or CSV files, list your rules in order, and get the unique rows plus a record of which rule matched which rows and why.

**Fuzzy matching never merges anything.** A `fuzzy_review` rule only lists similar pairs, with a score and a reason, so a person can decide. If you want similar names merged automatically, this is not the right tool.

### What you get

| Record (`_dedupe.recordType`) | What it is |
|---|---|
| `unique` | Your row, unchanged apart from the `_dedupe` details and any fields you chose to fill. `_dedupe.compared` says whether any rule could compare it |
| `duplicate_group` | One group: the kept row, the members, and each match with its rule and reason (optional) |
| `needs_review` | Two rows a `fuzzy_review` rule found similar. Not merged: both stay in the output. Holds `score`, `reason` and where the rows came from |
| `invalid` | A record that could not be used: where it was and why, without its content |
| `summary` | Input, unique, duplicate and invalid counts, in total and per rule |

Records always come in this order. The `OUTPUT` record gives two ready query strings for the dataset's items link: `uniqueRowsQuery` (for example `limit=5120&omit=_dedupe`) for the clean rows and `reviewRowsQuery` for the review list alone.

### How to use it

1. Add **Dataset IDs**, **File URLs**, or both.
2. Write your **match rules**. The first rule is applied first.
3. Choose **which row stays** and whether empty fields are filled from its duplicates.
4. Start the run. Without data it runs on a small sample for free, so you can see the output.

```json
{
  "datasetIds": ["WkzbQMuFYuamGv3YF"],
  "fileUrls": ["https://files.example.com/leads.csv"],
  "rules": [
    { "id": "same-site", "type": "normalized_url", "fields": ["website"] },
    { "id": "same-mail", "type": "email", "fields": ["email"] },
    { "id": "same-price", "type": "numeric", "fields": ["price"], "blockFields": ["sku"], "tolerance": 0.5 },
    { "id": "similar-name", "type": "fuzzy_review", "fields": ["company"], "blockFields": ["city"], "threshold": 0.85 }
  ],
  "survivor": "most_complete",
  "mergeEmptyFields": true
}
```

### Match rules

| Type | Rows match when | Merges? |
|---|---|---|
| `exact` | The values are identical (`1` and `"1"` differ; key order inside objects does not matter) | Yes |
| `normalized_text` | Equal apart from case, repeated spaces, invisible characters and punctuation at the edge of a word (`Acme, Inc.` = `acme inc`) | Yes |
| `normalized_url` | Same address, ignoring http/https, `www.`, the scheme's own default port, `#` parts, trailing slashes, query order and tracking parameters such as `utm_*`, `gclid`, `fbclid` | Yes |
| `domain` | Same host name without `www.` (`shop.example.com` and `example.com` differ) | Yes |
| `phone` | Same number after normalising, extension included; compared as hashes only | Yes |
| `email` | Same valid address, ignoring case and `mailto:`; compared as hashes only | Yes |
| `numeric` | Equal `blockFields` and a difference within `tolerance`, measured from the lowest value of the cluster, so a chain of small steps does not merge | Yes |
| `fuzzy_review` | Similar text. See below | **Never** |

`normalized_text` is deliberately strict. Accents, signs, symbols and punctuation inside a word all count, so these stay apart: `Müller` / `Muller`, `Maße` / `Masse`, `C++` / `C#`, `(-5)` / `(5)`, `5 %` / `5`, `1.5` / `1/5`, `1,000` / `1.000`.

Values that are not usable never match and are not billed: empty text, invisible characters, `[null]`, `["N/A"]`, `{"a":""}`, and placeholders in any spelling such as `N/A.`, `(none)`, `unknown!`, `-`. Over-long values are also refused for their rule: URLs above 8,192 characters, e-mails above 320, phone numbers above 64. Dates are not phone numbers, addresses with a user name are not URLs, and a value written without a scheme must end like a real host, so `main.py`, `Dr.No` and `v1.2` are not domains.

A rule with several `fields` needs all of them to match, field by field. With a single field that holds a list, one shared value is enough. Rules work together: if rule 1 joins A and B and rule 2 joins B and C, all three are one group.

#### What `fuzzy_review` does

The score runs from 0 to 1 and compares the two texts with case, Latin accents, punctuation and word order ignored. A pair at or above `threshold` (default 0.85) becomes a `needs_review` record with one of these reasons:

| Reason | Meaning |
|---|---|
| `same_words` | The same words, possibly in another order or split across fields differently |
| `possible_typo` | One or two words are one edit apart. This can still be two different names (`Stanford` / `Stamford`) |
| `numbers_differ` | Words holding a digit differ or come in another order (`Store 12` / `Store 13`) |
| `words_differ` | Other differences |

**Expect misses.** This rule finds spelling slips, not different ways of writing a name: `Acme Corp` / `Acme Corporation` and `123 Main Street` / `123 Main St` usually score below the threshold and are not listed at all. Many listed pairs are not duplicates. Lowering the threshold finds more and lists more noise.

Candidates are rows sharing `blockFields`, or, without them, the first four letters of a word. A block over 200 rows is not compared, texts over 4,096 characters are not compared, and comparisons are limited per run by count (500 per input row, at least 20,000, at most 5 million) and by a work budget that grows with the rows billed. The summary reports `oversizeBlocks`, `rowsInOversizeBlocks` and `comparisonLimitReached` per rule. The `needs_review` records show the compared text, so do not use this rule on a field you do not want to see there.

### What is kept, and what is limited

Every run satisfies: input rows = valid + invalid, and valid = unique + duplicates.

- A row with no content at all (`{}`, only blanks or placeholders, only true/false flags) is invalid with reason `empty_row`: free and not written.
- A row with content that no rule could compare stays unique and is written **free, up to 5 per billed row (at least 100)**. Rows beyond that are not written; `uncomparedRowsNotWritten` counts them. Add a rule that covers them if you need them all.
- `invalid` and `needs_review` records are each listed up to 5 per billed row (at least 100, at most 10,000), best scores first. The totals in the summary are always complete.
- Rows nested more than 64 levels deep and rows too large to write are invalid, counted by reason.
- If nothing is comparable after 50,000 rows or 32 MB, the run stops free, because the rules do not fit the data. If at least 10,000 rows are unreadable and they outnumber readable rows nine to one, it also stops free.
- A rule that finds no value fails a small run free, since that nearly always means a misspelled field. On a larger run where other rules did compare rows, the run finishes and names the rule in `rulesWithoutValues`.

### Same input, same output

Rows are read in the order given and every tie has a fixed rule, so the same input and settings give the same result. If a run is restarted it reads the input again and checks a digest of it. If the digest matches, it continues after the last row already written. If the input changed in between, the run stops rather than mix two versions.

### Limits

| Limit | Default | Highest |
|---|---|---|
| Input rows per run | 1,000,000 | 5,000,000 |
| Input size per run | 1,024 MB | 4,096 MB |
| Size of one row | 1,024 KB | 5,120 KB |
| Datasets, files | 20 each | 20 each |
| Download time per file | 1 hour | 1 hour |

At a row or size limit, or at your maximum charge, reading stops and the run ends as `stoppedEarly`: the result is correct for the rows read. If the disk fills up, the run fails without a charge; more memory also gives more disk.

**Memory.** Datasets are read in pages that are sized by bytes: the first page holds 10 items, then each page holds as many items as fit in about 32 MB of JSON (at most 1,000). A single item can be as large as the platform allows (about 9 MB), so a page of very large items is small. Files are read in 64 KB chunks and one row at a time. Not measured on the platform.

**Web pages are refused.** A file link that answers with a web page (an HTML or XML content type, or a body that starts with `<`) is refused whatever `fileFormat` you chose: the run stops with a clear message, nothing is parsed and nothing is charged.

**Names shown back.** Rule ids, field names, dataset ids, file host names and unknown option names that you typed are shown in the result and in messages with phone numbers, e-mail addresses and digit chains of 8 or more digits replaced by `[removed]`. Matching still uses what you typed.

Not supported: compressed files, Excel files, password-protected links, automatic fuzzy merging, and matching phonetic or translated names.

### CSV exports and formulas

Your values are written unchanged. A value such as `=HYPERLINK(...)` stays a formula when the dataset's CSV export is opened in a spreadsheet. If your data comes from strangers, sanitise it first, for example with Dataset Export to XLSX, CSV and Parquet.

### Which dedupe Actor?

Use **Dataset Merge & Deduplicate** (`dataset-merge-dedup`) to combine datasets and drop rows with identical field values, with keep-first or keep-last and resume by position. Use this Actor when you need files as input, normalised URL, e-mail, phone or number rules, an audit trail of why rows matched, or a review list of similar pairs.

### Your data

Row values are never written to the log. Phone and e-mail rules store and compare hashes in their working index, and group rows show no hash or value for them. Your rows are in the run's working folder only while it runs, and the result stays in your own run's storage.

### Pricing

**USD 0.30 per 1,000 compared rows, with a minimum of USD 0.03 per run** (100 rows), plus Apify's small start fee. A compared row is one that at least one of your rules could compare, whether it turns out unique or duplicate.

A run is billed for the largest of three figures:

| Figure | Example |
|---|---|
| Compared rows | 5,000 compared rows: USD 1.50 |
| The minimum of 100 rows | 1 compared row: USD 0.03 |
| One row per 256 KB of data read | 1 compared row and 1 GB of data: 4,096 rows, USD 1.23 |

`OUTPUT` shows `billableRows` (compared), `bytesRead`, `chargedRows` (billed) and `chargeBasis` (which figure applied).

Free: runs that compared nothing, the sample data, failed runs, and rows that are invalid, empty or not comparable. Their size still counts towards the 256 KB figure when the run compared something, because they had to be read.

The charge is made once, after the whole result is written. If a restart interrupts it, it is not sent again, so you are not billed twice. A run with a maximum charge stops reading before going over it, and a limit below the minimum is refused before anything is read.

### Run outcomes

`OUTPUT.outcome` is `complete`, `stoppedEarly` (with `stopReason`: `maxCharge`, `maxInputRows` or `maxInputBytes`) or `failed`. A failed run explains why in its status message.

# Actor input Schema

## `datasetIds` (type: `array`):

Apify datasets to read, in this order, up to 20. Through the API pass dataset IDs or username~dataset-name. Datasets are read before files.

## `fileUrls` (type: `array`):

Public http(s) links to JSON (array of objects), JSONL or CSV files, up to 20. Standard ports and host names only: IP addresses, private hosts and links with a user name are refused, also after a redirect. Compressed files are not supported.

## `fileFormat` (type: `string`):

Auto looks at the first bytes of each file.

## `csvDelimiter` (type: `string`):

Comma, semicolon, tab or pipe.

## `rules` (type: `array`):

1 to 10 rules; earlier rules are applied first. Each rule: type (exact, normalized_text, normalized_url, domain, phone, email, numeric, fuzzy_review) and fields (1 to 5; dots reach nested values, all fields must have a value). numeric also needs tolerance and blockFields. fuzzy_review never merges: it lists similar pairs for review, and takes threshold (0.70 to 0.99, default 0.85) and optional blockFields. Optional id names the rule in the output.

## `survivor` (type: `string`):

first: earliest row read. latest: newest value in the date field below. most_complete: most filled fields, earliest row on a tie.

## `latestField` (type: `string`):

Field with an ISO date or a Unix time. Needed when the latest row should stay.

## `mergeEmptyFields` (type: `boolean`):

Empty fields of the kept row are filled from its duplicates. Existing values are never changed.

## `outputDuplicateGroups` (type: `boolean`):

Adds one row per group: its members and which rule joined them, and why.

## `defaultCountryCode` (type: `string`):

Calling code such as 49 or +1, for phone numbers written without one. Without it, such numbers only match each other.

## `maxInputRows` (type: `integer`):

Reading stops here and the result covers the rows read so far.

## `maxInputMegabytes` (type: `integer`):

Reading stops at this many megabytes of input.

## `maxRowKilobytes` (type: `integer`):

Larger rows are counted as invalid and reported.

## Actor input object example

```json
{
  "fileFormat": "auto",
  "csvDelimiter": ",",
  "rules": [
    {
      "type": "normalized_url",
      "fields": [
        "url"
      ]
    },
    {
      "type": "email",
      "fields": [
        "email"
      ]
    },
    {
      "type": "fuzzy_review",
      "fields": [
        "company"
      ],
      "threshold": 0.85
    }
  ],
  "survivor": "most_complete",
  "mergeEmptyFields": true,
  "outputDuplicateGroups": true,
  "maxInputRows": 1000000,
  "maxInputMegabytes": 1024,
  "maxRowKilobytes": 1024
}
```

# Actor output Schema

## `results` (type: `string`):

Unique rows first, then duplicate groups, pairs to review (never merged), invalid rows and one summary row. \_dedupe.recordType tells them apart.

## `summary` (type: `string`):

Counts in total and per rule, the outcome, the rows charged and the query strings for the unique rows and the review list.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "rules": [
        {
            "type": "normalized_url",
            "fields": [
                "url"
            ]
        },
        {
            "type": "email",
            "fields": [
                "email"
            ]
        },
        {
            "type": "fuzzy_review",
            "fields": [
                "company"
            ],
            "threshold": 0.85
        }
    ],
    "survivor": "most_complete",
    "mergeEmptyFields": true
};

// Run the Actor and wait for it to finish
const run = await client.actor("bardach_technologies/dataset-dedupe-match-rules").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "rules": [
        {
            "type": "normalized_url",
            "fields": ["url"],
        },
        {
            "type": "email",
            "fields": ["email"],
        },
        {
            "type": "fuzzy_review",
            "fields": ["company"],
            "threshold": 0.85,
        },
    ],
    "survivor": "most_complete",
    "mergeEmptyFields": True,
}

# Run the Actor and wait for it to finish
run = client.actor("bardach_technologies/dataset-dedupe-match-rules").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "rules": [
    {
      "type": "normalized_url",
      "fields": [
        "url"
      ]
    },
    {
      "type": "email",
      "fields": [
        "email"
      ]
    },
    {
      "type": "fuzzy_review",
      "fields": [
        "company"
      ],
      "threshold": 0.85
    }
  ],
  "survivor": "most_complete",
  "mergeEmptyFields": true
}' |
apify call bardach_technologies/dataset-dedupe-match-rules --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,bardach_technologies/dataset-dedupe-match-rules"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/ZZ0bBl0WcJIDoXzbj/builds/QSUZgLfA3btDniv10/openapi.json
