Area 06 · AI Security · Concept 07 of 20

PII Redaction

Mask personal data (names, phone numbers, IDs) before you log it or send it to a model.

01–10 · The basePhase 7 · Weeks 24–26≈ 1 hour

The idea

Prompts and traces often contain personal data: names, emails, phone numbers, addresses, account and ID numbers. Sending it to third-party models and storing it in logs creates privacy and compliance obligations (GDPR in Europe, among others).

Redaction detects PII and replaces it with placeholders, either irreversibly (for logs) or reversibly with a mapping kept on your side (pseudonymisation), so the model works with <PERSON_1> and you restore real values in the final output.

Use a detector like Microsoft Presidio (regex + NER models), tune it for your locale (Irish PPS numbers, Eircodes), and test both misses and over-redaction.

Why it matters

It reduces the blast radius of a breach and is often a requirement to use cloud models with customer data.

Words to know

  • PIIPersonally identifiable information.
  • PseudonymisationReplacing identifiers with reversible placeholders.

Try it without code

Spot PII

  1. Take 10 real-looking support messages.
  2. Highlight every piece of personal data.
  3. Decide which the model actually needs to see.

Use it in code

Detect and anonymise with Presidio.

python
# pip install presidio-analyzer presidio-anonymizer ; python -m spacy download en_core_web_lg
from presidio_analyzer import AnalyzerEngine
from presidio_anonymizer import AnonymizerEngine

text = "Hi, I'm Aoife Byrne, call me on 087 123 4567 or aoife@example.ie about order 5531."
analyzer, anonymizer = AnalyzerEngine(), AnonymizerEngine()
findings = analyzer.analyze(text=text, language="en")
print(anonymizer.anonymize(text=text, analyzer_results=findings).text)
# -> "Hi, I'm <PERSON>, call me on <PHONE_NUMBER> or <EMAIL_ADDRESS> about order 5531."
PRACTICE · TICK IT AFTER THIS

Redact PII from all traces in your app before they are stored, and add a test with Irish-format phone numbers.

Common mistakes

  • Redacting logs but sending raw PII to the model unnecessarily.
  • Assuming default detectors handle your country’s formats.

Go deeper