FREE STUDY NOTES · DP-750

Lakeflow pipeline expectations: warn, drop or fail

How expectations validate records in Lakeflow Spark Declarative Pipelines and what each violation action does.

From Ultra Transcenders DP-750 by Tony Rough (coming November 2026)

Expectations are optional clauses on streaming tables, materialized views and temporary views that test every record against a SQL Boolean constraint and record the results. They need the ADVANCED product edition.

Each expectation has three parts: a name (unique within the dataset, used in metrics), a constraint (valid SQL that returns true or false per record) and an action. Figure 8.1 compares the three actions.

Incoming records are each tested against an expectation, which has a name, a constraint and an action. Warn, the default, writes invalid records to the target and records pass and fail counts. Drop discards them before the write and records the dropped count. Fail makes the update fail and roll back, so no metrics are recorded.
Figure 8.1: What each expectation action does to records that fail the constraint
Action SQL Python Effect on invalid records Metrics
warn (default) CONSTRAINT n EXPECT (cond) @dp.expect("n", "cond") Written to the target Pass and fail counts recorded
drop ... EXPECT (cond) ON VIOLATION DROP ROW @dp.expect_or_drop("n", "cond") Dropped before the write Dropped count recorded
fail ... EXPECT (cond) ON VIOLATION FAIL UPDATE @dp.expect_or_fail("n", "cond") The flow’s update fails and the table update rolls back Not recorded, because the update fails
CREATE OR REFRESH STREAMING TABLE orders_silver(
  CONSTRAINT valid_id     EXPECT (order_id IS NOT NULL) ON VIOLATION DROP ROW,
  CONSTRAINT valid_amount EXPECT (amount >= 0) ON VIOLATION FAIL UPDATE,
  CONSTRAINT recent       EXPECT (order_date >= '2020-01-01')
) AS SELECT * FROM STREAM(orders_bronze);

Grouped expectations in Python

Only Python can group expectations with a collective action. expect_all, expect_all_or_drop and expect_all_or_fail each take one dictionary of name-to-constraint pairs; the single forms take a description and a constraint as two strings. Each expectation in the dictionary still reports its own metrics, and the same dictionary can be reused across datasets or loaded from a rules table.

from pyspark import pipelines as dp

valid_orders = {"valid_id": "order_id IS NOT NULL", "valid_qty": "quantity > 0"}

@dp.table
@dp.expect_all_or_drop(valid_orders)
def orders_clean():
    return spark.readStream.table("orders_bronze")

What fail does in each pipeline mode

In a triggered pipeline, a failed expectation fails and rolls back only that flow; other parallel flows keep updating. In a continuous pipeline, the failure stops the flow and all dependent flows, and the pipeline reports why. Either way, someone must fix the code or data before reprocessing; the error message (EXPECTATION_VIOLATION) shows the violated expectation and, for many queries, the offending input record.

Limits to know

Common trap: Passing several description and constraint strings to @dp.expect_all_or_drop - the expect_all decorators take a single dict of {name: constraint}; the two-argument form belongs to expect, expect_or_drop and expect_or_fail.

Common trap: Assuming a failed expectation in one flow always leaves the rest of the pipeline running - that holds for triggered pipelines only; in a continuous pipeline it also stops every dependent flow.

Get the whole book

This note is one section of Ultra Transcenders DP-750: Implementing Data Engineering Solutions Using Azure Databricks, an independent study guide that explains every topic the exam covers by technology, with comparison tables, diagrams and the common traps, plus a glossary linked to Microsoft Learn.

Amazon.co.ukKindle: coming soonPaperback: coming soon
Amazon.comKindle: coming soonPaperback: coming soon

Due on Amazon in November 2026, in Kindle and paperback editions.

About the book · DP-750 terms in the glossary · All DP-750 study notes

More DP-750 study notes