guide
guide9 min read

How Do You Detect Wrong Data When Every Airflow Task Succeeds?

Why a green DAG says nothing about the numbers, and the checks that catch silent data failures

To detect wrong data when every Airflow task succeeds, you have to add checks that test the output, because Airflow only records whether the code ran. In one VentureBeat account of two silent failures, a pipeline ran for 11 days with green DAGs while audience counts were 40% wrong, and no alert fired. The fix is five layers of semantic checks: schema at ingestion, partition completeness, volume against history, freshness, and business-metric bounds.

Key Takeaways

  • •A green Airflow task means the process exited cleanly. It says nothing about whether the rows, counts or values are correct.
  • •In the VentureBeat case study, a renamed upstream field left audience counts 40% wrong for 11 days with zero errors.
  • •Run cheap structural checks first (schema, partition size), then statistical checks (volume against a trailing baseline), then business-metric bounds.
  • •Put the gate at the ingestion boundary. A mismatch caught there costs minutes. The same mismatch found downstream costs days of reprocessing.
  • •Detection is half the job. Someone still has to trace the cause and the blast radius, and that is work an agent can do from the evidence your checks leave behind.

Why a green DAG proves so little

Airflow marks a task successful when the operator returns without raising. A Spark job that joins on a key that no longer matches returns zero matched rows and exits with code 0. A load that reads an empty partition writes an empty table and exits with code 0. Both are correct behavior for the code as written. Nothing in the scheduler has any idea what the output should look like.

The VentureBeat article describes exactly this. An upstream ad network renamed a field and added a new one without warning, the join key stopped matching, and segment counts collapsed. The second incident was a feed that silently dropped data: the S3 partition existed, so the DAG succeeded, and three days of audience data vanished. In both cases a client noticed before the data team did.

The article's diagnosis is that monitoring checked structural completeness (the job ran, the partition existed, the table had rows) and never semantic correctness. We agree with that framing, and it gives us a useful test for any pipeline: if the upstream source changed shape tonight, which task would turn red? If the honest answer is none, the pipeline has a silent-failure gap.

Layer 1: validate the schema at the ingestion boundary

The first gate sits before any transformation. The source in the VentureBeat piece recommends validating incoming event schemas against a registry at ingestion, and argues that catching a mismatch there costs minutes where downstream corruption costs days. We would add one detail: make the gate fail the run, not just log a warning, for the fields your joins depend on.

In Airflow this can be a plain Python task placed upstream of the transform. It reads a sample of the new batch, compares the field names and types to the contract, and raises on a missing or retyped join key. New optional fields can warn. Missing required fields should stop the DAG so the failure is loud and attributed to the right task.

python from airflow.decorators import task REQUIRED = {"event_id": str, "segment_id": str, "user_id": str} @task def validate_schema(sample: list[dict]): missing = [k for k in REQUIRED if any(k not in row for row in sample)] wrong_type = [k for k, t in REQUIRED.items() if any(k in r and not isinstance(r[k], t) for r in sample)] if missing or wrong_type: raise ValueError(f"schema drift: missing={missing} wrong_type={wrong_type}")

The point is that the renamed-field incident becomes a red task on day one instead of a client complaint on day eleven.

Layer 2: check partition completeness, not existence

An empty partition is a valid partition. The second incident in the article happened because the S3 prefix existed, so any sensor that only checked for the path passed. The article's recommended metric is partition completeness measured by file count and byte count, which is the right unit because it is cheap and does not need the data to be parsed.

Compare today's partition against the median of the trailing seven. A partition that is under half the median size deserves a stop, not a warning. Do not hard-code the threshold forever, because seasonality will bite you, but a coarse bound catches the catastrophic case: the feed that went to zero.

For warehouse-landed data, the same check is a row count against a baseline. Airflow's common SQL provider ships operators for this. The SQLTableCheckOperator documentation describes a checks dictionary in which each named check carries a check_statement that resolves to a boolean, for example COUNT(*) = 1000, and an optional partition_clause that scopes the check to one slice.

Layer 3: compare volume and values against history

Static thresholds miss the 40% case. A segment count that falls by 40% is not zero, not null and not obviously invalid. It is only wrong relative to what the pipeline produced yesterday. That makes the check statistical: compute today's metric, compute a trailing baseline, and fail when the ratio leaves a band.

The simplest runnable form is a dbt singular test. dbt documents four built-in generic tests (unique, not_null, accepted_values and relationships), and none of them look at history, so you write the baseline comparison as a SQL file. The same page notes that error_if and warn_if set custom failure thresholds, so a drop can warn at one level and fail at another.

