Protecting personal data in development, AI agents and chat

Personal data leaves the protected system by different routes: as a test copy for developers, through an AI agent with database access, or in a chat with a cloud model. The article shows, for each route, where the data is best protected and which tools exist for this.

Analysis · Published 11 Nov 2026 · Updated 12 Nov 2026 · Joel Barmettler

Where personal data should disappear before developers, agents or cloud models see them

When a development team, an AI agent or a cloud model gets access to customer data, each of them quickly sees more than it needs. How much more depends on where the company removes the personal data. There are five such points, from a cleaned copy of the database to a model the company runs itself. Each point suits one kind of recipient in particular.

The first two parts of this series showed how easily people can be recognised even in data without names, and what the law requires before such data leave the company. The series keeps to one example: a family practice in the Knonaueramt and its patient Hildegard Kaufmann, 87, from Maschwanden. The practice and the patient are invented. The technical question remains open: at which point in the data flow is it best to remove the personal data? There is no single answer, because the recipients differ. The vendor of the practice software needs a test database that behaves like the real one. An AI agent for the practice administration writes its own queries. A chat in which the doctor has a model draft referral letters receives whole letters, with names and diagnoses in the middle of sentences.

This article goes through the five points in order, with tools, strengths and limits. One graphic per point shows what stays in the practice and what goes outside. A matrix then shows which point suits which use case.

Point 1: a masked copy of the database

Point 1: masked copy

In the practice

Practice database real values, stays in the practice
Anonymised here Anonymise once, before handing over
Masked copy substitute values instead of real names

Boundary

Outside

Vendor’s developers work only with the copy

Only the masked copy goes to the vendor of the practice software. The real practice database stays in the practice.

Static masking creates a copy of the production database that holds substitute values. Names are replaced by other names, AHV numbers (the Swiss social security number) by other valid AHV numbers, and amounts are changed slightly. The copy goes to the development team, to a test system or to a service provider. Production stays untouched. In the copy for the vendor of the practice software, Hildegard Kaufmann has a different name and a different AHV number.

For PostgreSQL there are two widely used open-source tools. PostgreSQL Anonymizer, from the French company Dalibo, defines the rules directly in the database and can produce masked exports as well as static copies.[1] Greenmask works during export and can replace values so that the same original value receives the same substitute. That way the tables still fit together.[2] For larger environments with several database systems, commercial vendors such as Tonic, Perforce Delphix, DATPROF or Redgate offer test data platforms.[3–6]

The strength of this pattern: whoever receives the copy sees no real values in the columns covered by rules, regardless of the queries they write. The weakness: every column needs a rule. If a new column is added and nobody adds the rule, the new column reaches the copy unchanged.

Why replacing columns one by one is not enough

The obvious route is to replace each column on its own, or to shuffle the values of a column between people. We measured this route and a consistent replacement with our own prototype on an invented practice database: 2,500 patients from the 14 municipalities of the Bezirk Affoltern, about 18,000 consultations with notes and as many invoices.[7] Hildegard Kaufmann is one of the patients. The table shows Hildegard Kaufmann and a second patient in three versions.

In the shuffled copy, the amount still matched tariff points times point value on only 0.06 per cent of invoices. None of the 1,539 email addresses still matched its name. Software that checks such values raises an alarm in the test, although the fault lies in the test data. Data protection weighs more: shuffling removes no value at all. All 2,500 real AHV numbers and 3,419 real names in the notes are still in the copy, only filed under other people.

In the consistently pseudonymised copy, the amount matched tariff points and point value on all of the roughly 18,000 invoices. All 1,539 email addresses matched the new name. All links stayed valid, and every consultation still hung on the same, renamed person.

What a usable copy must deliver

The measurement yields five requirements. A company can demand them from a tool or from the service provider that produces the copy.

  1. Same value, same replacement. A patient number needs the same replacement in every table, otherwise consultations and invoices no longer fit together. The replacement is therefore computed from the real value and a secret key, usually with the HMAC method. A plain hash without a key is not enough: anyone with a list of possible AHV numbers recomputes the hashes and finds the real numbers. The FDPIC therefore recommends a hash with a secret key.[8] The key is kept separate from the copy.
  2. One substitute person per human, in free text too. Name, email address and mentions in notes get the same invented person. Of the 12,068 notes that name the patient’s own surname, none still contained the real surname in the copy.
  3. Valid numbers. AHV numbers and IBANs carry check digits that many programs verify on input. The substitute number is therefore produced with format-preserving encryption and a recomputed check digit. In the copy, all 2,500 AHV numbers were valid.
  4. Treat related values together. Tariff points, point value and amount are swapped as a package with another invoice of the same year and the same law (KVG or UVG). A person’s dates of birth and appointments are shifted by the same amount. This has a price: the amount then belongs to a different consultation, and for 4.6 per cent of consultations the shifted date moved into the future.
  5. A check report after every run. A program searches the finished copy for real values. The report shows where rules are missing. Our copy still contained 164 AHV numbers written without dots and 272 phone numbers written with 0 instead of +41, because the rules did not know these spellings, plus 116 full names of relatives. We built these cases into the invented notes on purpose to measure the limit of the rules. How often such spellings occur in real notes only the report on your own database shows. Such leftovers are found by a recognition model like the one in the proxy section below, or by a person who reads a sample.

The rules sit in a readable file, one rule per column, which a person approves. The same source, the same rules and the same key produce the same copy: two runs of our prototype produced a byte-identical database.

Why the copy is still not anonymous

In the copy, Hildegard Kaufmann carries another name, yet she can still be found. Sex, date of birth and municipality stay in the copy because the vendor wants to test with realistic ages and places of residence. By sex, birth year and municipality, 86 per cent of patients in the copy sat in groups of fewer than five people, almost as many as in the original. The shifted date of birth helped little. Someone who knows that Hildegard Kaufmann was born on 14 March 1939 searches for women from Maschwanden with a date of birth up to 180 days before or after. We produced the copy with 1,000 different keys: every time, the search found one or two women. For all 1,000 keys, the only woman found with heart failure was Hildegard Kaufmann. Then there is the house number: the rule replaced the street name and kept the number. As the only woman in Maschwanden with this house number, Hildegard Kaufmann stayed unique.

Only coarser information changes that. With five-year age groups and the Bezirk instead of the municipality, nobody in the copy sat in a group of fewer than five. Many tests can live with this precision; analyses by municipality cannot. The first part of this series shows how to measure whether a coarsening is enough.

For the practice, which keeps the key, the copy remains personal data. Whether the copy also holds personal data for the vendor depends, as the second part explains, on whether the vendor can recognise people with reasonable effort. For Hildegard Kaufmann, sex, municipality, date of birth and diagnosis are enough. An employee of the vendor who knows Hildegard Kaufmann from the municipal newsletter or the neighbourhood finds the row. As long as that is possible, the copy belongs under a processing agreement under Art. 9 revFADP. Patient data are also subject to professional secrecy (Art. 321 of the Swiss Criminal Code). The second part describes which routes for passing them on remain.

Point 2: a mask on every query

Point 2: mask at query time

In the practice

Practice database real values, no copy
Anonymised here Mask hides values at every query
Practice team sees in the dashboard only what their role allows

Boundary

Outside

No copy leaves the practice. For outsiders the mask is not enough: anyone who writes their own queries can infer hidden values.

A mask directly on the real practice database hides, at every query, what a role may not see, for example the diagnoses at the reception desk.

Dynamic masking leaves the data unchanged. Only when a particular user runs a query does the database show a mask, such as “XXXX” instead of a phone number. SQL Server and Azure SQL call this Dynamic Data Masking, Oracle calls it Data Redaction, and PostgreSQL Anonymizer offers dynamic masking as well.

Dynamic masking is convenient because no copy is needed. The vendors themselves, however, describe its limit. Microsoft writes in its documentation that anyone allowed to run their own queries can infer the real data with skilful queries. According to Microsoft, masking prevents accidental exposure but does not protect against deliberate attempts to find out the values.[9] The documentation shows how this works with an example: a query with the condition “salary greater than 99,999 and less than 100,001” finds the person with exactly this salary, even though the salary is shown masked. Oracle states the same: Data Redaction does not protect against users who find out values through repeated queries.[10]

For a development team or an AI agent that writes its own queries, dynamic masking is therefore not sufficient protection. For a dashboard in which the practice team reads finished reports, dynamic masking can be enough. What a person may see on screen, they can still pass on, for example to a cloud model. Only the proxy at the fourth point protects against that.

Point 3: a subset or synthetic data

Point 3: synthetic data

In the practice

Practice database real values, stays in the practice
Anonymised here Generator learns distributions and relationships
Invented records no real person

Boundary

Outside

Vendor’s developers test with invented data

Only newly generated records go outside. A measurement still has to show whether rare real combinations reappear in them.

A test system often does not need all of the millions of records. A subset is enough as long as the links are correct: every consultation comes with its patient, every patient with their address. Tools such as the open-source program Jailer extract such a subset and keep the foreign keys intact.[11] The subset still has to be masked afterwards, because the subset contains real people.

