Skip to content
BytePatterns

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.

  1. Scan the model's reply before the user sees it
  2. Detect PII entities in the incoming message
  3. Send the masked prompt to the model
  4. Replace each entity with a typed placeholder

Mini quiz

1 / 3

Your gateway masks PII before the model sees it. Where can raw values still end up?

New lessons land every few weeks

Leave an address and we will tell you when the next one is up. That is the only reason we will use it.

One address, stored so we can email you. Nothing else, ever.