Skip to main content

Privacy by Design for AI Systems: GDPR Article 25 in Practice

GDPR Art. 25 in an ML pipeline means knowing where the copies of data are: a runnable register with expiry dates, pseudonyms and erasure requests.

What do you think about this article?

Privacy by Design for AI Systems: GDPR Article 25 in Practice
EU AI ActPhoto:RDNE Stock projectPexels

At a Glance

GDPR Art. 25 in an ML pipeline means knowing where the copies of data are: a runnable register with expiry dates, pseudonyms and erasure requests.

Privacy by design in an ML pipeline: knowing where the data are, for how long, and who has them

Article 25 of the GDPR asks for two things that break in a machine learning pipeline for the same reason. Paragraph 1: appropriate technical and organisational measures, such as pseudonymisation, both at the time of the determination of the means for processing and at the time of the processing itself, to implement principles such as data minimisation. Paragraph 2: that by default only the personal data necessary for each specific purpose are processed, as regards the amount collected, the extent of processing, the period of storage and accessibility. The common reason is that personal data, in a pipeline, get copied: the raw export, the training dataset and its versions, the inference logs, the embedding cache, the model. If you do not know where the copies are, you cannot delete them at expiry or find them when a data subject asks.

This article takes the engineering side: a register of artefacts with expiry dates and erasure requests, in a program you can run. The framework where the GDPR and the AI Act meet (legal basis, Article 22, impact assessments, log retention) and minimisation with k-anonymity are in the previous article of the series, on privacy by design and the AI Act; I do not repeat them here. This is not legal advice: it says what the rules provide, with the article beside it, and where a number is your choice and not the law's.

What the GDPR asks about copies

Four provisions decide the design. Article 5(1), point (e), requires that data be kept in a form which permits identification for no longer than is necessary for the purposes; point (c) requires that they be limited to what is necessary; paragraph 2 requires that the controller be able to demonstrate compliance. Article 15 gives the data subject the right to obtain access to the data and information such as the purposes, the categories, the recipients and, where possible, the envisaged period of storage or the criteria used to determine it. Article 17 gives the right to erasure, among other grounds when the data are no longer necessary in relation to the purposes. Article 12(3) requires answering without undue delay and in any event within one month of receipt of the request, extendable by two further months where necessary, taking into account the complexity and number of requests.

The link between the four is time and proof: you can answer within a month only if within a month you can find all the copies, and you can demonstrate compliance with point (e) only if a declared expiry date exists for each artefact. No rule gives you the days: you justify the duration yourself with the purpose. The record of processing activities of Article 30 remains the legal duty; the technical register of artefacts that follows is the layer beneath it, the one that lets you keep it true.

A register of artefacts, with expiry dates and requests

The program models each copy as an immutable Artefatto (artefact): name, type (dataset, log, model, cache), creation date, retention days (or None if it is needed as long as the model is in use, to be justified), the set of pseudonyms of the subjects present and, for derived artefacts, the artefact they come from. Subjects are identified by a pseudonym computed with HMAC-SHA256 and a key kept outside the repository: Article 4, point (5), requires that the additional information for re-attributing the data be kept separately, and the key is exactly that information. A pseudonym does not make the data anonymous; it serves to link the artefacts of the same subject without carrying name and tax code in every file.

Three functions do the work. scaduti (expired) returns the artefacts past their expiry date, that is, the check that a nightly job should run before deleting. richiesta (request) receives a pseudonym and returns, for each artefact that contains it or derives from one that does, the action to take: datasets are rewritten without the subject and derived versions are regenerated, logs are cleaned, caches are emptied. For the model the program does not decide: it prints "HUMAN DECISION", because the GDPR does not say whether a model trained on a datum "contains" it, and I have no rule to give you. The last part answers an access request under Article 15 by saying where the subject appears. Data and dates are fixed: the run is reproducible, and two consecutive runs gave the same output.

"""Register of the artefacts of an ML pipeline with personal data: expiry dates and erasure requests.
References: GDPR Art. 5(1)(e) storage limitation, Art. 15 access, Art. 17 erasure, Art. 25.
Synthetic data: no real data. Dates are fixed to make the run reproducible."""
import hashlib
import hmac
from dataclasses import dataclass
from datetime import date, timedelta

CHIAVE = b"chiave-tenuta-fuori-dal-repository"  # example key, kept as in the original: changing it changes every pseudonym; in production: a secrets manager


def pseudonimo(codice_fiscale: str) -> str:
    """Same subject, same pseudonym: it links the artefacts, it does not anonymise."""
    return hmac.new(CHIAVE, codice_fiscale.encode(), hashlib.sha256).hexdigest()[:10]


@dataclass(frozen=True)
class Artefatto:
    nome: str
    tipo: str            # "dataset" | "log" | "modello" | "cache"
    creato: date
    conserva_giorni: int | None   # None = as long as needed, to be justified
    soggetti: frozenset  # pseudonyms present in the artefact
    derivato_da: str | None = None


def scaduti(registro: list, oggi: date) -> list:
    return [a.nome for a in registro
            if a.conserva_giorni is not None and a.creato + timedelta(days=a.conserva_giorni) < oggi]


def richiesta(registro: list, p: str) -> list:
    """Where subject p appears, and what to do for each type of artefact."""
    azione = {
        "dataset": "rewrite without the subject and regenerate the derived versions",
        "log": "delete the subject's rows",
        "cache": "empty",
        "modello": "HUMAN DECISION: assess retraining (no automatic rule)",
    }
    nomi = {a.nome for a in registro if p in a.soggetti}
    # a model is touched if it derives from an artefact that contains the subject
    toccati = [a for a in registro if p in a.soggetti or (a.derivato_da in nomi)]
    return [(a.nome, azione[a.tipo]) for a in toccati]


