Using pipeline expectations to manage data quality
Lakeflow Spark Declarative Pipelines let you enforce data quality rules directly on streaming tables and materialized views using expectations, which are boolean constraints evaluated as each batch of records is processed. Expectations control what happens to rows that fail validation—keep, drop, or halt the pipeline—and their pass/fail metrics are captured automatically for monitoring.
1 · Learn the must-know
- In Python, expectations are declared with the @dlt.expect(), @
dlt.expect_or_drop(), and @dlt.expect_or_fail() decorators, each taking a constraint name and a SQL boolean expression. - In SQL, expectations use the CONSTRAINT name EXPECT (condition) syntax, optionally followed by ON VIOLATION DROP ROW or ON VIOLATION FAIL UPDATE to change the default warn behaviour.
- The default violation action is 'warn': failing rows are still written to the target table but counted as failures in pipeline metrics, so a passive expectation alone will not stop bad data from landing.
- Multiple related constraints can be grouped and applied together using
expect_all,expect_all_or_drop, andexpect_all_or_fail, which take a Python dictionary mapping constraint names to expressions. - Expectation pass/fail counts per constraint are recorded in the pipeline's event log and visible in the pipeline UI graph, enabling data quality monitoring over time without extra instrumentation code.
- Expectations only apply to records processed by the decorated streaming table or materialized view definition within the pipeline; they do not retroactively validate data already in the table or apply to plain batch/notebook code outside the pipeline.
2 · Check your understanding
A data engineer is building a Lakeflow Spark Declarative Pipeline that ingests raw sensor readings into a streaming table. Any row where sensor_id is null must be removed from the table entirely, but the pipeline update should continue processing the remaining rows without failing. Which expectation should the engineer apply to the streaming table definition?
What you have tried across DP-750's objectives, not a readiness score.
Set up and configure an Azure Databricks environment15-20% of the exam0 of 13 tried
Secure and govern Unity Catalog objects15-20% of the exam0 of 12 tried
Prepare and process data30-35% of the exam0 of 28 tried
Deploy and maintain data pipelines and workloads30-35% of the exam0 of 24 tried
3 · Keep going
Ready for more? Take a weighted mock or try free practice questions.