agentleFS
obielinobielin/responsible-ai-skills/skills/responsible-data-handling/SKILL.md

responsible-data-handling

Skill2 starsChanged 8 months agoMITView on GitHub

Use when accessing, loading, processing, or storing any dataset — especially one containing personal, sensitive, or demographic data. Run before any data pipeline code.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Rule: If a column is not in your model's feature set or your analysis plan, do not load it.

    line 51
  2. Distinctive:

    Never report statistics on groups smaller than 5:

    line 90
  3. Distinctive:

    Every access to personal or sensitive data must be logged:

    line 146
  4. Distinctive:

    Every dataset must have a documented retention schedule:

    line 187

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Responsible Data Handling

Data is the foundation of AI. How you handle it determines whether the system is lawful, fair, and trustworthy. Before writing a single line of data pipeline code, complete this skill.

Step 1: Classify Your Data

Classify every data source before touching it:

ClassDescriptionExamplesRequirements
PublicNo personal data, publicly availableONS statistics, OpenStreetMapStandard care
InternalOrganisation data, no personal infoProduct logs (anonymised), configAccess controls
PersonalIdentifies or can identify individualsNames, emails, IP addressesUK GDPR applies
Sensitive PersonalSpecial category under UK GDPRHealth, ethnicity, religion, biometricsExplicit legal basis required
High RiskPersonal + significant impact decisionsBenefits data, criminal recordsDPA 2018 Schedule 1 + DPIA

Action: Label every dataset in your code:

# DATA CLASSIFICATION: Sensitive Personal (health records)
# LEGAL BASIS: Article 9(2)(h) — medical treatment purposes
# RETENTION: 8 years per NHS Records Management Code
# ACCESS: Restricted to authorised clinical staff only
df_patients = load_patient_records(...)

Step 2: Apply Data Minimisation

Load only what you need. Every unnecessary field is a liability:

# BAD: Loading everything and filtering later
df = pd.read_csv('patients.csv')
df = df[['age', 'diagnosis']]  # the name and postcode were loaded into memory

# GOOD: Select columns at load time
df = pd.read_csv('patients.csv', usecols=['age', 'diagnosis'])

# GOOD: SQL — select only what's needed
query = "SELECT age, diagnosis FROM patients WHERE cohort = 'study_group'"
df = pd.read_sql(query, conn)

Rule: If a column is not in your model's feature set or your analysis plan, do not load it.


Step 3: Handle Personal Identifiers

Anonymisation vs Pseudonymisation

TechniqueWhat It DoesStill Personal Data?
AnonymisationIrreversibly removes all identifiersNo
PseudonymisationReplaces identifiers with tokensYes — UK GDPR applies
AggregationReports only group statisticsNo (if k≥5)
import hashlib
import pandas as pd

def pseudonymise(df: pd.DataFrame, id_cols: list[str], salt: str) -> pd.DataFrame:
    """
    Replace identifying columns with consistent pseudonymous tokens.
    The salt must be stored securely and separately from the data.
    """
    df = df.copy()
    for col in id_cols:
        df[col] = df[col].apply(
            lambda x: hashlib.sha256(f"{salt}{x}".encode()).hexdigest()[:16]
            if pd.notna(x) else None
        )
    return df

# Load salt from environment — NEVER hardcode
import os
SALT = os.environ['DATA_PSEUDONYMISATION_SALT']
df = pseudonymise(df, id_cols=['patient_id', 'nhs_number'], salt=SALT)

Suppression — Small Number Suppression

Never report statistics on groups smaller than 5:

def suppress_small_groups(
    df: pd.DataFrame,
    group_col: str,
    value_col: str,
    min_count: int = 5
) -> pd.DataFrame:
    """Suppress statistics where group count < min_count."""
    counts = df.groupby(group_col)[value_col].count()
    suppressed_groups = counts[counts < min_count].index
    df = df.copy()
    df.loc[df[group_col].isin(suppressed_groups), value_col] = None
    return df

Step 4: Secure Data Storage and Access

# NEVER store credentials in code
# BAD:
conn = connect(host='db.internal', password='mypassword123')

# GOOD: Environment variables or secrets manager
import os
conn = connect(
    host=os.environ['DB_HOST'],
    password=os.environ['DB_PASSWORD']
)

# NEVER log personal data
import logging
logger = logging.getLogger(__name__)

# BAD:
logger.info(f"Processing patient {patient_name}, DOB {date_of_birth}")

# GOOD:
logger.info(f"Processing patient record {record_id}")

File permissions — never leave data world-readable

# Set appropriate permissions on data files
chmod 640 data/sensitive_dataset.csv  # owner + group read, no world access
chmod 700 data/raw/                    # only owner can access raw directory

Step 5: Audit Logging

Every access to personal or sensitive data must be logged:

import logging
import json
from datetime import datetime, timezone

audit_logger = logging.getLogger('audit')

def log_data_access(
    user: str,
    dataset: str,
    purpose: str,
    records_accessed: int,
    fields_accessed: list[str]
) -> None:
    """Write an immutable audit log entry for data access."""
    entry = {
        'timestamp': datetime.now(timezone.utc).isoformat(),
        'user': user,
        'dataset': dataset,
        'purpose': purpose,
        'records_accessed': records_accessed,
        'fields_accessed': fields_accessed,
    }
    audit_logger.info(json.dumps(entry))

# Use it everywhere you access personal data
log_data_access(
    user=current_user(),
    dataset='patient_records',
    purpose='training_diagnostic_classifier',
    records_accessed=len(df),
    fields_accessed=list(df.columns)
)

Step 6: Data Retention and Deletion

Every dataset must have a documented retention schedule:

# Add to every data loading function
DATA_RETENTION = {
    'patient_records': '8 years (NHS Records Management Code)',
    'benefits_applications': '6 years (Limitation Act 1980)',
    'model_training_data': '3 years (internal policy)',
    'audit_logs': '7 years (HMRC / public sector standard)',
}

def check_retention(dataset_name: str, data_date: str) -> None:
    """Raise if dataset is past its retention date."""
    from dateutil.parser import parse
    from dateutil.relativedelta import relativedelta
    ...

Completion Checklist

  • Every data source classified (Public / Internal / Personal / Sensitive / High Risk)
  • Legal basis documented in code comments for any personal data
  • Data minimisation applied — only necessary columns loaded
  • Personal identifiers pseudonymised or anonymised as appropriate
  • Small number suppression applied to any published statistics
  • No credentials or personal data in logs or code
  • Audit logging implemented for all personal data access
  • Retention schedule documented

Proceed with your data pipeline. Run bias-assessment before training any model on this data.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.