The learning notebook · LLM engineering

PII Masking Lab

A support summary should explain the problem, without exposing the person.

Learning experiment · Synthetic data · Offline baseline

24 fictional support tickets. Five columns. Only issue_summary is changed; the ticket metadata is preserved. This is a focused practice lab, not a production privacy filter.

What does masking mean? PII means personally identifiable information. Here, masking replaces a detected sensitive value with a label such as [EMAIL], while retaining the useful issue description.

Detect → validate → mask → evaluate

Rules or an optional LLM propose candidate entities. Python checks the allowed types and exact text matches, rejects conflicting overlaps, then replaces spans from right to left. Valid JSON alone does not prove that detection is correct.

01 Before · fictional support issue

Device restarts during setup. Deliver to 42 Example Lane, Sample City. Email alex@example.com or call +1 202-555-0147. Refund details: bank account DEMO-ACCT-001; card 4242 4242 4242 4242.

Keep the device problem. Identify the contact, address and payment details separately.

What each mask means

Five entity types, with the exact replacement used by the notebook.

Scroll the table sideways to see all four columns.

All examples are fictional or test values. These definitions guide candidate detection; they do not prove that the detector finds every value.
EntityWhat it meansOriginal exampleMasked value
AddressA person's home or delivery location.Not a general city mention.42 Example Lane, Sample City[ADDRESS]
EmailA contact email, including clearly written-out forms.Detection must preserve the exact source text.alex@example.com[EMAIL]
PhoneA phone or mobile contact number.Include its country code and separators.+1 202-555-0147[PHONE]
Bank accountAn account identifier in a banking or refund context.Not a bank name or account balance.DEMO-ACCT-001[BANK_ACCOUNT]
Payment cardA full debit or credit card number.Not an explicitly identified order reference.4242 4242 4242 4242[PAYMENT_CARD]

What actually ran

17 / 25Sensitive occurrences found
8Sensitive occurrences missed
1Non-sensitive value flagged

These are rule-based results on 24 authored teaching fixtures, not an LLM score. The baseline has no address detector, misses written-out emails, and mistakes one order reference for a card number. A valid checksum does not establish meaning.

Assistant-run verification on 6 September 2026: 13 notebook code cells executed offline and 24 automated tests passed with the optional SDK installed. Without it, one SDK contract test is skipped. Live LLM evaluation and my hands-on practice remain pending.

Try it, then challenge it

  1. Download and unzip the complete project. Open pii_masking_walkthrough.ipynb in Jupyter, following the included README.
  2. Keep RUN_LLM = False for the first run. No model key or API call is needed for the default notebook.
  3. Inspect DEMO-001, DEMO-013 and DEMO-020. Explain the missed address, written-out email and over-masked order number before changing the code.

Optional model calls require explicit opt-in, a model choice and an API key, and may incur charges. Use only the synthetic samples. Never send real personal data to a service that is not approved to process it.

Built with AI assistance for learning. No employer or client data. No model training, production deployment or privacy certification. Masking is not encryption, and a clean pattern re-scan is not proof of privacy.

← Back to learning projects