Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 10.5 — Personal Data in Documents
RAG and Vector Search · Example 1 of 1

A redactor with patterns and a name list

All values are invented. Real redactors also handle other phone and card formats, and check a card number's checksum to avoid redacting ordinary numbers.

Documents contain names, emails, phone numbers and card numbers that nobody meant to put in a search index. Find and replace them before chunking, keep them out of embeddings and logs, and decide how long anything is kept.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write mask_emails(text) that replaces every email address of the form letters, digits, dots, underscores and hyphens, an at sign, and a domain with [EMAIL], and returns the new text. Test it on a sentence with two addresses.

02

Write pseudonymise(texts) that replaces each distinct email with [EMAIL_1], [EMAIL_2], ... in order of first appearance and returns the new texts and the mapping dict.

Explain it without notes

01

Why should personal data be removed before chunking and embedding, not from the final answer?

02

How do you find an email address, and how do you find a person's name? Why are they different?

03

Name two ways a redactor can fail, and what you do about each.

04

What is pseudonymisation, and where must the mapping table live?

A redactor with patterns and a name list
Sign in to run this example in your browser.

Expected output

ticket 1: [NAME] wrote from [EMAIL]: the lock on bike 12 is stuck, call me on [PHONE].
ticket 2: Charged twice on card [CARD] for the monthly pass. [NAME], [EMAIL]
ticket 3: My mail is jane dot doe at example dot com, please reply there.
found: CARD=1 PHONE=1 EMAIL=2 NAME=2