Skip to the page
Tecyfy

Databricks interview question · medium

You're using expectations in a Lakeflow declarative pipeline (formerly Delta Live Tables) to enforce data quality. An expectation fails. What is the default behavior of the pipeline, and how can you configure it to behave differently?

The short answerBy default nothing stops: an expectation without an action only warns, so failing rows are still written to the target table and counted in the pipeline's data quality metrics.

The full answer

By default nothing stops: an expectation without an action only warns, so failing rows are still written to the target table and counted in the pipeline's data quality metrics. To change that, give the expectation an action: drop the failing rows, or fail the update.

An expectation is a named condition on a dataset. Each has one of three actions:

ActionSQLPythonWhat happens to a failing row
Warn (default)EXPECT (cond)@dp.expectWritten to the target; counted
DropEXPECT (cond) ON VIOLATION DROP ROW@dp.expect_or_dropRemoved before it is written; counted
FailEXPECT (cond) ON VIOLATION FAIL UPDATE@dp.expect_or_failThe update stops; nothing is written

Python

from pyspark import pipelines as dp

@dp.table
@dp.expect("valid_age", "age BETWEEN 0 AND 120")
@dp.expect_or_drop("has_id", "customer_id IS NOT NULL")
@dp.expect_or_fail("positive_amount", "amount > 0")
def customers():
    return spark.readStream.table("raw.customers")

@dp.expect_all, @dp.expect_all_or_drop and @dp.expect_all_or_fail take a dictionary of several conditions at once. (Older code uses import dlt and @dlt.expect..., which still works.)

SQL

CREATE OR REFRESH STREAMING TABLE customers (
  CONSTRAINT has_id EXPECT (customer_id IS NOT NULL) ON VIOLATION DROP ROW
) AS SELECT * FROM STREAM(raw.customers);

What "fail" does. The table update is rolled back atomically, so no partial data is written, and the update stops with a message naming the expectation. In a triggered pipeline, other flows running in parallel are not failed; in a continuous pipeline the failed flow and the flows that depend on it stop. You fix the data or the rule and run the pipeline again. Fail records no metrics, because the update did not complete.

Seeing the results. Warn and drop counts appear in the dataset's Data quality tab in the pipeline UI and in the pipeline's event log, which you can query to track quality over time.

Choosing: warn for rules you are still learning about, drop for rows that are simply unusable, and fail only when a breach means the whole load is wrong. A common pattern is to quarantine instead of dropping: write rows that fail the rules to a separate table so they can be inspected. To do that, define the rules once in a dictionary, apply them with @dp.expect_all_or_drop on the clean table, and build a second table that keeps only the rows where the same conditions are false. Nothing is then lost silently: the clean table stays clean, and the quarantine table shows exactly which records broke which rule, so the source team can fix them and the rows can be reprocessed.

Last updated 16 October 2026

Sources

Where each fact comes from

  1. 1Manage data quality with pipeline expectations

Asked next