Synthetic Data Vault
GitHubSlackDataCebo
  • Welcome to the SDV!
  • Tutorials
  • Explore SDV
    • SDV Community
    • SDV Enterprise
      • ⭐Compare Features
    • SDV Bundles
      • ❖ AI Connectors
      • ❖ CAG
      • ❖ Differential Privacy
      • ❖ XSynthesizers
  • Single Table Data
    • Data Preparation
      • Loading Data
      • Creating Metadata
    • Modeling
      • Synthesizers
        • GaussianCopulaSynthesizer
        • CTGANSynthesizer
        • TVAESynthesizer
        • ❖ XGCSynthesizer
        • ❖ BootstrapSynthesizer
        • ❖ SegmentSynthesizer
        • * DayZSynthesizer
        • ❖ DPGCSynthesizer
        • ❖ DPGCFlexSynthesizer
        • CopulaGANSynthesizer
      • Customizations
        • Constraints
        • Preprocessing
    • Sampling
      • Sample Realistic Data
      • Conditional Sampling
    • Evaluation
      • Diagnostic
      • Data Quality
      • Visualization
      • Privacy
        • Empirical Differential Privacy
        • SDMetrics: Privacy Metrics
  • Multi Table Data
    • Data Preparation
      • Loading Data
        • Demo Data
        • CSV
        • Excel
        • ❖ AlloyDB
        • ❖ BigQuery
        • ❖ MSSQL
        • ❖ Oracle
        • ❖ Spanner
      • Cleaning Your Data
      • Creating Metadata
    • Modeling
      • Synthesizers
        • * DayZSynthesizer
        • * IndependentSynthesizer
        • HMASynthesizer
        • * HSASynthesizer
      • Customizations
        • Constraints
        • Preprocessing
      • * Performance Estimates
    • Sampling
    • Evaluation
      • Diagnostic
      • Data Quality
      • Visualization
  • Sequential Data
    • Data Preparation
      • Loading Data
      • Cleaning Your Data
      • Creating Metadata
    • Modeling
      • PARSynthesizer
      • Customizations
    • Sampling
      • Sample Realistic Data
      • Conditional Sampling
    • Evaluation
  • Concepts
    • Metadata
      • Sdtypes
      • Metadata API
      • Metadata JSON
    • Constraint-Augmented Generation (CAG)
      • Predefined Constraints
        • FixedCombinations
        • FixedIncrements
        • Inequality
        • OneHotEncoding
        • Range
        • ❖ CarryOverColumns
        • * ChainedInequality
        • ❖ CompositeKey
        • ❖ FixedNullCombinations
        • ❖ ForeignToForeignKey
        • ❖ ForeignToPrimaryKeySubset
        • ❖ MixedScales
        • ❖ PrimaryToPrimaryKey
        • ❖ PrimaryToPrimaryKeySubset
        • ❖ ReferenceTable
        • ❖ SelfReferentialHierarchy
        • ❖ UniqueBridgeTable
      • Program Your Own Constraint
      • Constraints API
  • Support
    • Troubleshooting
      • Help with Installation
      • Help with SDV
    • Versioning & Backwards Compatibility Policy
Powered by GitBook

Copyright (c) 2023, DataCebo, Inc.

On this page
  • How to Program Your Own Constraint
  • Programmable Constraints Template
  • FAQs
  1. Concepts
  2. Constraint-Augmented Generation (CAG)

Program Your Own Constraint

Previous❖ UniqueBridgeTableNextConstraints API

Last updated 21 hours ago

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 to see if your logic is captured by the list.

If you have any questions, please reach out to us on or 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.

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
Predefined Constraints list
Slack
GitHub
Google Colab
Logo
3KB
example_constraint.py
3KB
programmable_single_table_constraint_template.py
4KB
programmable_multi_table_constraint_template.py