Constraints API Reference

qualink.constraints — All built-in constraint classes and the Assertion predicate.

from qualink.constraints import Assertion, CompletenessConstraint, UniquenessConstraint

All constraints extend Constraint (ABC) and implement:

qualink.constraints.approx_count_distinct

class ApproxCountDistinctConstraint(Constraint)

Validates that the approximate distinct count of *column* satisfies *assertion*.

ApproxCountDistinctConstraint(column: str, assertion: Assertion, hint: str = "")
Param Type Default
column str
assertion Assertion
hint str ""
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.approx_quantile

class ApproxQuantileConstraint(Constraint)

Validates that an approximate quantile of *column* satisfies *assertion*.

ApproxQuantileConstraint(column: str, quantile: float, assertion: Assertion, hint: str = "")
Param Type Default
column str
quantile float
assertion Assertion
hint str ""
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.assertion

@dataclass(frozen=True)

class Assertion

Reusable predicate that tests a numeric metric value.

Field Type Default
_op _Op required
_value float 0.0
_upper float 0.0
_fn `Callable[[float], bool] None`
_label str ""
@staticmethod greater_than(value: float) → Assertion
@staticmethod greater_than_or_equal(value: float) → Assertion
@staticmethod less_than(value: float) → Assertion
@staticmethod less_than_or_equal(value: float) → Assertion
@staticmethod equal_to(value: float) → Assertion
@staticmethod between(lower: float, upper: float) → Assertion
@staticmethod custom(fn: Callable[[float], bool], label: str = 'custom') → Assertion
evaluate(metric: float) → bool

qualink.constraints.column_count

class ColumnCountConstraint(Constraint)

Validates that the number of columns in the table satisfies *assertion*.

ColumnCountConstraint(assertion: Assertion)
Param Type Default
assertion Assertion
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.column_exists

class ColumnExistsConstraint(Constraint)

Validates that *column* exists in the table schema.

ColumnExistsConstraint(column: str, hint: str = "")
Param Type Default
column str
hint str ""
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.completeness

class CompletenessConstraint(Constraint)

Validates that the completeness fraction of *column* satisfies *assertion*.

CompletenessConstraint(column: str, assertion: Assertion)
Param Type Default
column str
assertion Assertion
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.compliance

class ComplianceConstraint(Constraint)

Validates that the fraction of rows where *predicate* is true satisfies *assertion*.

ComplianceConstraint(name_label: str, predicate: str, assertion: Assertion, hint: str = "")
Param Type Default
name_label str
predicate str
assertion Assertion
hint str ""
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.correlation

class CorrelationConstraint(Constraint)

Validates that the Pearson correlation of *column_a* and *column_b* satisfies *assertion*.

CorrelationConstraint(column_a: str, column_b: str, assertion: Assertion, hint: str = "")
Param Type Default
column_a str
column_b str
assertion Assertion
hint str ""
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.custom_sql

class CustomSqlConstraint(Constraint)

Validates that *sql_expression* holds true for all rows.

The expression is evaluated as a WHERE-clause predicate; the constraint passes when the ratio of matching rows equals 1.0.

CustomSqlConstraint(sql_expression: str, hint: str = "")
Param Type Default
sql_expression str
hint str ""
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.distinctness

class DistinctnessConstraint(Constraint)

Validates that the distinctness ratio of *columns* satisfies *assertion*.

Distinctness = COUNT(DISTINCT cols) / COUNT(*)

DistinctnessConstraint(columns: list[str], assertion: Assertion, hint: str = "")
Param Type Default
columns list[str]
assertion Assertion
hint str ""
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.format

class FormatType(Enum)

Pre-defined format categories or a free-form regex.

Member Value
FormatType.REGEX 'regex'
FormatType.EMAIL 'email'
FormatType.URL 'url'
FormatType.PHONE 'phone'
FormatType.CREDIT_CARD 'credit_card'
FormatType.SSN 'ssn'
FormatType.IPV4 'ipv4'

class FormatConstraint(Constraint)

Validates that at least *threshold* fraction of *column* values match a pattern.

FormatConstraint(column: str, format_type: FormatType, pattern: str | None = None, threshold: float = 1.0)
Param Type Default
column str
format_type FormatType
pattern `str None`
threshold float 1.0
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.max_length

class MaxLengthConstraint(Constraint)

Validates that the maximum string length of *column* satisfies *assertion*.

MaxLengthConstraint(column: str, assertion: Assertion, hint: str = "")
Param Type Default
column str
assertion Assertion
hint str ""
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.min_length

class MinLengthConstraint(Constraint)

Validates that the minimum string length of *column* satisfies *assertion*.

MinLengthConstraint(column: str, assertion: Assertion, hint: str = "")
Param Type Default
column str
assertion Assertion
hint str ""
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.pattern_match

class PatternMatchConstraint(Constraint)

Validates that the fraction of *column* values matching *pattern* satisfies *assertion*.

PatternMatchConstraint(column: str, pattern: str, assertion: Assertion, hint: str = "")
Param Type Default
column str
pattern str
assertion Assertion
hint str ""
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.referential_integrity

class ReferentialIntegrityConstraint(Constraint)

Validates referential integrity between two tables via ReferentialIntegrity.

ReferentialIntegrityConstraint(child_table: str, child_column: str, parent_table: str, parent_column: str, assertion: Assertion, hint: str = "")
Param Type Default
child_table str
child_column str
parent_table str
parent_column str
assertion Assertion
hint str ""
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.row_count_match

class RowCountMatchConstraint(Constraint)

Validates row count match between two tables via RowCountMatch.

RowCountMatchConstraint(table_a: str, table_b: str, assertion: Assertion, hint: str = "")
Param Type Default
table_a str
table_b str
assertion Assertion
hint str ""
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.schema_match

class SchemaMatchConstraint(Constraint)

Validates schema match between two tables via SchemaMatch.

SchemaMatchConstraint(table_a: str, table_b: str, assertion: Assertion, hint: str = "")
Param Type Default
table_a str
table_b str
assertion Assertion
hint str ""
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.size

class SizeConstraint(Constraint)

Validates that the row count of the table satisfies *assertion*.

SizeConstraint(assertion: Assertion)
Param Type Default
assertion Assertion
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.statistics

class StatisticType(Enum)

The aggregate function to compute before applying an assertion.

Uses DataFusion built-in aggregate functions directly: https://datafusion.apache.org/user-guide/sql/aggregate_functions.html

Member Value
StatisticType.MIN 'MIN'
StatisticType.MAX 'MAX'
StatisticType.MEAN 'AVG'
StatisticType.SUM 'SUM'
StatisticType.STDDEV 'STDDEV'
StatisticType.MEDIAN 'MEDIAN'

Properties:


class StatisticalConstraint(Constraint)

Computes a SQL aggregate on *column* and asserts against *assertion*.

StatisticalConstraint(column: str, stat_type: StatisticType, assertion: Assertion)
Param Type Default
column str
stat_type StatisticType
assertion Assertion
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.unique_value_ratio

class UniqueValueRatioConstraint(Constraint)

Validates that the unique-value ratio of *columns* satisfies *assertion*.

UniqueValueRatio = (values appearing exactly once) / COUNT(DISTINCT values)

UniqueValueRatioConstraint(columns: list[str], assertion: Assertion, hint: str = "")
Param Type Default
columns list[str]
assertion Assertion
hint str ""
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata

qualink.constraints.uniqueness

class UniquenessConstraint(Constraint)

Validates that the uniqueness ratio of *columns* satisfies *assertion*.

UniquenessConstraint(columns: list[str], assertion: Assertion | None = None, threshold: float | None = None)
Param Type Default
columns list[str]
assertion `Assertion None`
threshold `float None`
async evaluate(ctx: SessionContext, table_name: str) → ConstraintResult
name() → str
metadata() → ConstraintMetadata