# Privacy Scanner: Multi-Layer PII Detection for Enterprise Data Protection

privacy
pii-detection
data-protection
compliance
Author

AI Tools Suite

Published

December 23, 2024

## Introduction

In an era where data breaches make headlines daily and privacy regulations like GDPR, CCPA, and HIPAA impose significant penalties for non-compliance, organizations need robust tools to identify and protect sensitive information. The Privacy Scanner is a production-grade PII (Personally Identifiable Information) detection system designed to help data teams, compliance officers, and developers identify sensitive data before it causes problems.

Unlike simple regex-based scanners that generate excessive false positives, the Privacy Scanner employs an eight-layer detection pipeline that balances precision with recall. It can detect not just obvious PII like email addresses and phone numbers, but also deliberately obfuscated data, encoded secrets, and international formats that simpler tools miss entirely.

## The Challenge of Modern PII Detection

Traditional PII scanners face several limitations. They struggle with obfuscated data where users write “john [at] example [dot] com” to evade detection. They cannot decode Base64-encoded secrets hidden in configuration files. They miss spelled-out numbers like “nine zero zero dash twelve dash eight eight two one” that represent Social Security Numbers. And they fail entirely on non-Latin character sets, leaving Greek, Cyrillic, and other international data completely unscanned.

The Privacy Scanner addresses each of these challenges through its multi-layer architecture, processing text through successive detection stages that build upon each other.

## Architecture: The Eight-Layer Detection Pipeline

### Layer 1: Standard Regex Matching

The foundation layer applies over 40 carefully crafted regular expression patterns to identify common PII types. These patterns detect email addresses, phone numbers (US and international), Social Security Numbers, credit card numbers, IP addresses, physical addresses, IBANs, and cloud provider secrets from AWS, Azure, GCP, GitHub, and Stripe.

Each pattern is designed for specificity. For example, the SSN pattern requires explicit separators (dashes, dots, or spaces) to avoid matching random nine-digit sequences. Credit card patterns validate against known issuer prefixes before flagging potential matches.

### Layer 2: Text Normalization

This layer transforms obfuscated text back to its canonical form. It converts “[dot]” and “(dot)” to periods, “[at]” and “(at)” to @ symbols, and removes separators from numeric sequences. Spaced-out characters like “t-e-s-t” are joined back together. After normalization, Layer 1 patterns are re-applied to catch previously hidden PII.

### Layer 2.5: JSON Blob Extraction

Modern applications frequently embed data within JSON structures. This layer extracts JSON objects from text, recursively traverses their contents, and scans each string value for PII. A Stripe API key buried three levels deep in a JSON configuration will be detected and flagged as `STRIPE_KEY_IN_JSON`.

### Layer 2.6: Base64 Auto-Decoding

Base64 encoding is commonly used to hide secrets in configuration files and environment variables. This layer identifies potential Base64 strings, decodes them, validates that the decoded content appears to be meaningful text, and scans the result for PII. An encoded password like `U2VjcmV0IFBhc3N3b3JkOiBBZG1pbiExMjM0NQ==` will be decoded and the contained password detected.

### Layer 2.7: Spelled-Out Number Detection

This NLP-lite layer converts written numbers to digits. The phrase “nine zero zero dash twelve dash eight eight two one” becomes “900-12-8821”, which is then checked against SSN and other numeric patterns. This catches attempts to evade detection by spelling out sensitive numbers.

### Layer 2.8: Non-Latin Character Support

For international data, this layer transliterates Greek and Cyrillic characters to Latin equivalents before scanning. It also directly detects EU VAT numbers across all 27 member states using country-specific patterns. A Greek customer record with “EL123456789” as a VAT number will be properly identified.

### Layer 3: Context-Based Confidence Scoring

Raw pattern matches are adjusted based on surrounding context. Keywords like “ssn”, “social security”, or “card number” boost confidence scores. Anti-context keywords like “test”, “example”, or “batch” reduce confidence. Future dates are penalized when detected as potential birth dates since people cannot be born in the future.

### Layer 4: Checksum Verification

The final layer validates detected patterns using mathematical checksums. Credit card numbers are verified using the Luhn algorithm. IBANs are validated using the MOD-97 checksum. Numbers that fail validation are either discarded or reclassified as “POSSIBLE_CARD_PATTERN” with reduced confidence, dramatically reducing false positives.

## Security Architecture

The Privacy Scanner implements privacy-by-design principles throughout its architecture.

Ephemeral Processing: All data processing occurs in memory using DuckDB’s `:memory:` mode. No PII is ever written to persistent storage or log files. Temporary files used for CSV parsing are immediately deleted after processing.

Client-Side Redaction Mode: For ultra-sensitive deployments, the scanner offers a coordinates-only mode. In this configuration, the backend returns only the positions (start, end) and types of detected PII without the actual values. The frontend then performs masking locally, ensuring that sensitive data never leaves the user’s browser in its raw form.

## Detection Categories

The scanner organizes detected entities into severity-weighted categories:

Critical (Score 95-100): SSN, Credit Cards, Private Keys, AWS/Azure/GCP credentials High (Score 80-94): GitHub tokens, Stripe keys, passwords, Medicare IDs Medium (Score 50-79): IBAN, addresses, medical record numbers, EU VAT numbers Low (Score 20-49): Email addresses, phone numbers, IP addresses, dates

Risk scores aggregate these weights with confidence levels to produce an overall assessment ranging from LOW to CRITICAL.

## Practical Applications

Pre-Release Data Validation: Before sharing datasets with partners or publishing to data marketplaces, scan for inadvertent PII inclusion.

Log File Auditing: Scan application logs, error messages, and debug output for accidentally logged credentials or customer data.

Document Review: Check contracts, reports, and documentation for sensitive information before distribution.

Compliance Reporting: Generate evidence of PII detection capabilities for GDPR, CCPA, or HIPAA audit requirements.

Developer Tooling: Integrate into CI/CD pipelines to catch secrets committed to version control.

## Conclusion

The Privacy Scanner represents a significant advancement over traditional pattern-matching approaches to PII detection. Its eight-layer architecture handles real-world data complexity including obfuscation, encoding, internationalization, and contextual ambiguity. Combined with privacy-preserving processing modes and comprehensive detection coverage, it provides organizations with a practical tool for managing sensitive data risk.

Whether you are a data engineer preparing datasets for machine learning, a compliance officer auditing data flows, or a developer building privacy-aware applications, the Privacy Scanner offers the depth of detection and operational flexibility needed for production environments.