Skip to content

modosaic.core.validation_constraint

modosaic.core.validation_constraint

ValidationConstraint dataclass

ValidationConstraint(minimum, score_fn=None, score_name='score')

Quality gate applied to a validator value.

Attributes:

Name Type Description
minimum float

Inclusive minimum score needed for a pass.

score_fn Callable[[U], float] | None

Optional converter from a structured validator value to a numeric score.

score_name str

Human-readable score name stored in validation output.

evaluate

evaluate(value)

Evaluate a validator value against the configured minimum.

Parameters:

Name Type Description Default
value U

Raw validator output.

required

Returns:

Type Description
tuple[float, bool]

A tuple containing the numeric score and whether the score passed.

Raises:

Type Description
TypeError

If no score_fn is provided and value is not numeric.

Source code in modosaic/core/validation_constraint.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def evaluate(self, value: U) -> tuple[float, bool]:
    """Evaluate a validator value against the configured minimum.

    Args:
        value: Raw validator output.

    Returns:
        A tuple containing the numeric score and whether the score passed.

    Raises:
        TypeError: If no `score_fn` is provided and `value` is not numeric.
    """
    raw_score = self.score_fn(value) if self.score_fn else value

    try:
        score = float(raw_score)
        minimum = float(self.minimum)
    except (TypeError, ValueError) as exc:
        raise TypeError(
            "ValidationConstraint without score_fn requires a numeric validator value."
        ) from exc

    passed = math.isfinite(score) and math.isfinite(minimum) and score >= minimum
    return score, passed