Stop 18 · Evaluation, Safety & Responsible AITopics · 8/9

Data Privacy in AI Systems

Part of the AI Engineer Roadmap

In short

Users paste phone numbers, addresses and medical details into chatbots without thinking. If your system logs, trains on or leaks that, it's your problem, ethically and legally.

Protecting personal and sensitive data used in training and inference — covers data minimization, anonymization, and understanding what data a model might memorize and leak.

The blob covers part of an ID card with a strip of paper before handing it across a hotel reception desk.

Think of it like this

The masked Aadhaar photocopy

When a hotel asks for ID, smart people share a masked Aadhaar: only the last four digits show. The hotel gets what it needs, nothing more. Good AI systems do the same: collect only what's needed, mask personal details, and throw them away when done.

Watch it happen

Personal data through an AI support bot

User msg
Mask PII
LLM call
Store
Delete

1/5A user writes: 'My number is 98xxxxxx10, my order never came.' It contains personal data.

The big ideas

What you need to know

Data minimisation

Collect and keep only what the feature needs. Data you never stored can't leak.

Mask before you send

Strip or tag PII before text reaches logs, vendors or training sets.

Models can memorise

Models trained on raw personal data can repeat it later. Clean training data first.

Laws apply

India's DPDP Act 2023 and Europe's GDPR set rules on consent, purpose and deletion. Know which apply to you.

See it in code

Walk through the code

python
1import re2 3PATTERNS = {4    "EMAIL": r"[\w.+-]+@[\w-]+\.[\w.]+",5    "PHONE": r"(?:\+91[\s-]?)?[6-9]\d{9}\b",6    "AADHAAR": r"\b\d{4}\s?\d{4}\s?\d{4}\b",7}8 9def mask(text: str) -> str:10    for label, pattern in PATTERNS.items():11        text = re.sub(pattern, f"[{label}]", text)12    return text13 14print(mask("Call Riya on 9876543210 or mail riya.k@example.com"))

1/3One pattern per kind of personal data: email, Indian mobile number, 12-digit ID number.

Regex masking for common Indian PII. It's a first layer only; libraries like Microsoft Presidio also catch names and addresses.

Save yourself the pain

Common mistakes

Oops

Logging full prompts and replies forever 'for debugging'.

Do this instead

Mask PII before logging, limit who can read logs, and delete them on a schedule.

Oops

Assuming regex catches all personal data.

Do this instead

Regex misses names, addresses and context. Combine it with an NER-based tool and human review for sensitive data.

Your mission

Build a PII scrubber

~25 min

Quick check

What's the safest default for personal data in AI logs?

Go deeper

  1. 1Learn the concept of training-data memorization and why it's a real privacy risk for LLMs.
  2. 2Practice basic PII detection/redaction on a text dataset before using it.
  3. 3Read the core principles of GDPR/data-protection regulation as they apply to AI systems.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge