AI-generated test data: synthetic data instead of a production copy
Updated:
Test automation needs users, orders, addresses, documents and unusual combinations of states. The quickest shortcut is often a copy of the production database. That copy also brings personal data, access risks, stale records and data that was not designed for a particular test objective.
Synthetic data is created artificially from rules or learned patterns. AI can help design and generate it, but the label “synthetic” does not automatically mean anonymous, safe or useful. You need a description of fields and rules, called a data contract, controlled generation and checks of privacy and test value.
Why copying and renaming production is not enough
A production copy feels realistic because it contains genuine relationships and distributions. It also expands the number of locations where information must be protected. A test environment may have weaker access controls, longer retention, verbose logs or integrations that unexpectedly send a message to a real customer.
Replacing a name with Test User does not solve the problem. An email address, phone number, order identifier, free text or combination of age, town and date may still allow a record to be linked to a person. Pseudonymised information remains personal data where additional information can reconnect it to an individual.
Article 5 of the GDPR includes purpose limitation and data minimisation principles. For testing, this raises the question of whether you need production personal data or a record with the right structure and properties. Discuss the specific legal basis, exceptions and safeguards with the person responsible for data protection. This article does not replace an individual legal assessment.
The broader lifecycle, masking and access-control questions are covered in test data and GDPR. Synthetic generation is one option within that strategy, not a replacement for it.
Synthetic, masked and anonymised are not the same
Three different approaches are often mixed together:
- Masking or pseudonymisation changes identifiers in existing records. It preserves many real relationships, but linking data back to a person may remain possible.
- Anonymisation aims to reduce identifiability so that information is no longer personal data. Assessment depends on the method, auxiliary information available and realistic re-identification risk.
- Synthetic generation creates new records. It can be purely rule-based, or a model can imitate statistical properties of source data.
A generative model trained on sensitive records may reproduce some of that information. EDPB Opinion 28/2024 requires a case-by-case assessment of a model’s anonymity, including the possibility of extracting personal data or obtaining them through queries. It does not say that every synthetic file is anonymous. If the legal status of anonymisation matters, you need a documented method and expert risk assessment.
When AI adds value to test data
For many tests, simple rule-based generation of email addresses, dates and identifiers is enough. Reproducibility still needs to be configured. For example, Faker’s guidance on reproducible results distinguishes the seed, the generator’s starting value, library version and reference time for relative dates. AI is useful for richer content or proposing meaningful combinations.
Suitable examples include:
- complaint text with different lengths, tones and missing details.
- invented names and addresses following several countries’ formats, which may nevertheless happen to match real details.
- documents with varied layouts for text recognition (OCR) or classification.
- catalogue descriptions, search phrases and spelling mistakes.
- proposed boundary combinations of order, payment and delivery states.
- additional rare classes for model testing, provided bias is also assessed.
AI is not required for every database row. Keep stable identifiers, relationships between records, amounts and business rules in a controlled generator. A model can prepare content fields or propose cases. Code then checks their agreement with the profile.
Start with the test objective, not the model
“How many synthetic customers should we create?” is too early a question. First name the behaviour to verify. Checkout might need an ordinary order, the last item in stock, a rejected payment, a discount combined with free shipping, and resumption after an interruption.
For each data profile, define:
- Schema: required fields, types, formats and allowed values.
- Relationships: the customer owns the order, items with discounts and fees agree with the total, and payment status permits the order state.
- Invariants: rules for valid records, such as a unique identifier or non-negative quantity. For a negative profile, mark the intended violation.
- Boundaries: minimum and maximum lengths, Unicode, leap day, an empty optional value or a very large basket.
- Protective constraints: approved test contacts, no production IDs or secrets. Do not assume an invented phone number cannot receive a message.
- Expected outcome: which journey the data activates and how the test will judge it.
This data contract defines what the generator should create and what the test should reject. Without it, a model may produce convincing rows that activate a different scenario from the one you intended.
The illustrative example uses customer customer-001 and product product-001, priced at 1250 euro cents per item. The price includes tax, delivery is free and no discount applies. Quantity must be a positive integer and the note is optional. These are the example’s conditions, rather than universal order rules.
| Profile | What changes | Expected outcome |
|---|---|---|
order-valid |
Quantity 2, all other required data valid |
The saved order belongs to the customer and totals 2500 euro cents |
order-empty-note |
The same valid input, note "" |
The order is created and the note remains empty |
order-invalid-quantity |
Quantity -1, all other preconditions valid |
Invalid quantity is rejected and no new order is created |
Valid records prepare the environment. A deliberately invalid payload, the request body, belongs in a rejection test through the interface under test. Do not insert it into the database as a valid order. Each profile needs its own separate records and cleanup after the run. The IDs shown are examples. At runtime you can separate them with a prefix or reset a dedicated test environment.
A controlled generation process
A practical flow can use the following stages.
1. Minimise source context
Do not send a sample production record to an external model merely to explain a format. Use an empty schema, artificial examples, lists of allowed values (enums) and a written description of the rules. Even when the organisation runs a model in its own controlled environment, purpose, access, retention and logging still need to be defined.
Sensitive data can enter not only a prompt but also attachments, a vector database, telemetry or diagnostic logs. A service assessment therefore needs the entire data flow, not only a statement that customer data is not used for training. The article on AI testing and data privacy covers these questions in more detail.
2. Generate named profiles
Instead of one request for ten thousand “realistic” rows, create named profiles: ordinary user, new account with no history, customer with several addresses, rejected payment and boundary-length text. A profile can be linked to a test and its frequency controlled.
AI can propose text values or combinations. A controlled layer adds keys, timestamps, totals and relationships according to the profile. Retain the output’s provenance, prompt, parameters and available model version. A seed helps with some generators, but together with the model version it does not guarantee an identical response from a language model. For example, Google’s parameter documentation explicitly does not guarantee deterministic output even with a fixed seed. Save the actual approved data for regression tests.
3. Validate before use
First check a generated file against its purpose. For valid profiles, verify:
- schema, types, required values and uniqueness.
- referential integrity and business invariants.
- allowed ranges and the representation of profiles.
- absence of forbidden domains, identifiers and secret patterns.
- similarity to source records if a model learned from real data.
- the expected outcome against a small reference set.
For a negative profile, verify the exact intended deviation and the validity of other preconditions. The validator must not change -1 to 1 or discard the invalid quantity that the application is meant to receive. The test then checks the agreed rejection and the resulting state. If the input also happens to contain a nonexistent customer, rejection may not demonstrate that quantity was checked.
The NIST Synthetic Data Report Tool evaluates utility and privacy separately. Version 1.4 compares data with specific NIST samples. Separating these questions is useful here too, but this is neither legal certification nor ready-made validation of your test profiles.
4. Publish a version, not a random result
An approved dataset should have a version, owner, creation date, purpose and known limitations. Save the exact file and its checksum so you can identify the content used. A test should not call a model without controls and change its own input on every run. Dynamic generation can support fuzzing, which explores further combinations. Save any case that reveals a defect so it can be repeated exactly.
A good combination is a stable baseline plus a controlled batch of new data. When a new case reveals a defect, its smallest reproducible form becomes part of the regression set.
5. Control side effects independently of the data
An invented name or address may happen to match a real one. For email examples, you can use an address such as customer-001@example.test from the namespace reserved in RFC 2606, if the application accepts it for the test in question. This still does not replace controls on sending messages.
Route notifications to a test capture service or an approved mode that prevents real delivery. Check forwarding, SMS, webhooks and payments as well. For example, Mailpit with relay configured can send a captured email onwards. Before the pilot, use a controlled check to confirm that the message stays within the test transport and cannot reach an external recipient. A list of supposedly fake contacts must not replace this protection.
How to verify utility
“It looks realistic” is not a test criterion. Measure utility against the objective:
- coverage of enums, states and pairs of dependent values.
- the number of boundary and negative cases.
- distributions of text lengths, amounts and line-item counts.
- ability to activate the expected application branches.
- agreement with an independent control calculation.
- successful data loading without manual repairs.
For analytics or machine learning (ML) tests, statistical distributions and model performance may need comparison across real and synthetic validation data. Similarity is not an unlimited goal: an overly faithful copy of an exceptional record can increase disclosure risk.
End-to-end tests often need only a smaller, deliberately designed set. The guide to test data for E2E tests covers state creation, cleanup and scenario isolation.
Limitations and common mistakes
Synthetic data does not remove every need to check real behaviour. It may omit a rare combination, preserve bias from a source or create a world that is too clean compared with the messy inputs integrations receive. A production decision may still require a controlled test with minimised real data under an appropriate legal and security regime.
Another mistake is treating a public chatbot as an improvised anonymisation service. A model should not be the final authority deciding whether text contains personal data. Technical rules, control samples and expert assessment are necessary where the risk warrants them.
Generation also has costs: model operation, validation, versioning and rule maintenance. If a simple function can reliably create ten rows, AI only adds complexity.
What the team gains
Controlled synthetic data can reduce the distribution of production copies and make particular states easier to prepare. A saved, approved dataset lets you repeat the exact input. The team knows why a record exists, which scenario it checks and which intended defect a negative profile contains.
Next step
Choose one scenario that currently requires a production export. Define its minimum schema, relationships, valid and negative profiles, and protective constraints. Create a small set without sending a real record to the model, check it against the profiles and verify the outcome in the application. After approval, save it and decide whether AI saved useful work in design and preparation compared with a rule-based generator.