PII Detection Fundamentals
What You'll Learn
You'll learn how to identify the most common types of personally identifiable information (PII) in LLM outputs to prevent privacy leaks and comply with regulations like GDPR and CCPA.
The Core Challenge
When LLMs generate responses, they may inadvertently include sensitive personal information—either echoed from training data, constructed from prompts, or hallucinated. PII detection is the practice of scanning text for structured patterns that identify real individuals, so you can redact, block, or flag outputs before they reach users.
Think of it like a TSA scanner for text: you're checking every output for "prohibited items" before it boards the flight to production.
The Big Five PII Types
The most critical categories to detect are:
- Email addresses:
user@example.com— structured with@and domain patterns - Phone numbers:
(555) 123-4567or+1-555-123-4567— digits with optional formatting - Social Security Numbers (SSNs):
123-45-6789— exactly 9 digits with specific formatting - Physical addresses:
123 Main St, Anytown, CA 12345— street numbers, names, cities, postal codes - Credit card numbers:
4532-1234-5678-9010— 13-19 digit sequences passing Luhn algorithm validation
Each type has characteristic patterns. Emails always contain @, phone numbers cluster 7-15 digits with delimiters, SSNs follow a fixed format, addresses combine numbers with location keywords, and credit cards have predictable length and checksum properties.
Detection Approaches
You can use regex patterns for structured data (emails, phones, SSNs), named entity recognition (NER) models for addresses, and checksum validation for credit cards. The goal is high recall—catching every instance—even if it means some false positives you'll handle downstream.
Key Takeaway: PII detection identifies five core types (emails, phones, SSNs, addresses, credit cards) using pattern matching and validation to prevent sensitive information from leaking through LLM outputs.