This documentation is available to agents as Markdown at https://docs.synthesized.io/tdk/latest/user_guide/020_guides/masking_data/masking.md. For the complete documentation index, see llms.txt.

Mask a Database

Replace the personal data in a copy of a database with realistic values. Data types, formats and the links between tables stay intact, so applications and tests keep working.

Before you start

  • An input data source for the database to mask, and an output data source set to Read & write, both in the same project. The demo from the Quick Start has both.

  • An output database you can overwrite. A run can empty its tables or recreate its schema. See Database permissions.

Mask the database

  • Web UI

  • CLI

  1. Open the project and click Create new workflow.

  2. In the Define step, name the workflow and choose a workflow type:

    Workflow type What it does

    Mask sensitive data

    Detects the sensitive columns and masks them

    Mask all data

    Masks every column

    Click Next.

  3. In the Connect step, choose the Input data source and the Output data source, then click Create workflow.

  4. Review what will be masked. The Configuration tab shows the whole configuration as YAML; the Database view tab shows the transformer chosen for each column. To change one, see Choose how each column is masked.

  5. Click Run. When the run is done, its status in Run history is COMPLETED.

  1. Save the configuration as config.yaml. In MASKING mode, the platform picks a masking transformer for every column from its type and role:

    default_config:
      mode: MASKING
    
    table_truncation_mode: TRUNCATE
    schema_creation_mode: CREATE_IF_NOT_EXISTS

    TRUNCATE empties the output tables before writing, and CREATE_IF_NOT_EXISTS copies the schema to the output if it isn’t there yet. See Choose a schema creation mode.

  2. Run it with the TDK CLI:

    tdk \
        --input-url <input JDBC URL> --input-username <user> --input-password <password> \
        --output-url <output JDBC URL> --output-username <user> --output-password <password> \
        --config-file config.yaml

    To see which transformations will be applied without running anything, use dry-run. It prints the effective configuration. See the CLI reference.

Try it on sample databases

The examples below use the Sakila sample schema. To run them on your machine, start the sample databases from the tdk-tutorial-databases repository:

git clone https://github.com/synthesized-io/tdk-tutorial-databases
cd tdk-tutorial-databases/
docker compose run databases

The input database is then at jdbc:postgresql://localhost:6000/postgres and the output at jdbc:postgresql://localhost:6001/postgres, both with user and password postgres.

Check the result

Compare a few rows in the input and the output. In the sample schema, customer links to address through address_id:

  • Before

  • After masking

customer

customer_id store_id first_name last_name email address_id

1

1

MARY

SMITH

MARY.SMITH@sakilacustomer.org

5

2

1

PATRICIA

JOHNSON

PATRICIA.JOHNSON@sakilacustomer.org

6

3

1

LINDA

WILLIAMS

LINDA.WILLIAMS@sakilacustomer.org

7

address

address_id address district city_id postal_code phone

5

1913 Hanoi Way

Nagasaki

463

35200

28303384290

6

1121 Loja Avenue

California

449

17886

838635286649

7

692 Joliet Street

Attika

38

83579

448477190408

customer

customer_id store_id first_name last_name email address_id

2013831174

2013831174

WQEJ

YKDPW

ZBHY.OYHYA@fgnwkhodyxxgkk.lxc

15183026

1843733460

2013831174

XJMVRIKE

DEJECWQ

QRODGFBA.BYBTDSM@ywjxsmntkpvozf.xyu

695573888

589262816

2013831174

GBBQA

FJENIEYU

QOIZU.FFMEWGOU@zmrogyqpgdsapk.itw

716836103

address

address_id address district city_id postal_code phone

15183026

5314 Laypz Acm

Plxwuyle

1693424342

79518

18846059374

695573888

0383 Wmwq Cckxcg

Iyzmcmbynx

2076144198

76495

339497461347

716836103

306 Kqeywo Hqeekv

Qfogmd

1505222168

13429

277221410948

What you see Why

Strings are replaced, formats kept

Names, emails and phone numbers keep their shape. This is format-preserving hashing.

Keys still match

address_id 5 became 15183026 in both tables, so joins still work. Keys are masked with unique hashing.

Choose how each column is masked

The default masking is safe but not realistic. To get realistic names, addresses and phone numbers, or to leave a table unmasked, set transformers for those tables.

  • Web UI

  • CLI

In the Database view tab, pick the table, then click the column to see or change its transformer. To edit several tables at once, edit the YAML in the Configuration tab and click Save.

Add a tables section to config.yaml. Settings in tables override default_config for those tables.

For example, to keep actor unchanged and generate realistic values for customer and address:

default_config:
  mode: MASKING

tables:
  - table_name_with_schema: "public.actor"
    mode: KEEP
  - table_name_with_schema: "public.customer"
    transformations:
      - columns: ["first_name", "last_name", "email"]
        params:
          type: "person_generator"
          column_templates: ["${first_name}", "${last_name}", "${email}"]
  - table_name_with_schema: "public.address"
    transformations:
      - columns: ["address", "district", "postal_code"]
        params:
          type: "address_generator"
          column_templates: ["${house_number} ${street_name}", "${city}", "${zip_code}"]
      - columns: ["phone"]
        params:
          type: "formatted_string_generator"
          pattern: "\\+44[0-9]{4} [0-9]{6}"

table_truncation_mode: TRUNCATE
schema_creation_mode: CREATE_IF_NOT_EXISTS

The result:

customer with realistic values

customer_id store_id first_name last_name email address_id

2013831174

2013831174

Casie

Dooley

dooley2605@effertzquitzonandreinger.com

15183026

1843733460

2013831174

Rickie

Trantow

trantow7645@kertzmannhaley.com

695573888

589262816

2013831174

Lynn

Kub

kub7789@keeblerinc.com

716836103

The transformer reference lists every transformer and the modes it works in. Most generators work in both MASKING and GENERATION modes; a few, such as noising, are for masking only.

If it fails

Problem What to do

The run stops because a column has no matching transformation

The default safety mode, STRICT, stops instead of copying such a column unmasked. Set a transformer for the column, or mode: KEEP for its table if it holds no personal data. Avoid safety_mode: RELAXED on production data: it copies those columns with their original values. See Safety Mode.

The run fails with duplicate key errors in the output

The output still holds rows from an earlier run: the default, DO_NOT_TRUNCATE, leaves them in place. Set table_truncation_mode: TRUNCATE to empty the tables first.

Tables or schemas are missing in the output

Check schema creation, and that the output user has the write grants.

Other errors

Read the run’s log in Run history, and see common issues.

Next

Watch it