PII Detection and Masking

PocketPaw includes an opt-in PII detection and masking system that scans text for sensitive personal information and applies configurable actions before data is stored in memory, audit logs, or application logs.

Overview

When enabled, the PII scanner runs on:

  • User messages before saving to session memory
  • Assistant responses before saving to session memory
  • Audit log entries before writing to ~/.pocketpaw/audit.jsonl
  • Application logs via an optional log filter

The scanner is regex-based with pre-compiled patterns for performance. It runs on every matching text block and deduplicates overlapping matches.

Detected PII Types

TypePatternExample
SSNDashed format only123-45-6789
EmailStandard email addresses[email protected]
US PhoneMultiple formats(555) 123-4567, +1 555-123-4567
International PhoneCountry code + number+44 7911 123456
Credit Card (Visa)Starts with 4, 16 digits4111-1111-1111-1111
Credit Card (MasterCard)Starts with 51-555500-0000-0000-0004
Credit Card (Amex)Starts with 34/37, 15 digits3734-567890-12345
Credit Card (Discover)Starts with 6011/656011-1111-1111-1111
IPv4 AddressStandard notation192.168.1.100
Date of BirthContext-aware (needs “born”, “dob”, etc.)Born on 03/15/1990
Info

SSN detection uses dashed format only (XXX-XX-XXXX) to avoid false positives on bare 9-digit numbers. Date of birth detection requires proximity to keywords like “born”, “dob”, or “birthday” within 20 characters.

Actions

When PII is detected, one of three actions is applied:

ActionBehaviorExample Output
maskReplace with type label[REDACTED-EMAIL]
hashReplace with partial SHA-256[PII-SSN:a7f3e9c1d2b8]
logFlag in audit only, text unchangedOriginal text preserved

You can set a default action and override per PII type.

Configuration

Environment Variables

Terminal window
POCKETPAW_PII_SCAN_ENABLED=true # Enable PII scanning (default: false)
POCKETPAW_PII_DEFAULT_ACTION=mask # Default action: mask, hash, or log
POCKETPAW_PII_SCAN_MEMORY=true # Scan before writing to memory
POCKETPAW_PII_SCAN_AUDIT=true # Scan audit log entries
POCKETPAW_PII_SCAN_LOGS=true # Extend log scrubber with PII patterns

Config File (~/.pocketpaw/config.json)

{
"pii_scan_enabled": true,
"pii_default_action": "mask",
"pii_type_actions": {
"ssn": "hash",
"email": "mask",
"phone": "log"
},
"pii_scan_memory": true,
"pii_scan_audit": true,
"pii_scan_logs": true
}

Web Dashboard

Toggle PII scanning and configure actions from Settings > Security in the web dashboard.

Per-Type Action Overrides

Use pii_type_actions to set different actions for each PII type:

{
"pii_type_actions": {
"ssn": "hash",
"email": "mask",
"phone": "log",
"credit_card": "mask",
"ip_address": "log"
}
}

With this config:

  • SSN 123-45-6789 becomes [PII-SSN:a7f3e9c1d2b8]
  • Email [email protected] becomes [REDACTED-EMAIL]
  • Phone 555-123-4567 is logged but text stays unchanged

Scanning Existing Memory

Use the audit CLI to scan stored memory files for PII:

Terminal window
pocketpaw --audit --pii-scan

This scans all markdown files in ~/.pocketpaw/memory/ and session JSON files in ~/.pocketpaw/memory/sessions/, reporting findings without modifying the files.