AI Hints
Home›RAG Tutorial›Serving RAG
RAG · Lesson 100 of 120

Personal Data

Keep it out.

⏱ 2 min read▶ Video at 1:38:27🎓 Free
Watch this lesson in the RAG courseWatch on YouTube ↗Full RAG course

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.

Personal Data
From the video: Personal Data
  • 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.

keyvalue
Redactbefore indexing
Indexonly what you need
Deleteon request
Followprivacy 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