Pii Pattern Redactor avatar

Pii Pattern Redactor

Pricing

$0.01 / actor start

Go to Apify Store
Pii Pattern Redactor

Pii Pattern Redactor

Pricing

$0.01 / actor start

Rating

0.0

(0)

Developer

Eichan Jolly

Eichan Jolly

Maintained by Community

Actor stats

0

Bookmarked

2

Total users

1

Monthly active users

3 days ago

Last modified

Categories

Features

Limited permissions

Share

Actor slug: pii-pattern-redactor
Store category: AI
Runtime: Python 3.12 standard library only; no Apify SDK, login, external LLM, or third-party AI service.

What it does

Take one user-supplied text string and replace detected patterns with [EMAIL], [PHONE], or [CARD]. Emit one Dataset item with redacted text and counts only; the findings array never contains matched values.

Who it is for

Developers who want a quick local, deterministic first-pass filter for logs, support content, prompts, or sample data before further handling. Do not use this as a standalone privacy/security control.

Method

  • EMAIL: a conservative, ASCII-oriented email-address regular expression.
  • CARD: 13–19 ASCII digits, either contiguous or separated by single spaces or hyphens. Only candidates that pass the Luhn checksum are replaced. Unsuccessful card candidates are excluded from partial phone matches.
  • PHONE: plausible phone-like groupings (7–15 digits including optional country code, punctuation and spaces), plus unformatted 10–12-digit sequences. Fixed-group formatted phone boundaries are checked first so two phone numbers separated by a space are not accidentally treated as one number or a rejected card candidate. Pattern shape and digit length are checked; no country-specific telephone validation occurs.
  • Match priority is EMAIL → CARD → PHONE, then matching spans are replaced left-to-right without overlaps. Every run is deterministic.
  • findings counts are ordered EMAIL, PHONE, CARD, and only nonzero categories are present. No raw values, offsets, or snippets are placed in findings or terminal logs.

Input

Required text (string): 1–100,000 Unicode code points; whitespace-only strings are rejected. The prefilled Actor input schema contains the working sample below.

Output fields

redactedText (string or null on error), findings (list of { "type": "EMAIL|PHONE|CARD", "count": integer } objects, never raw values), totalRedactions (integer), status (success or error), and error (null or readable message). No matches is a successful item with the original text, findings: [], and totalRedactions: 0.

Limits, false positives and safety warning

This is pattern matching. It can miss real personal data and can flag look-alikes. It is NOT a compliance, privacy, or safety guarantee. Do not assume the result is anonymized, de-identified, GDPR/CCPA/HIPAA-compliant, PCI-safe, or safe to publish.

  • Does not recognize names, addresses, IDs, free-form disclosures, many international/local phone formats, non-ASCII emails, or obfuscated values.
  • Luhn is a checksum, not proof that a number is an issued card. Conversely, an incorrectly entered card number fails Luhn and is not labeled as CARD.
  • Phone-like sequences can be mistaken for order numbers. Unformatted telephone patterns have conservative size limits; numbers outside them may remain.
  • If no pattern matches, input text is returned unchanged, even if it still contains sensitive information. Manually review outputs before sharing.
  • There is no content fetching or external AI API. On Apify, input/output do traverse Apify platform storage via its native REST API; this Actor does not send content to a separate service.
  • Invalid input yields one status: "error" Dataset item and a nonzero exit after saving it.

Working input example (also the exact schema prefill)

{
"text": "Email me at sam@example.org or call +1 415-555-2671. Test card: 4111 1111 1111 1111."
}

Actual output example (from script-mode smoke run)

{
"redactedText": "Email me at [EMAIL] or call [PHONE]. Test card: [CARD].",
"findings": [
{
"type": "EMAIL",
"count": 1
},
{
"type": "PHONE",
"count": 1
},
{
"type": "CARD",
"count": 1
}
],
"totalRedactions": 3,
"status": "success",
"error": null
}

How to run locally

From this Actor folder with Python 3.12+:

# Bash/macOS/Linux: reuse the proven sample input.
ACTOR_INPUT_JSON="$(cat tests/sample_input.json)" python src/main.py

Or create storage/key_value_stores/default/INPUT.json containing the input JSON, then run python src/main.py. Local Dataset items appear in storage/datasets/default/000000001.json (with increasing sequence numbers). You can override the storage root with APIFY_LOCAL_STORAGE_DIR.

Apify platform behavior (no SDK)

The Actor selects input in this order:

  1. ACTOR_INPUT_JSON (when set, even if it contains invalid JSON; invalid input is reported instead of silently falling through).
  2. When APIFY_DEFAULT_KEY_VALUE_STORE_ID exists: GET https://api.apify.com/v2/key-value-stores/{id}/records/INPUT with Authorization: Bearer {APIFY_TOKEN}.
  3. Otherwise: local ./storage/key_value_stores/default/INPUT.json (or the APIFY_LOCAL_STORAGE_DIR equivalent).

On the platform, one result is appended to POST https://api.apify.com/v2/datasets/{APIFY_DEFAULT_DATASET_ID}/items using the runtime token. The Actor does not require customers to provide an API key or log in to a third-party service. Both storage requests have a 20-second timeout; network, HTTP, and TLS certificate problems return readable errors without tracebacks. No custom API base URL validation is imposed.

Reproducible verification

  • python -m unittest discover -s tests -v runs included automated tests, including direct subprocess script mode and local REST mocks.
  • python tests/run_smoke.py re-runs the actual python src/main.py with the schema prefill, saves a local Dataset record, and regenerates tests/smoke_evidence.md, tests/smoke_stdout.txt, and tests/smoke_dataset_item.json.
  • python tests/run_regression_smoke.py runs the corrected two-phone case and the mixed-text case via real subprocess execution and saves their Dataset records and terminal outputs under tests/regression_smoke/.
  • tests/unittest_terminal.txt, tests/smoke_evidence.md, and tests/regression_smoke/evidence.md contain captured outputs from the delivery verification. Live Docker builds and Apify-platform deployment were not executed.

Store category and suggested pricing

Category: AI (data preparation utility). Suggested pricing: USD $0.005 per completed run; suggestion only. It is recorded in store_metadata.json. No publishing or billing setup was performed.