Skip to content
[nonimo]
EN
Try it free

Home / Blog

GDPR · Testing

Testing PII redaction before go-live: a CI test set

· 7 min read

A Cork health software firm has to show its DPO that patient data never reaches the model provider in clear text. This is the test suite it built.

The Nonimo teamData protection and AI integration, for engineering teams and DPOs.

In this article
  1. Why test redaction at all?
  2. What should a PII test set for Ireland and the UK contain?
  3. How do you assert that nothing leaks in CI?
  4. How do you report results by data type?
  5. What about the model's reply?
  6. What about text that identifies someone without a name?
  7. How does this look with the Nonimo Gateway?
  8. Testing PII redaction before go-live: checklist

Quick answer

Build a test set of invented people and placeholder identifiers, send it through your app in CI, and fail the build if any seeded value appears in a request bound for the AI provider. Add a round-trip test so the reply comes back with the real values, and tag every fixture by data type.

Ferncastle Health is a fictional software firm in Cork. Its product summarises referral letters for GP practices in Ireland and in England, and the summaries are drafted by a large language model through an API.

Before the first clinic went live, the firm's DPO, Deirdre Lynch, asked the engineering lead a direct question. How do we know that a patient's name, PPS number or NHS number never reaches the model provider in clear text?

"We redact them" was not an answer she could put in a DPIA. This article follows what Ferncastle built instead: a test set, assertions in CI and a report by data type that the DPO can read.

Why test redaction at all?

Article 32(1)(d) of the GDPR lists, among the measures to apply as appropriate, a process for regularly testing, assessing and evaluating the effectiveness of technical and organisational measures. The UK GDPR has the same wording, so Ferncastle's English clinics fall under the same duty with the ICO as regulator.

Article 25 adds data protection by design and by default. If redaction is the measure you rely on to keep patient data away from the provider, a repeatable test is how you show it works, and how you notice when a library upgrade or a prompt change quietly breaks it.

There is a practical reason too. Redaction failures are silent. The summary still reads well, the user is happy, and the only trace of a leaked NHS number is in a request you never look at.

That trace then becomes one more copy to find when a patient makes a subject access request.

What should a PII test set for Ireland and the UK contain?

Real patient data has no place in a test set. Ferncastle built its fixtures from invented people and from placeholder identifiers written so that nobody could mistake them for a real record: zeros, published test ranges and the word EXAMPLE.

The harder part is variety. Irish and British names and identifiers come in many shapes, and each shape is a separate chance to miss.

Data typeVariants in the setInvented examples
Irish namesStraight and curly apostrophes, fadas, Ní and Mac, hyphens, possessivesOrla O'Sullivan-Hayes, Seán O’Donoghue, Siobhán Ní Bhriain, Declan McAuley's
British namesDouble-barrelled, initials, surname first in formsGareth Pemberton-Ashe, A. K. Rahman, WHITFIELD, Priya
PPS numberSeven digits plus one or two letters, with and without spaces0000000A, 0000000AB, 0000000 A
NHS numberTen digits in 3-3-4 groups, unspaced, hyphenated999 765 4323, 9990000018, 999-765-4323
IBANIE and GB, grouped in fours and unbrokenIE00 AAAA 0000 0000 0000 00, GB00 AAAA 0000 0000 0000 00
Contact detailsEmail and UK phone formats[email protected], 0161 496 0000, 020 7946 0000
Near missesReference numbers, dates and codes that should stay readableREF-0000-0187, INV 000123, 12/03/2025

The near-miss row matters. It tells you whether the redaction step over-masks reference numbers and dates, which makes the model's summaries worse even if nothing leaks.

The IBANs use 00 check digits and the placeholder bank code AAAA, so they cannot match a real account. The NHS numbers start with 999, a range NHS England keeps for test records and never issues to patients.

The phone numbers come from Ofcom's drama ranges, and the email uses a reserved example domain.

Ferncastle still treats every value as if it were sensitive, because a test log is a log like any other. The fixtures live in one constants file, and every value in it is marked as an example.

