Sub topic 3
Removing Personal Data Before Anything Else
Assume you know how AI assistants and search systems answer questions, can read simple Python, and understand basic privacy terms. This chapter focuses on the first processing step in a real-question prompt pipeline: removing personal data before questions are copied, clustered, sampled, or sent to another system.
A customer question can contain useful intent and sensitive details in the same sentence:
> “Can I move my subscription from [email protected] to +1 415 555 0198?”
The intent is about changing an account email address. The email address and phone number are personal data. A prompt set usually needs the intent, not the customer’s identity.
Identify personal data in raw questions
Personal data is information that identifies a person directly or indirectly. Direct identifiers include names, email addresses, phone numbers, account IDs, and postal addresses. Quasi-identifiers may identify someone when combined with other data, such as a rare job title, location, order date, or unusual incident description.
Look for these categories before processing the text:
| Data type | Example | Typical replacement |
|---|---|---|
| Email address | `[email protected]` | `[EMAIL]` |
| Phone number | `+1 415 555 0198` | `[PHONE]` |
| Account or order ID | `ORD-839201` | `[ORDER_ID]` |
| Name | `Alex Morgan` | `[NAME]` |
| Address | `14 Market Street` | `[ADDRESS]` |
| Secret or credential | API key or password | `[SECRET]` |
The correct replacement depends on the test objective. If the exact value is irrelevant, use a stable token such as [EMAIL]. If the domain needs to distinguish personal and work addresses, preserve only a safe category such as [WORK_EMAIL]. Do not keep a reversible encrypted value in the prompt set unless a documented use case requires it.
Scrub before sharing or enrichment
Keep the raw export in a restricted location with a defined retention period. Create a scrubbed working copy, and give the working copy a record ID that cannot be used to recover the original customer identity. Apply scrubbing before sending text to an external model, analytics tool, spreadsheet, or annotation vendor.
A useful pipeline is:
Use more than one protection. Pattern matching can find obvious emails and phone numbers, but it may miss names, addresses, copied signatures, credentials, or personal details in free text. Human review and representative sampling are still needed.
import re
EMAIL = re.compile(r"[\w.+-]+@[\w-]+\.[\w.-]+")
PHONE = re.compile(r"\+?\d[\d\s().-]{7,}\d")
def scrub(text):
text = EMAIL.sub("[EMAIL]", text)
return PHONE.sub("[PHONE]", text)
def normalise(text):
return re.sub(r"\s+", " ", text).strip().lower()
def clean_and_dedupe(questions):
seen = {}
for question in questions:
cleaned = scrub(question)
seen.setdefault(normalise(cleaned), cleaned)
return list(seen.values())
questions = [
"Can Alex move [email protected] to +1 415 555 0198?",
"Can Alex move [email protected] to +1 415 555 0198?",
]
for question in clean_and_dedupe(questions):
print(question)The script replaces obvious email and phone patterns, collapses whitespace, converts text to lowercase for comparison, and keeps the first scrubbed wording. It does not prove that the data is anonymous. For example, “the only surgeon in a small town who ordered product X” may still identify one person.
Preserve intent without preserving identity
Scrubbing should remove identifying details while retaining the reason for the question. Replace a specific value with a category when that category affects the answer:
- “Can I change the email on my account?” keeps the account-management intent.
- “Can I return order ORD-839201?” becomes “Can I return order
[ORDER_ID]?” - “My delivery to 14 Market Street is late” may become “My delivery to
[ADDRESS]is late.” - “I am a 17-year-old customer” may require
[AGE]if age affects eligibility.
Record what transformation occurred and which rule produced it. This audit information belongs in restricted metadata, not in the evaluation prompt shown to a model or reviewer.
Check the scrubber
Test the scrubber with known examples and false positives. A phone-number rule might replace a product code. An email rule might miss an address surrounded by unusual punctuation. Test multilingual text, line breaks, copied signatures, and messages containing several identifiers.
Measure both kinds of error:
- A false negative leaves personal data in the set.
- A false positive removes useful meaning or changes the customer’s intent.
Exercise
A question says, “Why was order ORD-839201 sent to 14 Market Street?” Which parts should you replace, and what should remain?
Show answer
Replace the order ID and address with [ORDER_ID] and [ADDRESS]. Keep the question about the order being sent, because that expresses the customer’s intent.