Skip to main content

PII Detection & Redaction

AxonFlow provides built-in detection and redaction of Personally Identifiable Information (PII) in LLM interactions. The system uses a hybrid approach combining fast regex-based pattern matching with intelligent validation to minimize false positives while maintaining sub-millisecond latency.

Supported PII Types

TypeSeverityExampleValidation
SSNCritical123-45-6789Area/group/serial rules
Credit CardCritical4532-0151-1283-0366Luhn algorithm
EmailMedium[email protected]RFC 5322 format
PhoneMedium(555) 123-4567Format + context
IP AddressMedium192.168.1.100IPv4 validation
IBANCriticalDE89370400440532013000MOD 97 checksum
PassportHighAB1234567Format + context
Date of BirthHigh01/15/1990Context-dependent
Bank AccountCritical021000021-123456789ABA routing checksum

How It Works

Two-Layer Detection

  1. Agent Layer (Static Engine): Fast regex-based detection (<1ms) that flags potential PII for downstream processing
  2. Orchestrator Layer (Enhanced Detector): Deep validation with Luhn, MOD 97, and context-aware confidence scoring

False Positive Prevention

The enhanced detector uses context analysis to reduce false positives:

Input: "Order number: 123-45-6789"
→ Context contains "order" → Low confidence (not flagged as SSN)

Input: "Customer SSN: 123-45-6789"
→ Context contains "SSN" → High confidence (flagged as SSN)

Configuration

Gateway Mode

PII detection is automatically enabled in Gateway Mode's pre-check and audit endpoints:

# Pre-check detects PII in prompts
curl -X POST https://api.example.com/api/policy/pre-check \
-H "Content-Type: application/json" \
-H "X-Client-Secret: your-secret" \
-d '{
"prompt": "Customer SSN: 123-45-6789",
"context": {}
}'

Response includes PII warnings:

{
"approved": true,
"policies": ["ssn_detection"],
"context_id": "ctx_abc123"
}

SDK Usage

Python

from axonflow import AxonFlow

client = AxonFlow(client_secret="your-secret")

# Pre-check with PII detection
result = await client.get_policy_approved_context(
prompt="Customer SSN: 123-45-6789",
context={"user_id": "user123"}
)

if "ssn_detection" in result.policies:
print("Warning: SSN detected in prompt")

TypeScript

import { AxonFlow } from 'axonflow';

const client = new AxonFlow({ clientSecret: 'your-secret' });

const result = await client.getPolicyApprovedContext({
prompt: 'Customer SSN: 123-45-6789',
context: { userId: 'user123' }
});

if (result.policies.includes('ssn_detection')) {
console.log('Warning: SSN detected in prompt');
}

Go

import "github.com/getaxonflow/axonflow-sdk-go"

client := axonflow.NewClient(axonflow.Config{
ClientSecret: "your-secret",
})

result, err := client.GetPolicyApprovedContext(ctx, axonflow.PreCheckRequest{
Prompt: "Customer SSN: 123-45-6789",
Context: map[string]interface{}{"userId": "user123"},
})

for _, policy := range result.Policies {
if policy == "ssn_detection" {
log.Println("Warning: SSN detected in prompt")
}
}

Redaction Strategies

When PII is detected, AxonFlow applies redaction based on user permissions:

StrategyPII TypesResult
MaskingSSN, Credit Card, PhoneXXX-XX-6789, ****-****-****-0366
HashingEmail[HASHED_16]
Full RedactionUnknown types[REDACTED]

Permission-Based Access

PermissionVisible PII Types
view_full_piiAll PII types
view_basic_piiEmail, Phone only
view_financialCredit Card, Bank Account
Admin roleAll (wildcard)

Performance

OperationLatencyNotes
Single type detection~1μsType-specific check
Full detection (no PII)~17μsAll patterns
Full detection (with PII)~25μsWith validation
Long text (10KB)~1.4msComprehensive scan

Compliance

AxonFlow's PII detection helps with compliance requirements:

RegulationSupported PII Types
PCI-DSSCredit card numbers, bank accounts
HIPAASSN, DOB, medical identifiers
GDPREmail, phone, address, IP
CCPASSN, driver's license

Best Practices

  1. Enable validation for financial data (credit cards, bank accounts)
  2. Use context to reduce false positives
  3. Set appropriate permissions based on user roles
  4. Log PII detection events for audit trails
  5. Test with realistic data to tune confidence thresholds

See Also