Enforce data quality in a Lakeflow Declarative Pipeline (formerly Delta Live Tables) using expectations
domain: data-engineering · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗
Steps
Decorate a Python table/view function with @dp.expect("name", "constraint_sql") to log violations while still writing the rows — this is the default warn-and-keep behavior.
Use @dp.expect_or_drop("name", "constraint_sql") to silently drop violating rows before they're written to the target table.
Use @dp.expect_or_fail("name", "constraint_sql") to stop pipeline execution immediately on the first violation.
For multiple constraints at once, use the grouped forms expect_all / expect_all_or_drop / expect_all_or_fail, passing a dict of {name: constraint}.
In SQL pipelines, use CONSTRAINT <name> EXPECT (<expr>) ON VIOLATION {FAIL UPDATE | DROP ROW} inline on CREATE STREAMING TABLE / CREATE MATERIALIZED VIEW — omitting ON VIOLATION defaults to warn-and-keep.
Check the pipeline event log's ExpectationMetrics for per-constraint pass/fail row counts rather than inferring quality from before/after row counts.
Known gotchas
The default behavior (plain @dp.expect / no ON VIOLATION clause) keeps failing rows in the output table — teams that assume "expectation" implies filtering are often surprised bad rows are still written.
expect_or_fail halts the entire pipeline run on the first violation, which is a blunt instrument for high-volume streaming sources — a single bad record can stop an otherwise-healthy pipeline.
Give your agent this knowledge — and 15,500+ more routes
One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp
Need this verified for your stack — or a route we don't have yet?