Data Classification, Privacy & Protection Controls
Lesson opener
In one line: Label data by how much harm its exposure or alteration would cause, attach concrete handling rules to each label, and implement those rules with encryption, masking, tokenization, loss-prevention checks and retention so that protection follows the data into lakes, dashboards and AI systems.
Why it matters: A classification policy on a slide protects nothing. Protection happens when a column containing personal information is masked for a dashboard role, when an export to an external tool is blocked, when an index never ingests restricted text, and when old extracts are deleted on time. Engineers and analysts turn policy words into controls that run every day.
Before this lesson: Identity, Access & Least Privilege controlled who may reach data. Managers' classification and privacy awareness is covered in Privacy, Security & Compliance; this lesson goes further into engineering controls and does not repeat the governance introduction.
Northline Consumer Goods (illustrative) is building a customer insights dashboard and a support assistant. The source tables contain names, emails, mobile numbers, order totals and free-text support notes, and the notes sometimes contain phone numbers a customer typed in. The privacy lead asks the engineers: "Which fields are personal, which controls apply to each, who can see the raw values, and when is the data deleted?"
What you will be able to do
- Define classification labels and the handling rules attached to each.
- Explain encryption at rest and in transit, and the role of key management, at a conceptual level.
- Choose between masking, tokenization, pseudonymization and aggregation for a use case.
- Describe data loss prevention (DLP) patterns for exports, shares and AI prompts.
- Raise retention and deletion questions and record who decides.
- Separate personal information (PI) from non-PI in lakes, dashboards and AI systems, including free text.
Deliverable: a classification and protection plan: dataset or column inventory, label, handling rules, protection controls, retention, owner, validation tests and escalation path.
Prerequisites
| Prerequisite | Why it matters |
|---|---|
| Cybersecurity Foundations for Data, AI & Analytics | Assets, owners and CIA ratings that feed classification. |
| Identity, Access & Least Privilege | Access roles that classification rules refer to. |
| Privacy, Security & Compliance | Governance-level classification and privacy awareness. |
| Master Data Domains | Where customer and supplier master data originate. |
| Security, Guardrails & Governance | Data handling for AI assistants. |
| Cloud Fundamentals | Vocabulary for storage services and managed keys. |
Plain English
Classification labels. A small set of labels, typically four, keeps the scheme usable. A common pattern (the names and counts are your organisation's decision):
| Label | Meaning | Typical examples |
|---|---|---|
| Public | Approved for anyone | Published price list, annual report |
| Internal | For staff; low harm if leaked | Org charts, aggregated sales by region |
| Confidential | Harm if exposed; need-to-know | Customer-level orders, supplier contracts, personal data |
| Restricted | Serious harm; tightly limited | Payroll, health data, credentials, bank details |
A label is only useful if it drives rules. For each label write down: who may access it, whether it can leave the company, which tools and model endpoints may process it, how it is stored and protected, whether it may appear in logs, tickets or prompts, and how long it is kept.
Personal information (PI) versus non-PI. PI identifies or can reasonably be linked to a person: names, emails, phone numbers, account identifiers, device identifiers and sometimes combinations of ordinary fields (postcode, birth date and job title can identify someone). Order totals by region are not PI; order lines linked to a customer id are. What counts as personal or sensitive, and what the duties are, is jurisdiction-specific and decided by the legal and data protection functions. As engineers you find the PI, label it and apply controls.
Be especially alert to free text. Support notes, survey comments and chat logs hold PI in unpredictable places, and when such text is loaded into a lake, shown on a dashboard or embedded for an AI index, the PI travels with it.
Encryption at rest and in transit.
- In transit: data moving between systems is protected using TLS so that eavesdroppers on the network cannot read or alter it. Insist on TLS for every connection to databases, APIs and storage, and reject plain-text fallbacks.
- At rest: stored data (disks, object storage, backups, warehouse tables) is encrypted so that stolen media or a copied storage file is unreadable without the key. Most managed services do this by default; check rather than assume.
- Keys: encryption is only as strong as key handling. Keys are stored in a key management service or hardware module, access to keys is separate from access to data, and keys are rotated. Where policy requires, the organisation can manage its own keys rather than the provider's default. Encryption does not replace access control: a user who is allowed to read the data sees it decrypted.
Masking, tokenization, pseudonymization, aggregation. Different techniques for different needs:
| Technique | What it does | Good for | Limits |
|---|---|---|---|
| Masking | Hides part of a value (a***@example.com) | Showing records to support staff or dashboards | Original still exists; mask can leak if too light |
| Tokenization | Replaces a value with a consistent token; the mapping or key is held in a restricted system | Joining datasets without exposing the value | Token vault becomes a high-value target |
| Pseudonymization | Replaces direct identifiers with codes while the link back is kept separately | Analytics on behaviour | Still personal data in many jurisdictions; re-identification is possible with extra information |
| Aggregation | Reports totals or averages with minimum group sizes | Dashboards | Small groups can reveal individuals |
| Dropping the field | Not collecting or loading it | Everything where the field is not needed | None; it is the strongest control |
Prefer data minimisation: do not bring a field into the lake or index if the use case does not need it.
DLP patterns. Data loss prevention means detecting and blocking unintended movement of sensitive data. Patterns that work at engineering level: scan files and tables for PI patterns before they are published; block exports of confidential datasets to personal storage or unapproved tools; check text for PI before it is sent to an external AI service or stored in an index; restrict who can download or share from the BI workspace; and alert on unusually large exports. Pattern matching is imperfect, so treat detections as a safety net on top of classification and access control, not a replacement.
Retention and deletion. How long should each dataset be kept, and how is it deleted from every copy (lake, warehouse, backups, extracts, indexes, notebooks)? The purpose, business need and legal or contractual retention rules differ by dataset and jurisdiction. The data owner and the legal function decide the period; engineers make deletion possible and prove it. A dataset with no retention rule is a question to raise, not a default to "keep forever".
Teacher walkthrough
Build the plan for the customer insights dashboard and support assistant.
- Business owner. The Head of Customer Operations owns the customer data; the privacy lead owns the labels and retention rules; the platform lead owns implementation.
- Approved users. Insights analysts see masked or aggregated customer fields; the support team sees customer detail through the support tool only; the privacy lead and a small restricted group can request raw values under approval.
- Data and systems in scope. The customer table, order history, support notes, the lake zones that hold them, the dashboard, the support assistant's index and any exports.
- Permissions. Raw PI lives only in the restricted zone, readable by named service identities and an approval-based group. The curated zone holds tokens in place of direct identifiers. The dashboard role reads curated and aggregated data only.
- Validation. Scan every column sample for PI patterns; confirm free-text columns are either excluded, scrubbed or classified as confidential; test that a dashboard user cannot see raw values; test that an export from the confidential zone to an unapproved destination is blocked; confirm encryption settings and TLS enforcement in configuration; confirm a retention job removes data past its period.
- Escalation. PI found in a place labelled non-PI, or in a log or prompt, goes to the privacy lead and the security on-call. Confirmed exposure follows the organisation's incident process; notification obligations are decided by the data protection lead under the applicable jurisdiction.
- Monitoring evidence. Access logs on the restricted zone, DLP detections, export logs, retention job reports and quarterly sampling of dashboards and indexes for PI.
- Fallback and containment. If PI is found where it should not be, restrict the location, take the dashboard or index offline if necessary, purge or rebuild after scrubbing and record what was exposed and to whom.
- Stop condition. Raw PI in a dashboard dataset, an AI index or a log stops publication until it is scrubbed and the owner confirms. Missing retention for a restricted dataset blocks onboarding of that dataset.
- Review. Labels and rules are reviewed annually and when a new data source or use case appears.
Worked example
The script classifies columns from synthetic samples by detecting email and phone patterns, assigns a handling plan, demonstrates masking and tokenization, and checks datasets against retention rules. The tokenization uses a keyed hash (HMAC) with a demo key EXAMPLE-NOT-A-REAL-TOKEN; a real key would live in a key management service and a keyed hash is one form of pseudonymization, not a guarantee of anonymity. The pattern checks are deliberately simple and will miss some formats. The retention periods are illustrative proposals. It uses only the Python standard library.
import hashlib
import hmac
import re
DEMO_KEY = b"EXAMPLE-NOT-A-REAL-TOKEN" # demo only; real keys live in a key vault
EMAIL = re.compile(r"[\w.+-]+@[\w-]+\.[\w.]+")
PHONE = re.compile(r"\b\d{10}\b")
SAMPLE = {
"customer_email": ["asha.verma@example.com", "li.wen@example.org"],
"mobile": ["9876543210", "9123456780"],
"order_total": ["1250.00", "89.90"],
"region": ["North", "South"],
"support_note": ["Call back on 9876543210 please", "Delivered late"],
}
PLAN = {
"personal": {"class": "confidential", "control": "tokenize or mask outside the restricted zone"},
"non_personal": {"class": "internal", "control": "standard role access"},
}
def detect(values):
found = set()
for v in values:
if EMAIL.search(v):
found.add("email")
if PHONE.search(v):
found.add("phone")
return found
def mask_email(value):
local, domain = value.split("@")
return local[0] + "***@" + domain
def tokenize(value):
return "tok_" + hmac.new(DEMO_KEY, value.encode(), hashlib.sha256).hexdigest()[:12]
for column, values in SAMPLE.items():
kinds = detect(values)
kind = "personal" if kinds else "non_personal"
print(f"{column:15s} {kind:13s} {sorted(kinds)} -> {PLAN[kind]['class']}: {PLAN[kind]['control']}")
print(mask_email("asha.verma@example.com"))
print(tokenize("9876543210") == tokenize("9876543210"))
print(tokenize("9876543210") == tokenize("9123456780"))
RETENTION_DAYS = {"web_logs": 90, "customer_extract": 365}
HOLDINGS = [("web_logs", 120), ("customer_extract", 200), ("scratch_export", 400)]
for name, age in HOLDINGS:
limit = RETENTION_DAYS.get(name)
if limit is None:
print(name, "NO RETENTION RULE: ask the data owner")
else:
print(name, "DELETE-OR-REVIEW" if age > limit else "within retention")Expected result: customer_email and mobile are detected as personal and routed to confidential handling; order_total and region stay internal; and support_note is also detected as personal because one sample contains a phone number, which is the free-text lesson in one line. The mask prints a***@example.com. Tokenizing the same value twice gives the same token (True), so joins still work, while different values give different tokens (False for equality). In retention, web_logs at 120 days exceeds its 90-day period and needs deletion or an owner-approved exception, customer_extract is within retention, and scratch_export has no rule at all, which is exactly the ownership question to escalate.
A second workplace case
The Northline HR team wants an AI assistant that summarises employee survey comments. Comments are free text and may name individuals or include health details. The protection plan classifies the raw comments as restricted, strips names and direct identifiers before indexing, reports themes only for groups above a minimum size so a small team cannot be singled out, keeps raw comments in the restricted zone with a short retention period set by HR and legal, and routes prompts through an approved model endpoint with no logging of raw text. The same labels and techniques apply, but the choice of aggregation with minimum group sizes matters more than masking here, because the risk is singling out a person rather than leaking a field.
Failure example
Symptom: An analyst notices that the "customer insights" dashboard tooltip shows full email addresses when hovering over the top-spender chart.
Diagnosis: The dashboard dataset was built from the raw customer table because it was the easiest join. The email column was hidden from the table view but remained in the model and surfaced in the tooltip. Nobody scanned the dataset for PI, and the dashboard role could read the underlying table.
Correction: Remove the email column from the dashboard dataset, rebuild it from the curated zone where emails are tokenized, restrict the dashboard role to curated data, and review other reports using the same dataset. Check access logs to see who loaded the report; report the exposure through the incident process and let the privacy lead decide whether any notification is required in the applicable jurisdiction.
Validation: Open the rebuilt dashboard as the dashboard role and as an administrator, check every visual, tooltip, export and underlying data view for PI, and run the column scan against the new dataset.
Prevention: Make a PI scan part of every dashboard publish step, build dashboards only from curated sources, hide-by-removal rather than hide-by-formatting, and keep a list of datasets that must never be used as dashboard sources.
Guided practice
Scenario: A Northline support assistant will index support tickets containing customer name, email, order id and free-text comments. Produce the classification and protection plan.
Hints:
- Which fields do you really need in the index?
- Which columns are personal, and which technique suits each?
- Where could PI hide in free text?
- What is the retention question, and who answers it?
- What stops the plan?
Complete solution:
- Minimise: index only the order id, a ticket category and a scrubbed summary of the comment; do not index name or email at all. Look up customer details through the support tool at answer time under the support agent's own entitlements.
- Labels and techniques: raw ticket table is confidential; name and email are tokenized or dropped in the curated copy; comments pass through a PI scrubber that replaces emails and phone numbers with placeholders before indexing, with the scrubber's misses sampled each week.
- DLP: scan text for PI patterns before it is sent to the model endpoint or stored; block export of the raw table from the BI workspace.
- Encryption: TLS to the index and the model endpoint, encryption at rest for the index storage and backups, keys in the key management service with access limited to the platform identities.
- Retention: the Head of Customer Operations and the legal function set how long tickets and the index are kept; the index is rebuilt or purged on the same schedule so deleted tickets cannot be retrieved.
- Validation: seed test tickets containing synthetic emails and phone numbers and confirm none appears in the index, the answers or the logs.
- Stop condition: any real PI found in the index or logs pauses the assistant until the index is rebuilt after scrubbing.
Independent practice
Create a classification and protection plan for a data and AI use case that handles personal information, such as a customer churn model, a loyalty dashboard or an HR helpdesk assistant.
Acceptance criteria
- Defines at least four labels with handling rules for access, sharing, tools and model endpoints, logging and retention.
- Lists each dataset or column with its label and states whether it is PI; free-text fields are explicitly addressed.
- Specifies TLS in transit, encryption at rest and key-management responsibilities, and notes that encryption does not replace access control.
- Chooses a technique (drop, mask, tokenize, pseudonymize, aggregate) per field with a reason, and sets minimum group sizes where aggregation is used.
- Describes DLP checks at export, share and AI-prompt boundaries and acknowledges their limits.
- Raises retention and deletion questions for every copy, including indexes, and names who decides.
- Includes validation with synthetic PI, an escalation path, a fallback and a stop condition.
- Marks anything jurisdiction-specific as a question for the data protection function and uses no real personal data.
Common mistakes
- Publishing labels without handling rules, so the label changes nothing.
- Treating hidden columns as protected when the data is still in the model, tooltip or export.
- Ignoring free-text fields, which often hold the most surprising PI.
- Believing encryption at rest means any user may be given access safely.
- Using masking when tokenization or removal is needed, or the reverse.
- Calling pseudonymized data "anonymous" and relaxing the controls.
- Showing aggregates for tiny groups that identify individuals.
- Loading whole tables into lakes or AI indexes "in case they are useful".
- Keeping data forever because nobody owns the retention decision.
- Relying on DLP pattern matching alone to catch PI.
Quick check
- Why is a classification label without handling rules ineffective?
- Why is a support-notes column a classification risk even when other columns are clean?
- What is the difference between masking and tokenization in how they are used?
- Does encryption at rest stop an authorised but over-privileged user seeing the data?
- Who decides how long customer data is retained, and what must engineering provide?
Answers:
- Because people and systems act on rules, not names. Without rules for access, sharing, tools, logging and retention, the label does not change any behaviour.
- Free text can contain emails, phone numbers, names or sensitive details typed by customers, and these travel into dashboards, logs and AI indexes unless scanned or scrubbed.
- Masking hides part of a value for display; the real value remains stored. Tokenization replaces the value with a consistent token so datasets can be joined, with the mapping or key held in a restricted system.
- No. Encryption protects against stolen media or storage files; authorised users see decrypted data, so access control and least privilege are still needed.
- The data owner with the privacy and legal functions decides, according to purpose and jurisdiction; engineering must make deletion possible across all copies and prove it ran.
Quiz alignment
The quiz (QUIZ_CYBER3) covers labels and handling rules, PI and non-PI including free text, encryption in transit and at rest with key management, masking, tokenization and pseudonymization, aggregation limits, DLP patterns and retention, using the customer dashboard, support assistant and HR survey cases.
Lesson summary
Classification is useful only when labels drive concrete rules. Find PI in structured and free-text fields, minimise what enters lakes, dashboards and AI indexes, and choose the right technique: drop, mask, tokenize, pseudonymize or aggregate with minimum group sizes. Use TLS and encryption at rest with separate key control, but never mistake encryption for authorisation. Add DLP checks at exports, shares and prompts, accept their limits, and raise retention questions for every copy with a named owner. Leave jurisdiction-specific duties to the legal and data protection functions, and validate with synthetic data.
Bridge to the next lesson
Data is protected by labels and controls, but it also moves across networks and between services. The next lesson, Network Security for Cloud, Data & AI, covers trust boundaries, private connectivity, segmentation, egress control and safe exposure of warehouses, vector databases and BI gateways.
Sources
- NIST, Guide to Protecting the Confidentiality of Personally Identifiable Information (PII), SP 800-122: https://csrc.nist.gov/pubs/sp/800/122/final
- NIST, Recommendation for Key Management, SP 800-57 Part 1 (check the current revision): https://csrc.nist.gov/pubs/sp/800/57/pt1/r5/final
- NIST, Guidelines for Media Sanitization, SP 800-88 (secure deletion concepts): https://csrc.nist.gov/pubs/sp/800/88/r1/final
- NIST, De-Identification of Personal Information, NISTIR 8053: https://csrc.nist.gov/pubs/ir/8053/final
- OWASP, Cryptographic Storage Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html
- OWASP, Transport Layer Security Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Transport_Layer_Security_Cheat_Sheet.html
- IETF, RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3: https://www.rfc-editor.org/rfc/rfc8446
- Python 3 standard library,
hmac,hashlib,re: https://docs.python.org/3/library/hmac.html (example tested with Python 3.11+, standard library only)
Northline Consumer Goods, its datasets, labels and retention periods are illustrative. Definitions of personal and sensitive data, retention periods, anonymization standards and notification duties are jurisdiction-specific and are decided by the organisation's legal and data protection functions. Every credential-like string in this lesson is a harmless fake.