Synthetic data go one step further. A generator learns the distributions and relationships of the real data and produces new records that are meant to match no real person. Well-known libraries are SDV from DataCebo, under a Business Source License, and the software development kit from MOSTLY AI, which has been under an open-source licence since 2025.[12, 13]

Synthetic data are well suited to development and testing. For analyses they are of limited use, because rare cases and individual values are not reliably reproduced. If a generator learns the original data too precisely, the generator can reproduce real records. A measurement is needed here too: do rare combinations from the original data reappear in the result?

Point 4: a proxy in front of the language model

Point 4: proxy in front of the language model

In the practice

Doctor has a letter drafted
Anonymised here Proxy swaps names for placeholders, puts names back into the answer

Boundary

Outside

Cloud model sees placeholders instead of names

The cloud model receives the letter with placeholders instead of names and numbers. The proxy puts the real values back only in the answer.

In chat and document work, text goes to a language model. Proxies exist for this purpose: programs that sit between the application and the model. These programs detect names, numbers and addresses in the text, replace them with placeholders such as “PERSON_1” and send only the cleaned text to the model. When the answer comes back, these programs put the original values back in.

A widely used open-source tool for this is Presidio. Presidio was developed at Microsoft and has continued as an independent community project since June 2026.[14] Presidio can encrypt the replaced original values and decrypt them later. By default, however, Presidio is configured for English. Other languages have to be set up separately.[15, 16] gheim is built specifically for Switzerland. The founder of Souverana developed this open-source tool, so we are not independent where gheim is concerned. gheim ships with a recognition model trained on texts in the four national languages.[17]

We show the round trip with Presidio, configured as in the project comparison further down: with the GLiNER recognition model and rules for Swiss formats. We tested two invented examples from the practice: a short doctor’s letter about Hildegard Kaufmann and three rows from the patient list. Because the recognition model does not decide the same way on every run, we ran each example ten times. The graphic shows what the proxy detected and sent to the model.

In the doctor’s letter, Presidio replaced name, date of birth, place of residence, AHV number and phone number. It also replaced the month “Oktober” and the word “Patientin” (female patient), which Presidio classed as a name. The diagnosis went to the model in clear text, because this configuration contains no rule for health information. The answer comes back with the original values. The patient rows show the limit. The proxy judges each value on its own. In 8 of 10 runs Presidio replaced only the dates of birth. Municipality, sex and diagnosis remained in place. In 2 runs Presidio additionally replaced “Maschwanden” twice, classed as a name. Whether a combination is rare and reveals a person is something the proxy cannot judge. For that, the proxy would need to know the whole table and the population of the municipality, for example that according to the Federal Statistical Office exactly one woman born in 1939 lives in Maschwanden. In addition, the model now lacks the date of birth: the model can no longer answer questions about age. Depending on its configuration, a proxy therefore replaces too little in tables, or so much that the analysis suffers. For tables, Presidio Structured, an add-on to Presidio, offers an approach that classifies columns by name and content.[18] Which combinations are rare, however, only a measurement like the one in the first part of this series can tell.

How reliably the proxy finds personal data

A proxy only protects what its detection finds. A project comparison on 484 synthetic Swiss texts with 2,934 items of personal data such as names, AHV numbers, addresses and IBANs shows how much the configuration matters. Dates of birth are not counted.[19] The comparison is not public.

Key figure

804 → 72
Undetected items of personal data out of 2,934 with Presidio, once in its default configuration and once with the GLiNER recognition model and rules for Swiss formats. Measured on 484 synthetic Swiss texts, excluding dates of birth.

Source: Project comparison, October 2026, not public

In its default configuration, Presidio missed just over one item in four. With the GLiNER recognition model and rules for Swiss formats such as AHV numbers, case numbers and dates of birth, it missed fewer than 3 in 100. The rules were written with knowledge of the test texts, so the second figure is probably flattering. For your own use, this means a company has to set up the rules for Swiss formats itself. Only a measurement on twenty to fifty of your own examples shows how much the proxy misses, and it belongs before real data pass through the proxy.

Point 5: the model sees only the structure or runs in-house

Point 5: model run in-house

In the practice

Practice database real values
Own model runs in-house
Practice team access rights decide who sees what

Boundary

Outside

No model provider receives patient data.

The in-house model works with real values without patient data leaving the practice. Access rights decide who in the practice team sees what.

One variant: the model sees only the structure of the database, that is, table names, columns and examples with invented values. The model writes the query from this structure, and the query runs in the company’s own system. The values themselves stay in the database; the model sees only their structure. This variant suits analyses and dashboards.

