k-anonymity-verifier
БесплатноБез исполняемых скриптовНе проверенUse when a masked dataset must be proven to meet a k-anonymity, l-diversity or t-closeness threshold before it reaches a non-production environment. Computes…
от testland★ 18 звёзд на GitHubОб этом скилле
k-anonymity-verifier
Overview
A masked dataset is k-anonymous when every record is indistinguishable from at least k - 1 other records on the set of quasi-identifiers (QI) - columns that, when combined, could re-identify an individual (Sweeney 2002, cited in NIST SP 800-188:2023 at csrc.nist.gov/pubs/sp/800/188/final).
Two stronger models layer on top:
- l-diversity (Machanavajjhala et al. 2007, NIST 800-188 §3): each equivalence class must contain at least l well-represented distinct values of every sensitive attribute (SA), guarding against the homogeneity attack.
- t-closeness (Li et al. 2007, NIST 800-188 §3): the distribution of the SA within each equivalence class must be within distance t of the global distribution, measured by Earth Mover's Distance (EMD), guarding against the skewness and similarity attacks.
This skill verifies all three after masking. For choosing which
masking operator to apply per field, see the masking-techniques
catalog in pii-masking-pipeline-builder references/.
For detecting PII spans before masking, see
presidio-pii-detection.
How to use
- Agree the quasi-identifier (QI) and sensitive-attribute (SA) lists with a
privacy officer and record them in
qi-policy.yamlwithk_min/l_min/t_maxthresholds (Step 1). - Install pycanon (Step 2) and load the masked CSV into a pandas DataFrame.
- Compute
k_anonymity,l_diversity, andt_closenessfor the agreed QI / SA (Step 3). - Compare each value against the policy thresholds and the guidance bands (Step 4), then generate the full pycanon report for utility metrics (Step 5).
- Wire the gate script into CI so a failing dataset cannot be promoted (references/ci-gate.md, Step 6).
- When a dataset fails, re-mask or generalise with ARX (references/arx-api.md, Step 7) and re-verify.
- Report re-identification risk per equivalence class and per dataset (Step 8).
Step 1 - Select quasi-identifiers
QIs are columns that are not direct identifiers but whose combination can re-identify. Common QI categories (NIST 800-188 §2 "indirect identifiers"):
| Category | Examples |
|---|---|
| Demographic | age, sex, race, marital status |
| Geographic | ZIP code, city, state (below county level) |
| Temporal | date of birth, admission date, discharge date |
| Clinical / occupational | diagnosis code, specialty, employer industry |
Selection heuristics:
- Any column that appears in a publicly available external dataset (voter rolls, social media profiles) is a QI candidate.
- ZIP + birth date + sex together re-identified 87 % of the US population in Sweeney (2000), cited in NIST 800-188 §4. That triple is always a QI set.
- Columns with high cardinality relative to dataset size are stronger QIs (more granular = more identifying).
- Drop columns that are already nulled out or fully generalised - they contribute no identifying power and inflate computation.
Agree the QI list with a privacy officer before running verification.
Record the agreed list in a qi-policy.yaml alongside the dataset.
Step 2 - Install pycanon
pycanon is a Python library and CLI published by IFCA-CSIC that computes k-anonymity, l-diversity, t-closeness, and related metrics directly on a pandas DataFrame (github.com/IFCA-Advanced-Computing/pycanon).
pip install pycanon
# For PDF report generation:
pip install "pycanon[PDF]"
Requires Python 3.10, 3.11, or 3.12 (github.com/IFCA-Advanced-Computing/pycanon).
Step 3 - Compute k, l, t values
import pandas as pd
from pycanon import anonymity, report
data = pd.read_csv("masked_dataset.csv")
# Agree these with your qi-policy.yaml
QI = ["age", "zip_code", "sex"]
SA = ["diagnosis"]
# k-anonymity: returns int - the minimum equivalence-class size
k = anonymity.k_anonymity(data, QI)
print(f"k = {k}")
# l-diversity: returns int - minimum distinct SA values per class
l = anonymity.l_diversity(data, QI, SA)
print(f"l = {l}")
# t-closeness: returns float - maximum EMD across all classes
t = anonymity.t_closeness(data, QI, SA)
print(f"t = {t:.4f}")
Per github.com/IFCA-Advanced-Computing/pycanon:
k_anonymity(data, QI)-datais a pandas DataFrame;QIis a list of column name strings. Returns anint.l_diversity(data, QI, SA)-SAis a list of sensitive-attribute column names. Returns anint.t_closeness(data, QI, SA)- Returns afloat(the worst-case EMD across all equivalence classes). For numerical attributes, the one-dimensional Earth Mover's Distance definition is used (github.com/IFCA-Advanced-Computing/pycanon).
Step 4 - Interpret against thresholds
NIST
Установить k-anonymity-verifier в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл k-anonymity-verifier?
Use when a masked dataset must be proven to meet a k-anonymity, l-diversity or t-closeness threshold before it reaches a non-production environment. Computes equivalence classes over chosen quasi-identifiers with pycanon or ARX, reports re-identification risk and gates CI.
Как установить скилл k-anonymity-verifier?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл k-anonymity-verifier запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic