Course map
Stage 1: Foundations
Stage 2: Data Integration
Stage 3: Building & Shipping
Stage 4: Customer Engagement
Stage 5: Specialization

Part 12 / Topic 2 of 7

Personal data

Acme's data has people in it — customer names, emails, phone numbers. Three verbs cover your obligations:

  • Minimise: do not collect, copy or send fields the task does not need. The email-triage AI (Track A) needs the question, not the sender's phone number.
  • Redact: strip or mask personal data before it reaches logs, analytics, or any LLM:
# examples/01_redact_personal_data_before_it_reaches.py
import re

PATTERNS = {                       # order matters: match card numbers before the looser phone pattern
    "EMAIL": r"[\w.+-]+@[\w-]+\.[\w.]+",
    "CARD":  r"\b\d(?:[ -]?\d){12,15}\b",     # 13-16 digits, spaces or dashes between
    "PHONE": r"\+?\d[\d -]{8,}\d",
}

def redact(text):
    for label, pattern in PATTERNS.items():
        text = re.sub(pattern, f"[{label}]", text)
    return text

msg = "Call Ravi on +91 98765 43210 or [email protected]; card 4111 1111 1111 1111 was charged."
print("card before phone:", redact(msg))

PATTERNS = {"EMAIL": PATTERNS["EMAIL"], "PHONE": PATTERNS["PHONE"], "CARD": PATTERNS["CARD"]}
print("phone before card:", redact(msg), " <- wrong label")
# card before phone: Call Ravi on [PHONE] or [EMAIL]; card [CARD] was charged.
# phone before card: Call Ravi on [PHONE] or [EMAIL]; card [PHONE] was charged. <- wrong label

The deliberate bug in the second half is the lesson: a card number is a long digit string, so the looser phone pattern claims it first if you let it. Pattern order is logic, and redaction gets tested on realistic samples like any parser (Part 3) — a redactor that silently mislabels is a redactor you cannot trust.

  • Retention: data you keep is data you must protect. Agree how long pipeline copies, quarantine rows and logs live, and delete on schedule.

🧪 Quick quiz

  1. Why did the redaction example put the CARD pattern before the PHONE pattern?
Show the answer

The looser phone pattern would otherwise match card numbers first. With phone first, the card number was labelled [PHONE]; with card first it became [CARD]. Test redaction on real samples. (verified against the example output above)

Done here? The practice set for Part 12 — 4 exercises with solutions — is on the part page.

Search the guide