The full answer
When a DLT expectation fails, the default behavior depends on the expectation's constraint and the pipeline's quality control settings.
Expectation Constraints:
-
constraint(Default):
If an expectation with aconstraintfails, the entire pipeline fails. No further processing occurs for that update. This is the strictest level of enforcement, ensuring that only data meeting the expectations enters the target tables. -
expect:
If an expectation withexpectfails, the pipeline continues to run, but the records that violate the expectation are recorded in a separate table (the expectation results table). This allows you to monitor data quality issues without halting the pipeline.
Pipeline Quality Control Settings:
The quality setting within the DLT pipeline configuration controls how expectation failures are handled. There are three primary modes:
-
fail_on_drop(Default forconstraint):
When an expectation with aconstraintfails, the pipeline fails. -
drop_invalid_records(Forexpect):
When an expectation withexpectfails, the invalid records are dropped, but the pipeline continues. These dropped records are recorded in the expectation results table. -
warn(Forexpect):
When an expectation withexpectfails, a warning is logged, and the pipeline continues processing all records, including the ones that failed the expectation. This is useful for monitoring data quality without impacting pipeline execution.
How to Configure Different Behavior:
You configure the behavior of expectations using the expect or constraint keyword and the pipeline's quality control settings.
Examples:
-
Fail the pipeline on any violations (using
constraint):@dlt.expect_or_fail("valid_id", "id > 0") # Defaults to constraint @dlt.table def my_table(): # ... your data transformation logicThis will fail the entire pipeline if any
idis not greater than 0. -
Drop invalid records and continue (using
expectand defaultdrop_invalid_recordsquality):@dlt.expect("valid_value", "length(value) > 5") @dlt.table def my_table(): # ... your data transformation logicRecords where
length(value)is not greater than 5 will be dropped, and the pipeline will continue. -
Warn on violations and continue (using
expectandwarnquality):@dlt.expect("valid_date", "date is not null") @dlt.table(quality="warn") def my_table(): # ... your data transformation logicThe pipeline will continue even if some
datevalues are null, but warnings will be logged.
Key Takeaways:
- Use
constraintfor strict data quality enforcement where any violation should halt the pipeline. - Use
expectfor monitoring data quality and allowing the pipeline to continue even with violations. - Configure the pipeline's
qualitysetting (or useexpect_or_fail) to control the behavior whenexpectexpectations fail.
Last updated 17 January 2025