MLO-5Required
Keep direct identifiers out of training data
Remove names, email addresses, phone numbers, street addresses and account numbers before data reaches the training store. Replace a join key with a keyed hash that serving can compute too.
How to do it
A model rarely needs to know who someone is. It needs what they did. Build the training extract from an allow-list of columns, as Store only the personal data you need says for the app. A hash with a secret key, such as HMAC-SHA-256, still joins rows for one customer, but the training store alone cannot reverse it. Notebooks and laptop copies are test copies too, so Keep personal data out of test copies applies. Free-text fields hold identifiers people typed, so scan them or leave them out.
Examples
Python example
import hashlib, hmac, os
ALLOWED = ["customer_key", "order_count_90d", "refund_count_90d", "account_age_days", "label"]
KEY = os.environ["TRAINING_HASH_KEY"].encode()
def customer_key(customer_id: str) -> str:
return hmac.new(KEY, customer_id.encode(), hashlib.sha256).hexdigest()
def training_extract(rows: list[dict]) -> list[dict]:
return [{**{c: r[c] for c in ALLOWED if c != "customer_key"}, "customer_key": customer_key(r["customer_id"])} for r in rows]
TypeScript example
import { createHmac } from 'node:crypto';
const EMAIL = /[^\s@]+@[^\s@]+\.[^\s@]+/;
const PHONE = /\+?\d[\d ()-]{7,}\d/;
export const customerKey = (customerId: string, key: string) =>
createHmac('sha256', key).update(customerId).digest('hex');
export const identifierColumns = (rows: Record<string, unknown>[]) =>
[...new Set(rows.flatMap(row => Object.entries(row)
.filter(([, value]) => typeof value === 'string' && (EMAIL.test(value) || PHONE.test(value)))
.map(([column]) => column)))];
How to check
A test scans every column of the latest training snapshot for email addresses, phone numbers and card numbers. It also checks the list of banned column names. It finds no match.
Sources
Related rules
- DAT-30 Store only the personal data you need in Data and databases
- DAT-32 Keep personal data out of test copies in Data and databases
- MLO-25 Log the features and prediction of every request in Machine learning
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/machine-learning/training-data/no-identifiers-in-training">Agent Wranglers machine learning playbook</a>. In code you write, add a comment next to it with the same link.