Skip to main content

validate_target()

Check transformed data against the target contract.

Usage

Source

validate_target(data)

This method validates one table against the pipeline’s target contract and returns the interrogated Validate object. It’s the outbound counterpart of validate_source(). Use it to check the output of a transformation that runs outside the pipeline (for example, a table produced by a SQL model or a separate task) before it’s published to the people and systems that depend on it.

The validation is built the same way as in run(), with the pipeline’s label, thresholds, and actions. If the data fails, the target contract’s on_violation= setting is applied, and a "raise" violation propagates as a ContractViolationError.

Parameters

data: IntoDataFrame
The transformed table. Any table type that Validate accepts can be used (e.g., a Polars or Pandas DataFrame, or an Ibis table).

Returns

Validate
An interrogated Validate object with the results of every target contract check.

Raises

ValueError

If the pipeline has no target contract.

ContractViolationError
If the data fails the target contract and the contract has on_violation="raise". It’s a subclass of RuntimeError, and its validation attribute holds the failing validation.

Examples

Suppose a daily revenue summary is built by a separate SQL job, and we want to check it before it goes to a dashboard. The target contract requires one row per day and non-negative revenue. It uses on_violation="log", so failures are logged rather than raised.

import pointblank as pb
import polars as pl

summary_contract = pb.Contract(
    name="daily_revenue",
    direction="target",
    steps=[
        pb.Step("rows_distinct", columns_subset="day"),
        pb.Step("col_vals_ge", columns="revenue", value=0),
    ],
    on_violation="log",
)

publish = pb.Pipeline(target=summary_contract, label="Revenue summary")

Here’s the job’s output, which has a repeated day:

summary = pl.DataFrame(
    {
        "day": ["2025-03-01", "2025-03-02", "2025-03-02"],
        "revenue": [1520.0, 1785.5, 1785.5],
    }
)

validation = publish.validate_target(summary)

validation
Contract 'daily_revenue' (target) violated: validation has failing steps.
Pointblank Validation
Revenue summary [target]
Polarsdaily_revenue
STEP COLUMNS VALUES TBL EVAL UNITS PASS FAIL W E C EXT
#4CA64C66 1
rows_distinct
rows_distinct()
day — ✓ 3 1
0.33
2
0.67
— — —
#4CA64C 2
col_vals_ge
col_vals_ge()
revenue 0 ✓ 3 3
1.00
0
0.00
— — — —

The rows_distinct step fails for both copies of "2025-03-02", and a message is written to the "pointblank.contract" logger. Because the method returns the validation, the job can decide what to do with the result:

validation.all_passed()
False

Here the job would hold the summary back until the duplicate day is resolved. To make a failure stop the job instead, set on_violation="raise" on the contract, which turns a failing validation into a ContractViolationError.