RAG · Lesson 100 of 120
Personal Data
Keep it out.
Support tickets and emails are full of personal data. Names, emails, phone numbers. If we index them as they are, RAG might show one customer's details to another. So we remove personal data before indexing.

- Tickets hold personal data
- Could leak
- Remove before indexing
Redacting before indexing
Patterns finds emails, UK phone numbers, and card numbers. Redact replaces each match with a label. Run it. The useful part of the ticket stays. The personal details are gone.
redact.pypython
import re
patterns = {
"EMAIL": r"[\w.+-]+@[\w-]+\.[\w.]+",
"PHONE": r"\b07\d{3} ?\d{6}\b",
"CARD": r"\b(?:\d{4}[ -]?){3}\d{4}\b",
}
def redact(text):
for label, pattern in patterns.items():
text = re.sub(pattern, f"[{label}]", text)
return text
ticket = ("Sam (sam.lee@example.com, 07700 900123) says E07 shows after rain. "
"Card 4111 1111 1111 1111.")
print(redact(ticket))Output
Sam ([EMAIL], [PHONE]) says E07 shows after rain. Card [CARD].
Personal data rules
Redact before indexing, not after. Index only what you need. Keep a way to delete a person's data from the index. And follow your local privacy law, like GDPR in the UK and Europe.
| key | value |
|---|---|
| Redact | before indexing |
| Index | only what you need |
| Delete | on request |
| Follow | privacy law |
Summary
Remove personal data before indexing, and keep a way to delete it later. Next, serving RAG as an API.
Key takeaways- Find patterns
- Replace with labels
- Delete on request
Next up: Serving RAG — FastAPI