if __name__ == "__main__":
    anna, luca, sara = (pseudonimo(c) for c in ("RSSNNA85A41L219X", "BNCLCU90B12H501Y", "VRDSRA82C45F205Z"))
    registro = [
        Artefatto("train_v1.parquet", "dataset", date(2026, 6, 1), 180, frozenset({anna, luca})),
        Artefatto("train_v2.parquet", "dataset", date(2026, 9, 1), 180, frozenset({luca, sara})),
        Artefatto("inferences_october.log", "log", date(2026, 10, 31), 30, frozenset({anna, sara})),
        Artefatto("embedding_cache", "cache", date(2026, 11, 1), 7, frozenset({sara})),
        Artefatto("scoring_v2.pkl", "modello", date(2026, 9, 3), None, frozenset(), derivato_da="train_v2.parquet"),
    ]
    oggi = date(2026, 11, 13)
    print("Anna's pseudonym:", anna)
    print("expired on", oggi, ":", scaduti(registro, oggi))
    print("\nerasure request from Luca:")
    for nome, cosa in richiesta(registro, luca):
        print(f"  {nome:<24} {cosa}")
    print("\naccess request from Sara (where she appears):")
    print(" ", [a.nome for a in registro if sara in a.soggetti])

# Output:
# Anna's pseudonym: 0cce6c0128
# expired on 2026-11-13 : ['embedding_cache']
#
# erasure request from Luca:
#   train_v1.parquet         rewrite without the subject and regenerate the derived versions
#   train_v2.parquet         rewrite without the subject and regenerate the derived versions
#   scoring_v2.pkl           HUMAN DECISION: assess retraining (no automatic rule)
#
# access request from Sara (where she appears):
#   ['train_v2.parquet', 'inferences_october.log', 'embedding_cache']

Three lines of the output deserve careful reading. The first: embedding_cache has already expired on the fixed date, and until the job has deleted it, it holds data beyond the purpose, which is the condition of Article 5(1), point (e), violated in fact. The second: Luca's erasure request touches two datasets, which must be rewritten, and a model derived from the second, which the program does not decide on its own. The third: Sara's access request also finds the expired cache, so a targeted deletion at expiry protects you both on the retention side and on the response side.

What the program does not do, and what you have to add

It deletes nothing: it is a register and a plan, and real deletion touches storage, backups and replicas. The values 180, 30 and 7 days are examples, not indications of law. It does not state whether a model contains personal data, and that is the element I find most fragile to automate: the choice between retraining, documenting why it is not needed or doing something else is your decision, to be recorded with its reasons. It knows nothing about copies outside the pipeline, such as backups or exports downloaded onto someone's laptop; if they do not enter the register, they do not enter the answer.

For a high-risk system under the AI Act there is an interaction not to be forgotten. Automatically generated logs must be kept for at least six months, but "unless provided otherwise" in the applicable Union or national law, in particular Union law on the protection of personal data (Art. 19 and Art. 26(6)): the AI Act minimum does not cancel minimisation. Those obligations apply from 2 December 2027 for Annex III, under Regulation (EU) 2026/1744. The relationship between logs, the provider's proof and liability for damage is in the article on software liability.

Impact assessment: when the register helps to carry it out

Article 35 requires a data protection impact assessment prior to the processing where a type of processing, in particular using new technologies, is likely to result in a high risk to the rights and freedoms; a single assessment may address a set of similar processing operations that present similar high risks. The deployer of a high-risk AI Act system uses the information of Article 13 for this assessment (Art. 26(9)). The register of artefacts does not replace the assessment, but gives it the material that is usually missing: a list of flows, declared retention times, who accesses what. How the two texts fit together is in the article on the AI Act and the GDPR.

Frequently asked questions

Is pseudonymisation mandatory?

Not as such. Article 25(1) cites it as an example of a measure ("such as pseudonymisation") and Article 32(1), point (a), lists it among the security measures to be taken "as appropriate". What is mandatory is to implement the principles, minimisation included, with measures appropriate to the risk; which ones, you choose and document.

How long must I keep inference logs?

The GDPR gives no duration: it depends on the purpose, and you have to justify it. For high-risk systems under the AI Act the minimum is six months, unless other rules provide otherwise, starting from the dates of application. A log with personal data kept "for safety" beyond the purpose is justified by neither of the two rules.

If a data subject asks for erasure, do I have to retrain the model?

The GDPR does not say so in automatic terms. Article 17 requires erasing personal data when one of the listed grounds applies, and the register tells you where they are; what to do about the derived model is a decision to document case by case, and it has to be taken before the request arrives, not during the month you have to answer.

What you can do now

You know what Articles 5, 12, 15, 17 and 25 of the GDPR ask about copies of data, you can model them in a register with expiry date, pseudonym and provenance, and you know which decisions the program leaves to you: the duration, the backups, the fate of the model. The next step, with the AI Act framework on top, is in the compliance toolkit and in the article on providers and deployers, which explains why not all your obligations are those of the provider.

Sources

The listing was run with Python 3.14.4, with identical output in two runs; it uses synthetic data, no real data, and an example key. The GDPR text is the one published in 2016, not a later consolidated version. The amending act 2026/1744 was not re-read in full.

Commenti

Caricamento commenti...

Sign in to comment

New articles and tools on Telegram too

The Telegram channel flags the site's new articles and tools.

Did you like this article?

Explore other content on the blog or discover my projects