# fixtures.py: every person and identifier here is invented.
CASES = [
    (
        "Seán O’Donoghue (PPS 0000000A) was seen by Dr Pemberton-Ashe; "
        "NHS 999 765 4323 on file from his time in Leeds.",
        [("person", "Seán O’Donoghue"), ("person", "Pemberton-Ashe"),
         ("pps", "0000000A"), ("nhs", "999 765 4323")],
    ),
    (
        "Rent refund for Siobhán Ní Bhriain to IE00 AAAA 0000 0000 0000 00.",
        [("person", "Siobhán Ní Bhriain"), ("iban", "IE00 AAAA 0000 0000 0000 00")],
    ),
]

How do you assert that nothing leaks in CI?

Each fixture is a short clinical sentence plus the list of values seeded into it, tagged by type. In CI, the app talks to a stub provider instead of the real one. The stub records every request body it receives and replies by echoing the user's message.

The tests then check two things. No seeded value may appear in any recorded request, as written or with spaces and hyphens removed. And because the stub echoes the message, the reply must contain every seeded value again, in the right place.

Redaction tests in a CI pipeline Invented fixturesnames, PPS, NHS, IBAN App + redaction[PERSON_1] Stub providerrecords each request No value leaksspaced and unspaced Round tripreply gets real values Report by typefailures name the type Any failure blocks the merge
Three checks on every build. The fixtures never contain real patients.

The two tests in pytest

import pytest
from fixtures import CASES        # invented text + seeded values
from harness import send_via_app  # returns (decoded_bodies, reply_text)

def squash(s: str) -> str:
    return s.replace(" ", "").replace("-", "")

@pytest.mark.parametrize("text, seeded", CASES)
def test_no_seeded_value_leaves(text, seeded):
    bodies, _ = send_via_app(text)
    for kind, value in seeded:
        for body in bodies:
            assert squash(value) not in squash(body), f"{kind} left: {value!r}"

@pytest.mark.parametrize("text, seeded", CASES)
def test_reply_has_real_values(text, seeded):
    _, reply = send_via_app(text)
    for kind, value in seeded:
        assert value in reply, f"{kind} not restored: {value!r}"

Keep the assertion message to the data type and the seeded value. Because every value is invented, it is safe to print, and the developer who breaks the build sees at once which variant slipped through.

Have the stub store each body decoded (json.dumps(json.loads(body), ensure_ascii=False)). In raw JSON a fada can travel as \u00e1, and the comparison would miss it.

How do you report results by data type?

A single pass or fail hides the detail Deirdre needed. A missed PPS number and a missed Irish surname are different problems with different fixes.

Because every seeded value carries its type, the CI report groups failures by type: person, PPS, NHS, IBAN, contact details. Deirdre reads that summary for each release, and the team does not need to explain test code to her.

Fixtures are only ever added, never removed, and each addition goes through review. Every miss found in review becomes a new fixture and stays for good, which turns the test set into a regression suite.

What about the model's reply?

The reply is where the round trip shows. If the provider writes "[PERSON_1] should be reviewed in six weeks", the clinician must read the patient's real name, in the right place, every time.

Ferncastle added fixtures that check this with streamed replies and with tool calls, because both split text into pieces. A label cut in half between two chunks is a classic source of broken output, so the stub also streams its echo in small pieces.

What about text that identifies someone without a name?

Clinical letters are full of context. "The retired harbour master from Cobh with the pacemaker fitted in March" names nobody, yet in a small town it may point to one person.

Ferncastle added a group of fixtures like this to the set, marked as context cases rather than leaks. They do not fail the build; they go to a human review once a month, and the team decides what the prompt template should leave out.

That review led to a design change. The summariser now receives the clinical content and the reason for referral, and the free-text social history stays in the source letter, which is Article 5(1)(c) minimisation applied at the template.

Practice names and local clinic names went into a separate group of fixtures. Those are the terms most likely to identify a patient indirectly, and a group of their own makes them easy to test.

How does this look with the Nonimo Gateway?

Ferncastle routes its summaries through the Nonimo Gateway, which sits between the application and the AI provider. Before each request leaves, it replaces personal data with labels such as [PERSON_1], and puts each real value back in the reply, in streaming and in tool calls too.

Ferncastle changed the base URL and the key in its client, and kept the official SDK, the model and the prompts. The fixtures and the stub stay in CI for the app's own code.