The other variant: a model run in-house sees the real values. Because the data stay in-house, anonymisation for a model provider is no longer needed. Open models such as the Swiss Apertus can run on the company’s own hardware or at a Swiss hosting provider. Anyone in the practice who accesses the model sees the real values. Access rights therefore determine who may use the model.

Which point suits which use case

The five points can be combined, and in practice a company often needs two or three. The matrix shows our assessment for four typical use cases. Select a case to read the reasons.

Tools that assess the risk of re-identification check whether a cleaned copy or an export is anonymous enough. The open-source program ARX supports, among other things, k-anonymity, l-diversity and differential privacy.[20] The R package sdcMicro comes from official statistics and estimates the risk that individual people in a dataset can be recognised.[21] For text, Presidio remains a widely used open choice, with the limits described above.

How to get started

  1. 01

    List the recipients

    Note who receives data: development team, test system, AI agent, cloud model, dashboard. For each recipient, record whether the recipient can write their own queries.

  2. 02

    Choose the point

    Use the matrix to choose the right point for each recipient. For developers and agents with query rights, choose a cleaned copy.

  3. 03

    Measure on your own examples

    Put together twenty to fifty typical texts and tables with invented values and check what the tool detects. Test Swiss formats such as AHV numbers, case numbers and dates of birth in particular.

  4. 04

    Maintain the rules

    With every new column and every new document type, extend the rules and repeat the measurement.

Sources

[1]
Templ, Matthias. «sdcMicro: Statistical Disclosure Control Methods for Anonymization of Data and Risk Estimation». 12 June 2026. cran.r-project.org/package=sdcMicro. Open Source, GPL-2.

Frequently asked questions

What is the difference between static and dynamic data masking?
Static masking creates a copy of the database in which the real values are replaced. Dynamic masking leaves the data unchanged and hides values only at query time, for particular users. Microsoft and Oracle write in their documentation that users with their own query rights can infer masked values through targeted queries.
Can I use real production data for testing?
With personal data, only if the processing is permitted for that purpose and the test system is as well protected as production. A masked copy with valid formats or a subset with synthetic values can replace the real data. Tools such as PostgreSQL Anonymizer or Greenmask produce such copies so that the same original value is replaced the same way everywhere. This is an assessment, not legal advice.
Is a pseudonymised test database anonymous?
Usually not. Pseudonymisation replaces names and numbers; attributes such as date of birth, sex and municipality remain. In a Souverana measurement on an invented practice database, 86 per cent of people in the copy sat in groups of fewer than five by sex, birth year and municipality. Anyone who needs anonymity has to coarsen these attributes and measure the result.
Does Presidio detect German and Swiss personal data?
Presidio, a widely used open-source tool for detecting personal data, is designed for English in its default configuration. Users have to set up other languages and Swiss formats such as AHV numbers themselves. In a project comparison on 484 synthetic Swiss texts, Presidio with Swiss rules and the recognition model GLiNER detected around 97 per cent of the personal data, dates of birth not counted.
What does a proxy in front of a language model such as ChatGPT do?
The proxy detects names, numbers and addresses in the text, replaces them with placeholders such as <PERSON_1> and sends only the cleaned text to the model. In the answer, the proxy puts the original values back. With running text this works well. With table rows, the proxy judges each value on its own. Whether a combination such as date of birth, sex and municipality reveals a person is something the proxy cannot detect.

LinkedIn

Share this article

Ready-formatted graphics and a suggested post for your LinkedIn feed: download, copy, post.

Five points at which personal data can be removed, with the use cases they suit: masked copy, mask at query time, subset or synthetic data, proxy in front of the language model, model run in-house.

Suggested post

Does your development team work with a copy of the production database, or does an AI agent query your customer data directly?

For both cases there are tools that hide or replace personal data. The tools work at five points: on a masked copy, on every query, with synthetic data, in a proxy in front of the language model or with a model run in-house. Microsoft and Oracle themselves write that their query-time masking does not protect against people who write their own queries.

For text, we measured detection. In a project comparison on 484 synthetic Swiss texts, the widely used tool Presidio missed 804 of 2,934 items of personal data in its default configuration, dates of birth not counted. With the GLiNER recognition model and rules for Swiss formats, it missed 72. Our conclusion: how well a tool is configured for Swiss formats decides how well the data is protected. Whether the configuration works has to be measured on your own examples.

The article describes the five points with tools and limits and shows a proxy in a real run. A matrix maps the points to four use cases. The PDF contains the tools with their licences and a worksheet for the architecture decision. Link in the comments.

#DataProtection #TestData #AI #Anonymisation #Switzerland