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
Programming your own constraint is a last resort. Programming a constraint requires you to specify and maintain your own logic. The SDV team does not offer debugging support to SDV Community users for their programmed logic.
In many cases, it's possible to achieve your result more easily with existing constraints. Please browse the Predefined Constraints list to see if your logic is captured by the list.
If you have any questions, please reach out to us on Slack or GitHub and we'll be happy to point you in the right direction.
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.
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.
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.
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.
Can I use my constraint to generate data from scratch (DayZSynthesizer)?
If you are an SDV Enterprise user, you have access to the DayZSynthesizer which can be used to generate data from scratch.
Starting from SDV Enterprise version 0.30.0, you'll be able to add single-table constraints to DayZSynthesizer, including your own, programmable single-table constraint. To use this make sure you fill out the 2 functions that are listed as "REQUIRED FOR DayZSynthesizer" in the template. These are: is_valid and fix_data. All other functions are optional.