PII Removal
The PII Removal operation detects and removes personally identifiable information (PII) from messages to help ensure privacy compliance and data protection. It supports multiple PII types, replacement strategies, and format preservation options for comprehensive data sanitization.
Overview
Personally Identifiable Information (PII) poses significant privacy and compliance risks in AI systems. The PII Removal operation provides comprehensive protection by:
- Detecting Multiple PII Types - Emails, phone numbers, SSNs, credit cards, addresses, and more
- Flexible Handling Strategies - Redact, replace with realistic fake data, or remove entirely
- Format Preservation - Maintain document structure and readability while protecting privacy
- Compliance Support - Meet GDPR, CCPA, HIPAA, and other privacy regulations
- Custom Pattern Support - Define organization-specific PII patterns
The operation uses advanced pattern matching and contextual analysis to accurately identify PII while minimizing false positives that could disrupt legitimate content.
Configuration
Basic Configuration
const config = {
types: ['email', 'phone', 'ssn', 'credit_card'], // PII types to detect
replacementStrategy: 'redact', // How to handle detected PII
preserveFormat: true, // Preserve original format
customPatterns: [] // User-defined patterns
}
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
types | array | ['email', 'phone', 'ssn'] | PII types to detect |
replacementStrategy | string | 'redact' | How to handle detected PII |
preserveFormat | boolean | true | Preserve original format when replacing |
customPatterns | array | [] | Custom regex patterns for organization-specific PII |
confidenceThreshold | number | 0.8 | Minimum confidence score for PII detection |
Supported PII Types
| Type | Description | Detection Patterns |
|---|---|---|
email | Email addresses | RFC 5322 compliant patterns |
phone | Phone numbers | US/International formats |
ssn | Social Security Numbers | XXX-XX-XXXX, XXXXXXXXX |
credit_card | Credit card numbers | Visa, MasterCard, Amex, Discover |
ip_address | IP addresses | IPv4 and IPv6 formats |
address | Physical addresses | Street addresses with context |
name | Person names | First/last name combinations |
date_of_birth | Birth dates | Multiple date formats |
passport | Passport numbers | Various country formats |
license_plate | License plates | US state formats |
bank_account | Bank account numbers | 8-17 digit sequences |
routing_number | Bank routing numbers | 9-digit ABA numbers |
Replacement Strategies
| Strategy | Behavior | Example Output | Use Case |
|---|---|---|---|
redact | Replace with [REDACTED] | Contact me at [REDACTED] | Maximum privacy protection |
replace | Use realistic fake data | Contact me at jane@example.com | Maintain readability |
remove | Delete PII entirely | Contact me at | Minimal data retention |
mask | Partially obscure data | Contact me at j***@example.com | Balance privacy and context |
Examples
- REST API
- JavaScript SDK
- Python
curl -X POST https://api.meta-prompt.com/v1/process \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"messages": [
{
"role": "user",
"content": "Please contact John Smith at john.smith@company.com or call 555-123-4567. His SSN is 123-45-6789."
}
],
"operations": [
{
"name": "piiRemoval",
"config": {
"types": ["email", "phone", "ssn", "name"],
"replacementStrategy": "redact",
"preserveFormat": true
}
}
]
}'
Response:
{
"messages": [
{
"role": "user",
"content": "Please contact [REDACTED] at [REDACTED] or call [REDACTED]. His SSN is [REDACTED]."
}
],
"operations": [
{
"name": "piiRemoval",
"result": {
"detectedPii": [
{"type": "name", "value": "John Smith", "position": [14, 24]},
{"type": "email", "value": "john.smith@company.com", "position": [28, 51]},
{"type": "phone", "value": "555-123-4567", "position": [60, 72]},
{"type": "ssn", "value": "123-45-6789", "position": [85, 96]}
],
"replacementCount": 4
}
}
]
}
import { MetaPrompt } from '@meta-prompt/sdk-js';
const client = new MetaPrompt('YOUR_API_KEY');
// Basic PII removal
const result = await client.process(
[
{
role: 'user',
content: 'My credit card is 4111-1111-1111-1111 and email is user@domain.com'
}
],
[
{
name: 'piiRemoval',
config: {
types: ['email', 'credit_card'],
replacementStrategy: 'redact'
}
}
]
);
console.log(result.messages[0].content);
// Output: "My credit card is [REDACTED] and email is [REDACTED]"
// Advanced configuration with custom patterns
const advancedResult = await client.process(
[
{
role: 'user',
content: 'Employee ID: EMP-12345, call me at john@company.com'
}
],
[
{
name: 'piiRemoval',
config: {
types: ['email'],
replacementStrategy: 'replace',
customPatterns: [
{
name: 'employee_id',
pattern: 'EMP-\\d{5}',
replacement: 'EMP-XXXXX'
}
]
}
}
]
);
console.log(advancedResult.messages[0].content);
// Output: "Employee ID: EMP-XXXXX, call me at jane@example.com"