The pipeline is green and the client's data is still wrong
Great Expectations turns the unwritten assumptions in a client's data into nightly checks, so the engineer finds the break before the dashboard does.
In brief
- Each Expectation is a verifiable assertion about data, like a unit test written for data.
- A Checkpoint is the main way to run checks in production. When it finishes, it runs Actions such as sending a Slack message or updating Data Docs.
- The Airflow provider has an operator that runs Checkpoints and needs GX 1.7.0+ and Python 3.10+. The nightly schedule lives in the Dag.
Revenue on the dashboard fell by half overnight, and not one job reported an error. Take a delivery company, a hypothetical client, one week after go-live: they call because yesterday’s figure looks wrong, yet the pipeline is green. Tracing it back, you find the source system has started sending orders with an empty amount column.
Forward deployed engineers run into this kind of incident all the time. Client data always comes with assumptions nobody has written down, and when one of them breaks, your code carries on as if nothing happened. Great Expectations lets you write those assumptions as automated checks, so that you find the problem before the client does.
What GX Core actually is
Great Expectations describes GX Core as the engine at the heart of the GX data quality platform. It is open source under the Apache 2.0 license, published on PyPI, and new releases still arrive regularly. The GitHub repository describes Expectations as unit tests for data, which is the easiest way to remember the idea.
The open license means you can try GX on your own machine against an extract of the data in the first week. Before bringing it into the client’s systems, though, check their internal policy on third-party libraries.
The concepts to learn, in order
The GX documentation defines an Expectation as a verifiable assertion about data. “The order_id column is never empty” and “the amount is always greater than or equal to 0” are both Expectations. You group Expectations into a suite, usually one suite per client table.
According to the GX documentation, a Checkpoint is the main way to validate data when GX runs in production. A Checkpoint runs Validation Definitions and passes the results to a list of Actions, which runs once for each Validation Definition. Alerts therefore always arrive after the checks have finished.
A worked example with an orders table
Back to the delivery company. Every night it loads an orders table into its data warehouse. In a discovery session, the client’s data engineer says four things: order IDs are unique, every order has an amount, the amount is never negative, and the status takes only a handful of fixed values.
Those four spoken statements become four Expectations. The snippet below sketches only the Checkpoint part in GX 1.x, following the “Create a Checkpoint with Actions” page in the GX documentation. Creating the data source, the Expectation suite and the Validation Definitions is described in comments; follow the documentation for whichever version the client has installed.
The Slack channel is a placeholder for illustration, and the API changes between 1.x releases, so compare this snippet against that page before running it:
import great_expectations as gx
from great_expectations.checkpoint import SlackNotificationAction, UpdateDataDocsAction
# Assumes you already have:
# context: the project's GX environment (from the environment setup step)
# validation_definitions: Validation Definitions for the orders table,
# using the four Expectations taken from the discovery session:
# 1. order_id is unique
# 2. amount is not null
# 3. amount is not negative
# 4. status belongs to a fixed set of values
# Actions run after validation finishes: alert Slack on failure, update Data Docs
actions = [
SlackNotificationAction(
name="slack_on_failure",
slack_token="${SLACK_TOKEN}",
slack_channel="#data-alerts",
notify_on="failure",
),
UpdateDataDocsAction(name="update_docs"),
]
checkpoint = gx.Checkpoint(
name="orders_checkpoint",
validation_definitions=validation_definitions,
actions=actions,
)
context.checkpoints.add(checkpoint)
# The nightly run: results are passed to the Actions
results = checkpoint.run(batch_parameters={"dataframe": orders_df})
The second Expectation, that the amount must not be empty, is the rule that catches the failure described at the start. With notify_on=“failure”, your team gets a Slack alert on the very night the amount column goes empty. The code reads no attributes from results. If you need to handle the results in code, read the documentation on result formats first.
The real value here lies outside any single line of code. Each Expectation is a client assumption recorded in a form that runs. The next time the client asks why the numbers are off, you have validation results that show which assumption broke.
Running it in Airflow
Many clients already orchestrate their pipelines with Airflow. Astronomer has a guide to using the GX provider to run checks inside a Dag. The provider includes an operator that runs a Checkpoint, and that operator can trigger Actions such as Slack or email notifications. Version 1.0.0 of the provider replaced the old GreatExpectationsOperator.
The nightly schedule belongs to the Dag; GX does not handle it. Before making promises to the client, check their environment: the provider needs GX 1.7.0+ and Python 3.10+. If the client still runs an older Python, the upgrade may take longer than writing the checks.
Which rules should not alert yet?
GX checks only what you write down. It cannot know that, at this client, a valid order must carry a warehouse code. The hardest part remains customer discovery: asking enough questions to learn what “correct” data means to them.
The opposite mistake is just as damaging: rules that are too strict. Suppose the status rule turns red every time the source system adds a new status, even though nothing is wrong with the data. Within a few weeks the client’s team gets used to ignoring alerts. By the night the amount column really is empty, nobody is reading them.
GX has two built-in tools for this, severity and mostly. Every Expectation has a severity of critical, warning or info, with critical as the default.
Test yourself: of the four rules above, which would you not let alert tonight? One reasonable answer is to keep critical for unique order IDs and non-empty amounts, since the client has confirmed those as hard rules.
The status rule should drop to warning until the client settles the list of values. For the non-negative amount rule, ask again whether refunds are recorded as negative amounts before letting it wake anyone up.
What to learn first, and what to put on your CV
Learn Expectation, Validation Definition, Checkpoint and Action first, and leave Airflow for later. When job hunting, look for FDE job descriptions that mention data quality or data validation.
On your CV, do not stop at “used Great Expectations”. Say which dataset you wrote checks for, how you set severity levels, and what errors those checks caught before they reached the client.
A good Expectation suite is also the most honest documentation of a client’s data that you can leave behind when you roll off the project.
Was this article useful?
Thanks for the feedback!
8 sources
- GX Core: Open Source Data Quality Platform | Great Expectations
- GitHub - great-expectations/great_expectations
- great-expectations · PyPI
- GX Core overview | Great Expectations
- Create a Checkpoint with Actions | Great Expectations
- Run a Checkpoint | Great Expectations
- Create an Expectation | Great Expectations
- Orchestrate Great Expectations with Airflow