For each data type, Ferncastle chose what the Gateway does: mask it, stop the request, or only warn and count. The practice and clinic names went into the dashboard as custom terms, and the test set checks the chosen behaviour for each type.

For the check against the live Gateway, Deirdre gets three things, all of them figures only:

WhatWhat it showsWhat Deirdre uses it for
Local MCP connectorA test run with invented data, and the DPO reportA check after each code change
Monthly reportItems masked by typeThe Article 30 record and the DPIA
Per-request logTime, provider, model, counts by type (CSV or JSONL)Comparing a test run with the fixtures

Where the Gateway runs is on the security page. If your assistant answers from your own documents, our article on RAG and personal data shows where else to add fixtures.

Testing PII redaction before go-live: checklist

  • The test set uses invented people and example identifiers only.
  • Identifiers are placeholders that cannot belong to anyone (zeros, published test ranges, EXAMPLE), and near misses are included.
  • Irish name forms (O', Mc, Mac, Ní, fadas, curly apostrophes) are covered.
  • CI fails if any seeded value appears in a request bound for the provider, spaced or unspaced.
  • A round-trip test checks that replies come back with the real values, including streamed replies and tool calls.
  • Every fixture is tagged by data type, and the CI report groups failures by type.
  • Every miss found in review becomes a permanent fixture.
  • The test process and its results are referenced in the DPIA under Article 32(1)(d).

The same fixtures are handy for a dry run of a subject access request, as described in subject access and erasure in LLM apps. To try the Gateway against your own test set, see the trial on the pricing page.

Common questions

Can we use real patient records to test redaction?

Avoid it. Invented people and placeholder identifiers, such as zeros, published test ranges and the word EXAMPLE, exercise the pipeline just as well and keep real patient data out of test logs, CI output and developers' laptops.

Which NHS numbers are safe to use in test data?

Numbers starting with 999. NHS England keeps that range for test records and never issues it to patients, so a fixture such as 999 765 4323 cannot point to a real person. Still treat test logs like any other log.

What should an Irish and UK test set cover?

Name forms first: fadas, O' and Mc with straight and curly apostrophes, Ní and Mac, double-barrelled surnames and surname-first forms. Then PPS and NHS numbers, IBANs and contact details, spaced and unspaced, plus near misses that must stay readable.

How often should redaction tests run?

On every build, plus a run against the live set-up before each release. Article 32(1)(d) of the GDPR and the UK GDPR lists regular testing of the effectiveness of security measures among the measures to apply as appropriate.

Why can a leak test pass when data has actually left?

Often because it compares raw JSON. A serialiser that escapes non-ASCII characters turns a fada into a \u sequence, so the seeded value no longer matches. Decode each recorded body before comparing, and check spaced and unspaced forms.

Should context cases fail the build?

Usually not. Text that identifies someone without a name, such as a job and a small town, is better sent to a human review on a fixed schedule. The outcome is often a template change that keeps that context out of the prompt.

What should the DPIA say about redaction testing?

Describe the test set, how often it runs, what fails the build and who reviews the results, and reference it under Article 32(1)(d). Attach the CI summary by data type so the DPO can follow it without reading test code.

Can we test the Nonimo Gateway without sending real data?

Yes. Its local MCP connector can run a test with invented data and download the DPO report, and the per-request log shows counts by data type to compare with your fixtures. See the security page.

Sources

  1. Regulation (EU) 2016/679 (General Data Protection Regulation)
  2. UK GDPR (retained Regulation (EU) 2016/679)
  3. Data Protection Act 2018 (Ireland)
  4. Data Protection Act 2018 (UK)
  5. EDPB Guidelines 01/2025 on Pseudonymisation (version for public consultation)
  6. ICO, Guidance on AI and data protection

More articles

Nonimo Gateway redacts personal data before your request reaches the AI provider and puts it back in the reply.

See how it works
€0 today10 days free · cancel any time

Try Nonimo Gateway

Try it free on real requests from your own applications.

Then €290/month inc. VAT, only if you carry on.

We’ll use your email to send you the trial and remind you before it ends. Privacy.

Questions? Email [email protected]

Already have a Gateway? Go to Your Gateway