Synthetic Data for Non-Production Environments: Realistic Without the Liability

Your production database is guarded like a vault. Then someone clones it into a test environment that half the engineering team can read, and the vault door is left open at the back.

Almost every regulated firm I have looked at has the same blind spot. The controls on production data are serious: encryption, access logging, least-privilege, break-glass procedures, a data protection officer who has signed things. The controls on the copy of that data sitting in staging, UAT, the developer’s laptop and last quarter’s disaster-recovery snapshot are, charitably, thinner. Non-production environments are where real customer records go to live an under-supervised life, and they are the part of the estate a supervisor, an attacker or a plaintiff’s lawyer will find least defensible.

Why lower environments are the soft underbelly

The reason engineers copy production down is legitimate: they need data that behaves like the real thing. Realistic volumes, realistic distributions, realistic edge cases, foreign keys that actually join. Hand-written fixtures never exercise the awkward record — the customer with three addresses and a null middle name that breaks the batch job. So the path of least resistance is to take a dump of production, maybe run a masking script over the obvious columns, and load it into test.

Free · 4 minutes

Would you survive contact with a determined attacker — or an auditor?

Fourteen questions on access, patching, detection, and recovery — the basics that prevent most real incidents, and the ones most often assumed rather than verified. Banded finding on screen, full sheet by email.

The trouble is that a masked copy is still a copy. Under the GDPR, pseudonymised data — where names are swapped but the underlying records still relate to identifiable people — remains personal data, fully in scope, Recital 26 is explicit about that. Only genuinely anonymous data, where re-identification is not reasonably possible, sits outside the regulation. A staging table where you replaced the surname column but kept the real date of birth, postcode, transaction history and account balance is not anonymous. It is personal data in a weakly-controlled environment, and every obligation that applies to production applies to it too.

This is the same failure mode that turns a cross-border development team into a data-transfer problem nobody signed off, which I have written about in the context of HR data moving across GCC and EU jurisdictions. The data does not stop being regulated because it moved to a less important server.

Masking is not the same as synthesis

Masking transforms real records in place: shuffle a column, hash an identifier, redact a field. The one-to-one correspondence with a real person survives, which is exactly why masked data keeps leaking — a shuffled postcode column still reveals the real distribution of your customers, and correlations across the un-masked columns often let you re-identify individuals anyway.

Synthesis is a different operation. You fit a statistical model to the production data, learn its distributions and the relationships between columns and tables, and then generate entirely new records by sampling from that model. No synthetic row corresponds to a real person. The aggregate behaves like production — the join cardinalities, the value distributions, the correlation between income band and product holding — but the individuals are fictional. That is the distinction that lets you give engineers useful data while removing the liability of real records sitting where your controls are weakest.

Preserve the shape, not the people

The open-source Synthetic Data Vault (SDV) is a practical place to start, because it handles the part that naïve approaches get wrong: referential integrity across a relational schema. A single-table generator is easy; the moment you have customers, accounts and transactions with foreign keys between them, most home-grown fakers produce orphaned rows that fail the first join. SDV’s hierarchical synthesiser models the parent-child relationships and generates children whose foreign keys point at synthetic parents that actually exist.

# Fit a multi-table generator on a production schema and emit
# privacy-safe test data. Tested with sdv 1.37.
#   pip install sdv

from sdv.metadata import Metadata
from sdv.multi_table import HMASynthesizer
from sdv.evaluation.multi_table import run_diagnostic, evaluate_quality

# A dict of {table_name: DataFrame} pulled from production.
# Extract these in a controlled job -- do NOT hand them to developers.
tables = {
    "customers": customers_df,      # customer_id (PK), dob, postcode, ...
    "accounts": accounts_df,        # account_id (PK), customer_id (FK), balance
    "transactions": transactions_df # txn_id (PK), account_id (FK), amount
}

# Detect column types, primary keys and relationships from the data.
# Always review the detected metadata: fix any mis-typed column and
# declare the foreign keys explicitly rather than trusting detection.
metadata = Metadata.detect_from_dataframes(tables)
metadata.validate()

# HMASynthesizer preserves referential integrity across the schema.
synthesizer = HMASynthesizer(metadata)
synthesizer.fit(tables)

# Emit a synthetic estate the same size as production (scale=1.0).
synthetic = synthesizer.sample(scale=1.0)

# Structural check: every foreign key must resolve to a real parent,
# and the diagnostic score should be 1.0 before you ship this data.
diagnostic = run_diagnostic(tables, synthetic, metadata)

# Statistical realism: column shapes and cross-column trends vs source.
quality = evaluate_quality(tables, synthetic, metadata)

for name, frame in synthetic.items():
    frame.to_parquet(f"synthetic_{name}.parquet", index=False)

The run_diagnostic call is the one that earns its keep. It reports whether the generated data is structurally valid — no foreign key pointing at a non-existent parent, no primary key collisions, values within declared ranges. If that score is not perfect, your test environment will behave differently from production in ways that mask real bugs.

Validating realism without re-identifying anyone

There are two ways synthetic data fails, and they pull in opposite directions. Too unrealistic and it is useless — the distributions do not match, the edge cases are gone, and the test environment stops catching production defects. Too realistic and it becomes dangerous — a generative model that has memorised its training data can reproduce real records almost verbatim, at which point you have re-created the liability you were trying to remove. Synthetic is not automatically anonymous.

So the validation has to run both directions. On the realism side, evaluate_quality scores how closely column distributions and cross-column correlations track the source. On the privacy side, you check that no synthetic record is suspiciously close to a real one — SDV exposes metrics for this, and the honest position is to treat a synthetic dataset as un-cleared until it has passed a distance-to-closest-record test, not to assume synthesis conferred anonymity by definition. Document that check. When someone asks whether your test data contains personal data, the defensible answer is a report, not an assertion.

Getting this right also quietly fixes an adjacent governance problem: the sprawl of ungoverned extracts that accumulates when teams help themselves to production copies, a pattern I have described in the context of self-service BI. A single controlled synthesis job that produces the shared test dataset is easier to govern than a hundred private clones.

The decision this actually changes

Synthetic data is not free. Fitting generators, validating them and wiring the job into your data pipeline is real engineering effort, and it is worth it where the exposure is real: environments many people can read, third-party developers, offshore teams, anywhere a breach or a discovery request would reach records you cannot afford to lose. The prize is that a leak from staging exposes fictional people, and the expanding liability around privacy invasions lands on a dataset with no real subjects in it.

The question to put to your engineering leads is not whether they have masked the test data. It is whether a real customer could be identified from anything currently sitting outside production. If nobody can answer that with a report, the answer is yes.

Build and rescue work

Hands-on delivery of this kind is handled by Sixteen Pillars Studio.

Free interactive tool

Website compliance checklist

What your site has to do, based on what it actually does

Answer as much or as little as you like — the list builds as you go. Nothing is stored against your name and no email is required.

Can you trust the architecture you have?

Architecture diagrams rarely show the reality of how systems actually operate. An independent review establishes what is really there.