Program Your Own Constraint

If the predefined constraints don't meet your needs, you can program your own constraint with the logic that you need.

Compatibility: Any type of column except for primary and foreign keys

How to Program Your Own Constraint

In most cases, your business rules can be achieved by pre-processing your data before using SDV, and post-processing the data after getting the synthetic data. Programmable constraints allow you to input that pre- and post-processing logic directly into your synthesizer, so you do not have to worry about maintaining a separate script.

Learn how to program your own constraint using the tutorial below.

Download the example constraint code used in the tutorial using the link below.

Programmable Constraints Template

Below, you will find a template code for programming a single table constraint (to be used within a single table of your dataset) and a multi-table constraint (to be used within different tables of your dataset). Select the file you need and fill out the relevant code.

FAQs

Which types of columns can I use within my constraint?

You are free to use any type of column for a custom constraint except for primary and foreign keys.

Primary and foreign keys pay a special role in identifying rows and relationships. Their original values are needed for all our synthesizers to work — especially multi-table synthesizers that learn patterns between the relationships.

The constraint crashes. How should I fix the logic?

You can debug your custom constraint by creating the constraint object and trying to run the different functions — transform, reverse_transform, is_valid, etc.

my_constraint = MyExampleConstraint()

transformed_data = my_constraint.transform(original_data)
print(transformed_data)

reversed_transformed_data = my_constraint.reverse_transform(transformed_data)
print(reverse_transformed_data)

validity = my_constraint.is_valid(original_data)
print(validity)

Ensuring that there are no crashes and printing out these results may help you understand where the logic is failing.

Unfortunately, the SDV team is unable to offer individualized support for this to SDV Community users. For SDV Enterprise users, we offer help with debugging and may prioritize creating a new, predefined constraint related to your logic. To learn more, visit our page about SDV Enterprise features.

Last updated