Finding and Masking PII
AI & ML: lesson 27 of 32
Find personal data, swap it for placeholders, and mask the logs too.
Lesson 27 of 32 · 5 min
Finding and Masking PII
Step 1 of 9
A support message arrives: a name, a card number and an email, plus the actual question — why was I charged twice?
The Idea
Personal data leaks through three doors: the prompt, the reply and the logs. Detection finds each entity with a type, a confidence score and its position in the text. Masking swaps it for a typed placeholder such as {NAME}, so the model can still answer the question. Then scan the output, and mask logs at ingestion, because a log may keep the original.
Real-World Example
In a sealed-bid tender, the judges score bids with each company's name replaced by a number. The envelope matching numbers to names sits in a separate safe that only one person can open.
The Tradeoff
Detection is probabilistic: a low threshold masks harmless numbers, a high one misses real ones. On AWS, Amazon Comprehend detects PII, Amazon Bedrock Guardrails mask prompts and replies, CloudWatch Logs data protection masks log lines, and Amazon Macie finds PII already sitting in S3.
Your turn
Put the steps in the right order.
- Scan the model's reply before the user sees it
- Detect PII entities in the incoming message
- Send the masked prompt to the model
- Replace each entity with a typed placeholder
Mini quiz
1 / 3