# PII Masking (`canadesk/pii-masking`) Actor

Identify, mark and replace PII information.

- **URL**: https://apify.com/canadesk/pii-masking.md
- **Developed by:** [Canadesk Support](https://apify.com/canadesk) (community)
- **Categories:** SEO tools, Integrations, Other
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, NaN bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per event

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/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## PII Redaction (PPE)

This Apify Actor redacts PII/PHI/PCI from text using a remote redaction API.

### What it does

* Takes either:
  * `INPUT.text` (a string or array of strings), **or**
  * `INPUT.datasetId` (reads items from an existing dataset and redacts selected fields)
* Sends text to a redaction API for entity detection + redaction (marker or mask)
* Makes **one API call per input text**
* Writes multiple output records:
  * one record per **sentence** (`type: "sentence"`)
  * one record per **entity** (`type: "entity"`)

### Pricing (PPE)

The Actor uses Pay-Per-Event.

* **Event:** `REDACTION_REQUEST` (configurable via `chargeEventName`)
* **Charged per output entry:** One PPE event per dataset record pushed.
  * each `type: "sentence"` record charges once
  * each `type: "entity"` record charges once

This matches Apify's PPC/PPE design where **events correspond to output units**.

### Input

| Parameter | Type | Default | Description |
|---|---:|---:|---|
| `apiKey` | String | (optional) | API key (sent as `x-api-key`). Use an Apify Secret in production. |
| `text` | String \| String[] |  | Text(s) to redact. |
| `datasetId` | String |  | Dataset to read items from. |
| `fieldPaths` | String[] | `["text"]` | Field paths (dot/bracket notation) to redact inside each dataset item, e.g. `"text"`, `"customer.message"`, `"items[0].note"`. |
| `split.enabled` | Boolean | `true` | Whether to split the **redacted output** into sentences for dataset records. |
| `hideit.endpoint` | String | (default set in code) | Override the redaction endpoint URL. |
| `hideit.entityTypes` | String[] | (sane default list) | Entity types to enable. |
| `hideit.outputMode` | String | `MARKER` | Redaction output mode: `MARKER` (replace with typed markers like `[NAME_1]`) or `MASK` (replace with a fixed token). |
| `hideit.maskToken` | String | `[REDACTED]` | Only used when `hideit.outputMode="MASK"`. |
| `hideit.markerPattern` | String | `[UNIQUE_NUMBERED_ENTITY_TYPE]` | Marker pattern for redaction output. |
| `hideit.markerLanguage` | String | `en` | Marker language. |
| `hideit.coreferenceResolution` | String | `heuristics` | Coreference setting supported by the endpoint. |
| `proxy` | Object |  | Optional Apify proxy configuration. |
| `chargeEventName` | String | `REDACTION_REQUEST` | PPE event name to charge. |

#### Output modes

* **MARKER**: returns structured placeholders like `[NAME_1]`, `[PHONE_NUMBER_1]`.
* **MASK**: returns a uniform token like `[REDACTED]`.

### Output dataset schema

Two kinds of output records are written:

#### Sentence records (`type: "sentence"`)

* `type`: `"sentence"`
* `source`: `"input.text"` or `"dataset"`
* `sourceMeta`: metadata like `index`, or `{ datasetId, itemIndex, fieldPath }`
* `sentenceIndex`, `sentencesTotal`
* `text` (one redacted sentence)
* `hideit` request metadata (endpoint + mode)
* `createdAt`

#### Entity records (`type: "entity"`)

* `type`: `"entity"`
* `source`, `sourceMeta`
* `entityIndex`, `entitiesTotal`
* `entity` (as returned by the endpoint)
* `createdAt`

### Notes

* Keep your API keys out of git. Prefer Apify Secrets.
* For very large datasets, you may want to implement pagination + concurrency. Current implementation reads the dataset first page only.

#### Length limits

* `limits.maxInputChars` (default: `10000`): if an input text exceeds this length, the actor logs `max reached`, truncates the text, and continues processing.

# Actor input Schema

## `text` (type: `array`):

One or more text inputs to redact.
## `datasetId` (type: `string`):

Optional. If set, the actor reads items from this dataset and redacts selected fields.
## `fieldPaths` (type: `array`):

When using datasetId, redact these fields in each item (dot/bracket notation).
## `hideit` (type: `object`):

Advanced settings for the redaction endpoint.
## `split` (type: `object`):

Controls sentence splitting of the redacted output.
## `limits` (type: `object`):

Safety limits. If text exceeds maxInputChars, it will be truncated and processed.
## `proxy` (type: `object`):

Select proxies to be used by your crawler.
## `chargeEventName` (type: `string`):

PPE event name to charge for each output entry.

## Actor input object example

```json
{
  "text": [
    "Hello John Matthews. Call me at 555-0100."
  ],
  "fieldPaths": [
    "text"
  ],
  "hideit": {
    "outputMode": "MARKER"
  },
  "split": {
    "enabled": true
  },
  "limits": {
    "maxInputChars": 10000
  },
  "proxy": {
    "useApifyProxy": true
  },
  "chargeEventName": "REDACTION_REQUEST"
}
````

# 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 = {
    "text": [
        "Hello John Matthews. Call me at 555-0100."
    ],
    "fieldPaths": [
        "text"
    ],
    "hideit": {
        "outputMode": "MARKER"
    },
    "split": {
        "enabled": true
    },
    "limits": {
        "maxInputChars": 10000
    },
    "proxy": {
        "useApifyProxy": true
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("canadesk/pii-masking").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 = {
    "text": ["Hello John Matthews. Call me at 555-0100."],
    "fieldPaths": ["text"],
    "hideit": { "outputMode": "MARKER" },
    "split": { "enabled": True },
    "limits": { "maxInputChars": 10000 },
    "proxy": { "useApifyProxy": True },
}

# Run the Actor and wait for it to finish
run = client.actor("canadesk/pii-masking").call(run_input=run_input)

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

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

```

## CLI example

```bash
echo '{
  "text": [
    "Hello John Matthews. Call me at 555-0100."
  ],
  "fieldPaths": [
    "text"
  ],
  "hideit": {
    "outputMode": "MARKER"
  },
  "split": {
    "enabled": true
  },
  "limits": {
    "maxInputChars": 10000
  },
  "proxy": {
    "useApifyProxy": true
  }
}' |
apify call canadesk/pii-masking --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=canadesk/pii-masking",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "PII Masking",
        "description": "Identify, mark and replace PII information.",
        "version": "3.0",
        "x-build-id": "mPALJTY34WkTvYSSN"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/canadesk~pii-masking/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-canadesk-pii-masking",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/canadesk~pii-masking/runs": {
            "post": {
                "operationId": "runs-sync-canadesk-pii-masking",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/canadesk~pii-masking/run-sync": {
            "post": {
                "operationId": "run-sync-canadesk-pii-masking",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "text": {
                        "title": "Text",
                        "type": "array",
                        "description": "One or more text inputs to redact.",
                        "items": {
                            "type": "string"
                        }
                    },
                    "datasetId": {
                        "title": "Dataset ID",
                        "type": "string",
                        "description": "Optional. If set, the actor reads items from this dataset and redacts selected fields."
                    },
                    "fieldPaths": {
                        "title": "Field paths",
                        "type": "array",
                        "description": "When using datasetId, redact these fields in each item (dot/bracket notation).",
                        "default": [
                            "text"
                        ],
                        "items": {
                            "type": "string"
                        }
                    },
                    "hideit": {
                        "title": "Redaction API",
                        "type": "object",
                        "description": "Advanced settings for the redaction endpoint."
                    },
                    "split": {
                        "title": "Output shaping",
                        "type": "object",
                        "description": "Controls sentence splitting of the redacted output."
                    },
                    "limits": {
                        "title": "Limits",
                        "type": "object",
                        "description": "Safety limits. If text exceeds maxInputChars, it will be truncated and processed."
                    },
                    "proxy": {
                        "title": "Proxy configuration",
                        "type": "object",
                        "description": "Select proxies to be used by your crawler."
                    },
                    "chargeEventName": {
                        "title": "Pricing event name",
                        "type": "string",
                        "description": "PPE event name to charge for each output entry.",
                        "default": "REDACTION_REQUEST"
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
