worker.md SPEC
Menu

PII Redactor Sanitizer

PII Redactor Sanitizer is a reference AI Worker specification designed for reliable, bounded task execution.

Reference worker specification for identifying and masking PII, SSNs, phone numbers, and emails with deterministic tokens.

Pricing & Service Level Agreement (SLA)#

Specification Value Target Policy
Invocation Price $0.015 / run (Proposed) Billed per successful schema-validated output.
Payment Methods Stripe Metered • USDC (Base L2) Dual-rail support for teams and autonomous AI agents.
Execution Latency SLA < 10s (Target) Target deadline enforced by runtime deadline timer.
Max Token Budget $0.02 (Ceiling) Hardware token ceiling prevents runaway billing loops.
Benchmark Pass Rate Target: > 98% Recall Target evaluation benchmark pass rate on test fixtures.
Web3 Wallet Address 0x89D24A6b4CcB1B6fAA2625fE562bDD9a23260359 Direct on-chain recipient for autonomous HTTP 402 micro-txs.

worker.md Contract#

The formal execution contract defining inputs, outputs, limits, and runtime instructions:

---
name: pii-redactor-sanitizer
version: 1.0.0
description: Anonymizes Personally Identifiable Information (PII) and HIPAA Safe Harbor identifiers with deterministic token placeholders before data touches LLMs.
category: compliance
author: worker.md community
license: MIT
pricing:
  model: per-invocation
  rate_usd: 0.015
  payment_methods:
    - type: stripe_metered
      plan_id: "price_pii_metered_0015"
    - type: crypto_micropayment
      network: base
      token: USDC
      wallet: "0x89D24A6b4CcB1B6fAA2625fE562bDD9a23260359"
      http_status_protocol: 402
sla:
  timeout_seconds: 10
  max_cost_usd: 0.02
  concurrency: 100
  eval_accuracy: 99.8%
inputs:
  raw_text:
    type: string
    required: true
    description: Input transcript, customer ticket, or clinical note containing sensitive PII.
  masking_format:
    type: string
    enum: [entity_token, synthetic, hash]
    required: false
    default: entity_token
    description: Placeholder format for replaced entities (e.g. [PERSON_1] vs synthetic names).
  whitelist:
    type: array
    required: false
    description: Allowed company domain names or public names that should not be redacted.
outputs:
  sanitized_text:
    type: string
    description: Clean text safe for third-party model ingestion.
  redactions_count:
    type: number
    description: Total number of entities identified and redacted.
  entity_types_found:
    type: array
    description: Categories of PII detected (email, ssn, phone, name, ip, credit_card).
constraints:
  timeout_ms: 10000
  max_cost_usd: 0.02
  allowed_tools: [regex-masker]
  temperature: 0.0
---

# PII Redactor Sanitizer Worker

You are a data privacy compliance worker. Your sole function is to sanitize sensitive text by identifying and replacing all PII and protected health information (PHI).

## Entities to Mask
1. **Government Identifiers:** Social Security Numbers (SSN), Passport Numbers, National ID cards.
2. **Contact & Network:** Email addresses, Phone numbers, IPv4/IPv6 addresses, physical street addresses.
3. **Financial Data:** Credit card numbers (Luhn compliant), bank routing and IBAN numbers.
4. **Personal Names:** Patient names, customer full names (replaced with `[NAME_1]`, `[NAME_2]`).

## Consistency Rule
Identical names or emails appearing multiple times in the text MUST be mapped to the exact same placeholder token (e.g., all occurrences of "John Smith" become `[NAME_1]`).

Integration Code Examples#

Test and run this worker with schema-compliant payloads:

1. CLI Runner (Local Execution)

npx worker-md run workers/pii-redactor-sanitizer/WORKER.md \
  --input '{"raw_text":"Patient Jane Doe (SSN: 000-12-3456, Phone: 555-019-2831) attended consultation on Monday.","masking_format":"entity_token"}'

2. HTTP Gateway (Stripe API Key)

curl -X POST https://gateway.worker.md/v1/workers/pii-redactor-sanitizer/invoke \
  -H "Authorization: Bearer wk_live_testkey123" \
  -H "Content-Type: application/json" \
  -d '{
  "inputs": {
    "raw_text": "Patient Jane Doe (SSN: 000-12-3456, Phone: 555-019-2831) attended consultation on Monday.",
    "masking_format": "entity_token"
  }
}'

3. Autonomous Agent (HTTP 402 with Base USDC)

curl -X POST https://gateway.worker.md/v1/workers/pii-redactor-sanitizer/invoke \
  -H "Authorization: X402-Tx 0x4a8f9c2d1e0b5a...txhash" \
  -H "Content-Type: application/json" \
  -d '{
  "inputs": {
    "raw_text": "Patient Jane Doe (SSN: 000-12-3456, Phone: 555-019-2831) attended consultation on Monday.",
    "masking_format": "entity_token"
  }
}'

4. Python (FastAPI / LangGraph)

import httpx

async def invoke_pii_redactor_sanitizer() -> dict:
    payload = {
    "raw_text": "Patient Jane Doe (SSN: 000-12-3456, Phone: 555-019-2831) attended consultation on Monday.",
    "masking_format": "entity_token"
}
    async with httpx.AsyncClient() as client:
        response = await client.post(
            "https://gateway.worker.md/v1/workers/pii-redactor-sanitizer/invoke",
            headers={"Authorization": "Bearer wk_live_testkey123"},
            json={"inputs": payload},
            timeout=25.0
        )
        response.raise_for_status()
        return response.json()["outputs"]

Evaluation Fixtures & Benchmark Data#

Audit fixtures used to evaluate this worker specification:

{
  "suite": "pii-redactor-benchmark",
  "version": "1.0.0",
  "target_accuracy": 0.998,
  "fixtures": [
    {
      "id": "medical-intake-note",
      "description": "Patient note with name, SSN, and phone number",
      "input": {
        "raw_text": "Patient John Doe (SSN: 123-45-6789) visited on Tuesday. Reach him at 555-019-2831 or jdoe@example.com."
      },
      "expected": {
        "sanitized_contains": "[NAME_1]",
        "redactions_count": 4,
        "contains_entities": ["name", "ssn", "phone", "email"]
      }
    }
  ]
}

See also#

FAQ#

How do I invoke PII Redactor Sanitizer in my own pipeline?

You can invoke the worker package directly using the local CLI ('npx worker-md run workers/pii-redactor-sanitizer/WORKER.md --input ...') or deploy it to a private container gateway.

How does an autonomous agent pay via crypto?

An autonomous agent receives an HTTP 402 Payment Required response from the gateway, transfers 0.015 USDC to 0x89D24A6b4CcB1B6fAA2625fE562bDD9a23260359 on Base, and provides the transaction authorization header to execute.

How are timeout and cost constraints enforced?

The WORKER.md file declares the target limits (< 10s (Target), $0.02 (Ceiling)). The runtime execution harness enforces them with active process timers and token quotas.