PII Detection
~2 min read
Concept & How It Works
Why Does It Exist?
Agents process user data, logs, and documents containing PII. Leaking PII in responses or traces violates GDPR/HIPAA and destroys trust.
Real-World Analogy
PII detection is a redaction pen that runs automatically — black out sensitive lines before they leave the building.
Visual Workflows
What is PII Detection?
Example
Scenario
User pastes SSN in chat; output guardrail redacts before display; trace stores `SSN-[REDACTED]` not the real number.
Solution
In Security & Guardrails, apply PII Detection to this scenario: User pastes SSN in chat; output guardrail redacts before display; trace stores `SSN-[REDACTED]` not the real number. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.
Practice Task
Do this before moving to the next module — reading alone is not enough.
Open the Code Walkthrough below and run it locally. Change one parameter related to PII Detection (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.
Code Walkthrough
Highlighted lines show where PII Detection happens in the code.
1from presidio_analyzer import AnalyzerEngine # import dependencies2analyzer = AnalyzerEngine()3results = analyzer.analyze(text=response, language="en",4 entities=["EMAIL_ADDRESS", "US_SSN", "CREDIT_CARD"])5redacted = anonymize(response, results)Commands to Remember
Commands to Remember
pip install guardrails-ai # input/output validationpip install presidio-analyzer # PII detection
Common Mistakes
- Treating PII Detection as a black box without evaluation
- Ignoring cost and latency in production
- Skipping error handling for pii detection
Cheat Sheet
Quick recap — the most important points from this module.
Cheat Sheet
quick ref- •PII Detection
- •Presidio
- •Tokenization
- •GDPR