Databricks Delta Live Tables expectations provide a practical way to validate records as data moves through a declarative pipeline. This checklist explains how to choose expectation actions, write reusable rules, inspect quality metrics, and troubleshoot rejected or failed records without treating data quality as a one-time exercise.
Overview
Delta Live Tables (DLT), now presented in some Databricks experiences under the Lakeflow Declarative Pipelines terminology, lets you attach data-quality rules directly to pipeline datasets. An expectation is a Boolean condition that describes what a valid row should look like—for example, a required identifier must not be null, an event timestamp must be parseable, or a quantity must be greater than or equal to zero.
Expectations are useful because they place validation close to the transformation that creates or consumes the data. Instead of discovering every issue later in a dashboard or machine-learning workflow, you can measure violations during ingestion and transformation. The right action depends on the consequence of bad data:
| Action | Behavior | Use when |
|---|---|---|
| Warn | Keep the row and record the expectation result. | The data is useful for analysis, but quality issues need monitoring or follow-up. |
| Drop | Exclude rows that violate the rule from the target dataset. | Invalid rows must not reach downstream consumers, and losing those rows is acceptable or they are captured separately. |
| Fail | Stop the update when the rule is violated. | The dataset cannot safely advance with invalid records, or the issue indicates a contract or upstream failure. |
Use expectations as part of a broader Databricks data quality checks strategy. They do not replace schema management, reconciliation, business-owner review, access controls, or tests for pipeline logic.
Checklist by scenario
1. Start with a rule that can be evaluated per row
Write the condition as a SQL expression that returns true for acceptable data. Keep the first version narrow and observable. For example, a customer-events dataset might require:
customer_id IS NOT NULLevent_type IS NOT NULLevent_timestamp IS NOT NULLamount >= 0
Give each rule a stable, descriptive name such as valid_customer_id or nonnegative_amount. Names appear in pipeline metrics and make incidents easier to investigate than anonymous conditions.
2. Choose warn for visibility without interruption
Use a warn-style expectation when the pipeline should continue while the team measures data quality. In Python, a representative pattern is:
@dlt.expect("valid_customer_id", "customer_id IS NOT NULL")
def customer_events():
return spark.readStream.table("raw.customer_events")The exact decorator and pipeline syntax can vary with the Databricks runtime and whether the dataset is defined with Python or SQL. Treat this example as a pattern: define the expectation beside the dataset and confirm the supported syntax for the runtime used by your pipeline.
3. Use drop when invalid rows should not enter the target
A drop action is appropriate when downstream consumers require clean rows and an invalid record has no safe interpretation. A Python example is:
@dlt.expect_or_drop("valid_event_timestamp", "event_timestamp IS NOT NULL")
def clean_events():
return dlt.read_stream("raw_events")With SQL, the equivalent pattern commonly uses a constraint with an ON VIOLATION DROP ROW clause:
CREATE OR REFRESH STREAMING TABLE clean_events (
CONSTRAINT valid_event_timestamp EXPECT (event_timestamp IS NOT NULL) ON VIOLATION DROP ROW
)
AS SELECT * FROM STREAM(raw_events);Do not assume dropped records are recoverable from the target. Preserve enough source data, audit information, or quarantine output to support investigation and replay.
4. Use fail for critical contracts
Choose a fail action when continuing would create misleading or unsafe output. Examples include a required partitioning field becoming null, a source contract changing unexpectedly, or a critical reference key failing validation. In Python, this is commonly expressed with an expectation that fails on violation:
@dlt.expect_or_fail("valid_account_id", "account_id IS NOT NULL")
def account_events():
return spark.readStream.table("raw.account_events")Failing fast is most useful when the team has an operational path to inspect the source, correct the issue, and restart or rerun the affected update. A fail rule without ownership or alerting can turn a quality control into an unattended outage.
5. Separate quarantine from the clean output
For valuable records that need correction, consider a quarantine design rather than silently dropping them. Add a readable reason or rule identifier, write invalid records to a controlled table, and keep the clean target restricted to rows that pass the required conditions. This approach is especially helpful for ingestion pipelines where upstream data cannot be corrected immediately.
What to double-check
- Expression semantics: Check null behavior, data types, timestamp parsing, case sensitivity, and implicit casts. A condition that looks correct may behave differently when a column contains nulls or unexpected strings.
- Rule scope: Confirm that the expectation is attached to the dataset and transformation where the rule is meaningful. A rule applied too early may reject records that a later normalization step could repair; applied too late, it may allow bad values to spread.
- Metrics location: After a pipeline update, inspect the pipeline details and data-quality or expectation metrics available in the workspace. Event logs and system tables may also be available depending on the pipeline configuration and platform setup. Verify the current UI path and retention behavior in your environment.
- Counts and denominators: Compare input rows, valid rows, dropped rows, and failed updates. A percentage can look stable while the absolute number of violations grows with volume.
- Streaming behavior: Test the rule with new data, retries, late records, and backfills. A rule that works on a static sample may expose different operational behavior in a streaming pipeline.
- Permissions and observability: Confirm that the operators who respond to failures can read the relevant source, target, event-log, and quarantine data. Quality metrics are less useful if the incident responder cannot inspect the offending records.
- Deployment parity: Run the same expectation definitions through development, staging, and production using the intended configuration. Asset Bundles or another deployment workflow can help prevent environment-specific edits from becoming hidden production behavior.
Common mistakes
- Using fail for every rule: This creates brittle pipelines and makes it difficult to distinguish a tolerable quality trend from a genuine contract breach.
- Dropping without a recovery path: If invalid rows are discarded without a quarantine or source replay strategy, the team may lose the ability to explain missing records.
- Combining unrelated conditions: A single rule such as
id IS NOT NULL AND amount >= 0 AND status IN (...)makes failures harder to attribute. Prefer separate named expectations when each condition has a different owner or remediation. - Testing only happy-path data: Include nulls, malformed values, duplicates, boundary values, late events, and schema changes in test data.
- Ignoring rule drift: A business definition can change even when the pipeline code does not. Review whether thresholds, allowed values, and required fields still match the source contract.
- Confusing quality checks with uniqueness: A row-level expectation can validate that a key is present, but uniqueness and cross-row reconciliation often require separate aggregation or monitoring logic.
When to revisit
Review your Databricks pipeline validation checklist whenever an upstream source changes its schema, a new consumer depends on the output, or a data-quality incident reveals a missing rule. Revisit it before seasonal planning cycles when transaction volume, event types, or operating thresholds may change. Also review expectations after upgrading the Databricks runtime, changing from batch to streaming, adopting new pipeline terminology or interfaces, or moving definitions into a CI/CD deployment process.
For a practical review, begin with the last successful pipeline update and ask:
- Which expectations ran, and what were their violation counts?
- Did any rule silently remove records that a business user expected to see?
- Can an operator identify the source, rule, and affected records from the available metrics?
- Does each fail action have a documented owner and recovery procedure?
- Have the current syntax, supported actions, and workspace locations been checked against the Databricks release documentation?
Record the answers with the pipeline code or runbook. When you add the next rule, first classify it as warn, drop, or fail, then test it against representative bad data before deploying. This small discipline keeps expectations understandable, measurable, and aligned with the reliability needs of the AI and data applications built on top of the pipeline.