sql -- tests/audience_segment_volume.sql {{ config(severity='error', warn_if='>0', error_if='>2') }} with today as ( select segment_id, count(*) as n from {{ ref('audience_events') }} where event_date = current_date - 1 group by 1 ), baseline as ( select segment_id, avg(n) as avg_n from ( select segment_id, event_date, count(*) as n from {{ ref('audience_events') }} where event_date between current_date - 8 and current_date - 2 group by 1, 2 ) group by 1 ) select t.segment_id from today t join baseline b using (segment_id) where t.n < 0.6 * b.avg_n

The test returns the offending segments. Zero rows passes, one or two rows warns, more than two fails the build. The 0.6 multiplier is a starting point that we tune per dataset, not a universal constant.

Layer 4: freshness and the business metric itself

Freshness is the hours since the last successful load, and the article lists it among its recommended metrics alongside schema validation pass rates and pipeline SLA windows. Its first recommendation is the more important one: monitor the business outcome, such as audience segment counts, not only system metrics. A pipeline can be fresh, complete and wrong in the one number an executive reads.

In Airflow, put the business-metric gate at the end of the DAG so a bad day is flagged before downstream consumers read it. The column and table check operators let you encode bounds declaratively. The SQLColumnCheckOperator documentation describes a column_mapping where each column maps to checks such as null_check, min and max, with conditions like geq_to and equal_to.

python from airflow.providers.common.sql.operators.sql import ( SQLColumnCheckOperator, SQLTableCheckOperator) quality_gate = SQLColumnCheckOperator( task_id="segment_bounds", conn_id="warehouse", table="analytics.audience_segments", column_mapping={ "segment_id": {"null_check": {"equal_to": 0}}, "user_count": {"min": {"geq_to": 1}}, }, ) fresh = SQLTableCheckOperator( task_id="fresh_enough", conn_id="warehouse", table="analytics.audience_segments", checks={"loaded_recently": { "check_statement": "MAX(loaded_at) > CURRENT_TIMESTAMP - INTERVAL '6 hours'"}}, ) validate_schema_task >> transform >> [quality_gate, fresh]

The interval syntax is warehouse-specific, so adjust it for your engine. If you are on Snowflake, data metric functions can run quality checks inside the warehouse on a per-table schedule, described in the Snowflake data quality docs. Either approach is fine. What matters is that the check runs on every load and can fail the run.

Layer 5: what an agent adds after a check fails

Layers one to four tell you something is wrong. They do not tell you why, who is affected, or what to change. That gap is where the on-call engineer spends the hours. We built the Observability Agent to work on exactly that gap, reading the evidence the checks leave behind.

The mechanics are concrete. When the volume test fails, the agent pulls the run history for the failing task, diffs the schema of today's batch against the last passing batch, and walks the lineage graph downstream from the failing model to list the dashboards and tables that read it. A renamed field shows up as one removed key and one added key, which is the diff that took eleven days to find in the incident above.

It then hands that context to the Orchestration Agent, which routes the fix: a mapping change for the Pipeline Agent to propose, or a notice to the upstream owner. In the default read-only OSS edition the agent reports and proposes. Applying a change requires an approval you configure. You can ask it directly from Claude Code: "Why did row counts drop 40% overnight?" or "What's the blast radius if the segment_id mapping changes?"

A rollout order that does not drown the team in alerts

Start with layer one and layer two on your three most consumed datasets. These checks have a near-zero false-positive rate because a missing join key or an empty partition is never correct. Run them for a week before adding anything statistical.

Add the volume test in warn-only mode next. Watch how often it fires against days you know were healthy, then tighten or loosen the multiplier. Promote it to error severity only once you trust it. Teams that skip this step end up muting the alert channel, which recreates the original problem with extra steps.

Finally, name an owner for each check. A failing gate with no owner is a red task nobody reads. The owner is also who the agent notifies, so the routing is the same list you wrote down for the humans.

Frequently Asked Questions

Why does Airflow show success when the data is wrong?

Airflow records whether an operator returned or raised. It has no model of what the output should contain. A join that matches nothing and a load of an empty partition both finish without an exception, so the task is green. Correctness has to be asserted by a check you add, such as a row-count, schema or bounds test that raises when the result is implausible.

Which Airflow operators check data quality?

The common SQL provider includes SQLTableCheckOperator, SQLColumnCheckOperator, SQLValueCheckOperator and SQLThresholdCheckOperator, all documented in the provider docs. Use the table and column operators for declarative bounds, and a Python task for schema validation against a contract at ingestion.

Should data quality checks block the pipeline or only alert?

Block on checks with no legitimate failing state: missing join keys, empty partitions, null primary keys. Warn on statistical checks until you have measured their false-positive rate. dbt's warn_if and error_if thresholds support this staged approach within one test.

How is an agent different from adding more tests?

Tests detect. An agent investigates. It correlates the failing check with schema diffs, run history and lineage, then reports the root cause and affected consumers. In a read-only deployment it proposes the fix and a human approves it.