Principle:Sdv dev SDV Custom Constraint Definition
| Knowledge Sources | |
|---|---|
| Domains | Data_Quality, Extensibility |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
An extensibility pattern that allows users to define custom business rule constraints using Python code for scenarios not covered by built-in constraints.
Description
Custom constraint definition enables users to implement arbitrary business logic as constraints by subclassing ProgrammableConstraint. Users define methods for validation, transformation, reverse transformation, and metadata updates. The SDV framework wraps these custom constraints in a ProgrammableConstraintHarness that integrates them into the standard constraint pipeline.
Usage
Use this pattern when built-in constraints (Inequality, FixedCombinations, Range) do not cover the specific business rules needed. Examples include custom validation logic, cross-table constraints, or domain-specific rules.
Theoretical Basis
The pattern follows the strategy pattern, where users implement a standard interface:
- validate: Check that metadata is compatible with the constraint
- fit: Learn any necessary information from the data
- transform: Modify data to encode the constraint
- get_updated_metadata: Describe how metadata changes after transformation
- reverse_transform: Reconstruct original data format from transformed data
- is_valid: Validate that synthetic data satisfies the constraint