# De Identification Techniques

> Use when preparing a dataset for sharing, analytics, or testing and direct identifiers must be removed or transformed. Covers direct and quasi identifier discovery, k-anonymity checks, generalization and suppression, pseudonym key handling, and re-identification risk testing. Use when a team asks for production data in a lower environment or when an external partner needs a safe extract.

- Skill: `mizazhaider-ceh/de-identification-techniques` (Agent Skill)
- Install (CLI): `npx get-skill add mizazhaider-ceh/de-identification-techniques`
- Raw SKILL.md: https://api.skillmd.com/api/skills/mizazhaider-ceh/de-identification-techniques/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Product & Planning
- Author: mizazhaider-ceh (https://skillmd.com/u/mizazhaider-ceh)
- Updated: 2026-11-22
- Page: https://skillmd.com/skills/mizazhaider-ceh/de-identification-techniques

---


De-identification is the work of turning a dataset about identifiable
people into one that cannot reasonably be traced back to them, while
keeping it useful. Removing names alone never achieves that. A
combination of postcode, birth date, and gender can single out most
people, and a "de-identified" extract joined against a public dataset
can quietly re-identify the whole file. This sub-skill covers the
practical pipeline - find every identifier, transform the risky ones,
measure what remains, and attack your own output before anyone else
gets it.

## Quick Workflow

1. Classify every column - direct identifier, quasi identifier,
   sensitive attribute, or non-identifying.
2. Drop direct identifiers outright, unless a keyed pseudonym is
   genuinely needed for linkage, in which case protect the key.
3. Generalize quasi identifiers - age bands instead of birth dates,
   regions instead of postcodes - until equivalence classes are big
   enough.
4. Suppress or perturb the records that still stand out, and record
   how many rows were affected.
5. Measure k-anonymity on the quasi identifiers and check that
   sensitive attributes are diverse within each group.
6. Attack your own output - attempt linkage against plausible public
   or partner datasets, and record the success rate.
7. Ship with a data sharing agreement that bans re-identification
   attempts, and keep the mapping key separate from the extract.

## 1. Classify identifiers in a dataset

```python
#!/usr/bin/env python3
"""Identifier classification - direct, quasi, sensitive, or safe."""
import csv
from collections import Counter

DIRECT = {"name", "email", "phone", "national_id", "customer_id"}
QUASI = {"postcode", "birth_date", "gender", "city", "job_title"}
SENSITIVE = {"diagnosis", "salary", "political_view", "religion"}

with open("extract.csv", newline="") as fh:
    reader = csv.DictReader(fh)
    for column in reader.fieldnames:
        if column in DIRECT:
            kind = "DIRECT - drop or keyed pseudonym"
        elif column in QUASI:
            kind = "QUASI - generalize and check group sizes"
        elif column in SENSITIVE:
            kind = "SENSITIVE - check diversity within each group"
        else:
            kind = "non-identifying - keep"
        print(f"{column:15s} {kind}")
```

## 2. Generalize and pseudonymize

Generalization trades precision for safety, and the trade must be
deliberate per column. Pseudonyms must be keyed and one way - a
sequential fake id, or a hash without a secret, is reversible by
anyone who guesses the scheme.

```python
#!/usr/bin/env python3
"""Generalization plus keyed pseudonyms for a sample extract."""
import hashlib
import hmac
from datetime import date

PEPPER = b"secret-loaded-from-vault"  # never hardcode in real code

def pseudonym(value: str) -> str:
    return hmac.new(PEPPER, value.encode(), hashlib.sha256).hexdigest()[:24]

def age_band(birth: date, today: date = date(2026, 10, 27)) -> str:
    age = today.year - birth.year - ((today.month, today.day) < (birth.month, birth.day))
    low = (age // 10) * 10
    return f"{low}-{low + 9}"

def region(postcode: str) -> str:
    return postcode[:2] + "***"  # keep only the coarse area

print(pseudonym("user@example.com"))
print(age_band(date(1991, 4, 12)))
print(region("1000AA"))
# The pepper lives in the vault, never in the repo, the extract, or the ticket.
# Rotate the pepper and the extract is unlinkable to earlier extracts.
```

## 3. Measure k-anonymity and group diversity

```python
#!/usr/bin/env python3
"""k-anonymity check - every quasi identifier group must have at least k rows."""
from collections import Counter

# (age_band, region, gender, diagnosis) rows after generalization
ROWS = [
    ("30-39", "10***", "F", "asthma"),
    ("30-39", "10***", "F", "diabetes"),
    ("30-39", "10***", "F", "asthma"),
    ("40-49", "20***", "M", "asthma"),
    ("40-49", "20***", "M", "asthma"),
    ("40-49", "20***", "M", "asthma"),
]
groups = Counter((age, reg, gen) for age, reg, gen, _ in ROWS)
k = min(groups.values())
print(f"k = {k} (smallest group size; aim for k of 5 or higher for external sharing)")
for group, size in sorted(groups.items()):
    diagnoses = {d for a, r, g, d in ROWS if (a, r, g) == group}
    print(f"  {group} size {size} distinct diagnoses {len(diagnoses)}")
    if len(diagnoses) == 1:
        print("    WARNING - single diagnosis in this group reveals it for every member")
```

## 4. Attack your own output before shipping

```bash
# Linkage test sketch - join the extract against a known public-style file
# on the quasi identifiers and count how many rows match exactly one person
python3 - <<'EOF'
import csv
from collections import Counter
extract = list(csv.DictReader(open("extract-deidentified.csv")))
public = list(csv.DictReader(open("public-register.csv")))
public_keys = Counter((r["age_band"], r["region"], r["gender"]) for r in public)
unique_matches = sum(
    1 for r in extract
    if public_keys[(r["age_band"], r["region"], r["gender"])] == 1
)
print(f"Rows matching exactly one public record: {unique_matches} of {len(extract)}")
print("Any nonzero count here must be generalized or suppressed before release.")
EOF
```

## Edge cases

- Longitudinal data defeats one-off checks. The same person across
  monthly extracts can be linked by pattern even when each extract
  passes, so use consistent generalization and consider fresh
  pseudonyms per release window.
- Free text notes, images, and audio can carry identifiers that
  column checks never see. Scan or redact unstructured fields before
  any release, and treat unreviewed free text as identifying.
- Small populations break anonymity fast. A dataset about a rare
  condition, a small town, or a single employer may be unreleasable
  in row form no matter the generalization, in which case publish
  aggregates only.
- Pseudonymized data is still personal data under GDPR when the key
  exists somewhere. Only truly irreversible anonymization, with the
  key destroyed and re-identification tested, leaves the scope of
  data protection law.
- Differential privacy and de-identification compose well. Adding
  calibrated noise to aggregates on top of a de-identified extract
  protects against the differencing attacks that row level transforms
  alone cannot stop.

## Key references

- GDPR Recital 26 - anonymous information versus pseudonymous data
- ISO/IEC 20889 - privacy enhancing data de-identification terminology and classification
- NIST SP 800-188 - de-identification guidance
- Parent skill anonymization-techniques - anonymization foundations
- Sibling skill differential-privacy - noise based protection for aggregates

