Controlling Data Quality Programmatically: Why We Built the Telmai Python SDK
Most data quality monitoring runs alongside the pipeline, not inside it. Here’s why we built the Telmai Python SDK to put a fail-closed quality gate between write and publish, and what we learned getting it right.
In most stacks, data quality monitoring runs alongside the pipeline. It observes the pipeline but doesn’t control it. A monitor flags anomalies in the overnight batch and fires an alert. By the time someone reads it, the pipeline has already promoted the batch and downstream dashboards have refreshed on bad numbers. Detection worked. Nothing stopped the promotion.
Closing that gap means moving the quality decision into the pipeline, after a batch is written and before it is published to production. In this blog, we walk through how the Telmai Python SDK makes that decision a single call in your data jobs, blocking publication unless the table passes validation.

Why This Is Harder Than It Looks
Like most data observability platforms, Telmai detects anomalies and invalid records. Detection alone doesn’t protect downstream consumers, though. To stop a bad load, the decision has to sit in the orchestration layer, between writing a batch and publishing it. An external service can’t fail a Databricks task or halt an Airflow DAG on your behalf. The quality gate that makes that decision has to run as code inside your job.
Most teams assume this is a simple check they can script with a few validation rules. It isn’t. Gating a load means orchestrating four steps: trigger a scan, poll until it completes, read the alerts, and decide whether to stop the load. Along the way, five things can go wrong:
- The scan fails or runs past your deadline
- The scan never managed to read the table at all
- An alert comes back with a severity you don’t recognize
- The table has no monitors, so a clean scan proves nothing
- The network drops halfway through and the error handler moves on

In every one of these cases, the quality gate never sees a failure, so code built for the happy path lets the load through. Now bad data sits in your gold tables, and everyone downstream assumes it passed a quality check. That’s worse than having no check at all, because the business trusts it. A dependable quality gate has to fail closed: if it can’t confirm the data is clean, it stops the load.
Our First Answer, and What It Cost
Our first answer was the API. It exposed everything a quality gate needed, and teams that wanted one built their own client on top of it. That’s the classic build path, and it held up for a while.
In practice, every team rebuilt the same polling loop, state machine and error handling. It was usually written under a delivery deadline and tested only against scans that succeeded. Because the failure cases are rare, a homegrown gate can run cleanly for months. Then the first scan times out, the client reads “no answer” as “no problems,” and a bad load ships.
The costs are lopsided. A gate that blocks a good batch costs you an hour. A gate that passes a bad one costs the business its trust in the numbers. So we built the quality gate once, tested it against every one of those failure cases, and shipped it in the SDK so every team runs the same one.
How the SDK Gates a Data Load
Here’s what that looks like in practice: what you need to set it up, how the three gate modes behave, and what it costs to run.
Setup
Install with pip install telmai The SDK supports Python 3.9 through 3.14 and has one dependency, requests
Set three environment variables (host, tenant and API key) and you have a client.The gate works on tables already onboarded in Telmai with at least one monitor. It refers to each table by its asset ID, which you look up once with python -m telmai resolve <table> The API key has the same data access as your Telmai account.
Three Gate Modes
Every gate call runs the same scan a schedule would, triggered when the batch lands instead of on a timer. The modes differ only in what they do with the verdict:
- Circuit breaker stops the load. Place it between the write and publish steps. If the batch fails, it raises an exception, the task fails, and your orchestrator skips everything downstream.
- Quarantine keeps the pipeline moving. With Telmai’s data quality binning, flagged rows land in an object storage bucket you configure, so you can still promote the clean rows. The verdict also tells you whether binning covered every failing check, so you know when to hold the whole batch instead.
- Notify never blocks on a quality result. It waits for the scan to finish, then passes the verdict to your callback. Use it for pipelines that must run no matter what but still need someone told. In Python this is live pass-through, and on the CLI it’s
--mode notify.

from telmai import Telmai, Severity
ORDERS = "a1b2c3d4e5f6" # the table's asset id, from: python -m telmai resolve gold.orders
with Telmai.from_env() as tm:
write_batch()
tm.circuit_breaker(ORDERS, min_severity=Severity.MEDIUM) # raises if the batch is bad
promote_batch()
All three modes fail closed. Any outcome the gate can’t confirm as clean counts as a failure, from a timed-out scan to a table with no monitors. In notify mode, that means your callback receives a failure, never a pass. This is how the gate is built, not a setting you can forget to turn on.
Roll Out in Notify Mode First
When you first add the gate, run it in notify mode. It reports which batches it would have blocked while every load still goes through. Once its verdicts match what your team expects, switch to a blocking mode.
Works With Any Orchestrator
In Python, the gate is a single call, so it fits into an Airflow task or a Databricks job like any other code. Outside Python, the CLI runs the same gate and returns an exit code that any scheduler, CI/CD job or shell step can act on:
0: the data is clean2: the data failed a real check1: the gate couldn’t get an answer
python -m telmai gate --assets <asset-id> --min-severity HIGH
What It Costs to Run
- No new load – The gate triggers the scan you’d otherwise schedule. If a table also has a scheduled scan, let the gate replace it, or every batch gets scanned twice.
- Compute – Your warehouse pays to read the data. Checks run in Spark, either in Telmai’s cloud or, on a hybrid deployment, in your own cloud account.
- Incremental scans – With incremental scanning on (the Delta Only setting in Telmai), each scan covers only rows that arrived since the last one, tracked by a timestamp column. Otherwise it reads the full table.
- Latency – Expect minutes per batch for typical tables, depending on table size, full or incremental scan, and the Spark compute behind it. The gate’s deadline,
timeout_s, defaults to one hour. - Concurrency –
max_concurrencycaps how many scans hit your warehouse at once. The default is 20.
Manage Telmai as Code
The gate is the visible part, but most of the SDK is configuration. Connections, projects, assets, monitors, scans, alerts, incidents, DQ scores and data binning are all available through it. You can onboard a table from scratch, define its monitors, and keep them in git: export from staging, review the diff in a pull request, and import to production.
Built for production – Every request has a timeout. Reads retry on rate limits and server errors, honoring Retry-After. Proxies and private certificate authorities are supported, and certificate verification can’t be switched off. The API key never appears in a log line or an error message. The SDK ships with full type hints, checked under mypy strict.
What Can Go Wrong, and What the Gate Does
| What happens | What the SDK does |
|---|---|
| The scan fails or exceeds your deadline | Blocks, says the scan didn’t finish, and the CLI exits 1 |
| The scan couldn’t read the table | Blocks, reports it separately from bad data, and the CLI exits 1 |
| An alert has a severity the SDK doesn’t recognize | Treats it as blocking, not harmless |
| The asset has no monitors | Blocks: a clean scan with no checks proves nothing |
| An asset id is mistyped or ambiguous | Raises before any scan starts (the CLI exits 1), so a typo never looks like a data problem |
| The API rate-limits or has a transient error | Retries with backoff, honoring Retry-After (scan triggers only when it’s safe; see below) |
| Several assets fail at once | Reports every failure, not just the first |
What We Learned the Hard Way
Most of what makes the gate dependable came from getting something wrong first.
Table names are not identifiers – Our first design let you gate on a table name like gold.orders. On real tenants, two tables in one project can share a name, and renaming an asset in the Telmai UI broke every job that referenced it. The gate now takes asset IDs. A one-time lookup (python -m telmai resolve gold.orders) fails loudly if a name is unknown or ambiguous.
A blocked batch is not an error – A circuit breaker exists to stop the load. But a common pipeline pattern is “on any Telmai error, retry.” If a failed quality check raised the SDK’s general error class, that retry would quietly push past a real failure and let the load through. So the exception the gate raises when it trips sits deliberately outside that hierarchy.
“Couldn’t check” and “the data is bad” need different answers – A scan that can’t reach the warehouse still blocks the load. But telling the on-call engineer “your data is bad” starts a fire drill aimed at the wrong root cause. The verdict reports the two separately, and the CLI returns a different exit code for each.
A severity that doesn’t exist will pass everything – Telmai alerts are high, medium or low. There is no “critical.” A gate set to block on critical would set a bar nothing can reach, silently pass every batch, and leave the business trusting numbers it shouldn’t. The SDK rejects it at call time instead.
Not every request is safe to retry – Reads are idempotent, so retrying them is harmless. A scan trigger isn’t. Retrying one after a timeout can start a second full scan while the first is still running, doubling the load on your warehouse. So the SDK retries a trigger only when the platform confirms it never accepted the request.
Test against the real platform, every release – Mocks only prove your code agrees with itself. Before every release, the gate modes and the configuration API run against a live Telmai tenant, and a contract test checks every platform operation the SDK calls against the live API. That’s how we caught the first onboarding step timing out against a warehouse that was still starting up, and fixed it before any customer saw it in production.
If You’re Building Your Own Quality Gate
- Decide what “I don’t know” means, and make it block – Any result you can’t confirm as clean should stop the load. Enforce that in code, not in a config setting someone can forget to set.
- Separate “couldn’t tell” from “bad” – Both stop the load, but one is an infrastructure problem and the other is a data problem, and they page different people.
- Reference assets by stable IDs – Display names get duplicated and renamed. Pipeline code shouldn’t break when someone tidies up a UI.
- Know which of your calls are safe to retry – Reads are safe to retry. Anything that starts work on the other side, like triggering a scan, needs a stricter rule.
- Test against the real dependency – Mocks only confirm your assumptions. The live system’s behavior is the contract, whatever its docs say.
Final Thoughts
Detection was never the hard part. Most data quality tools can tell you a batch is bad. The hard part is acting on that inside the pipeline, at the one moment you can still stop the load. The Telmai Python SDK makes that a single call.
Get started with pip install telmai
(pypi.org/project/telmai), or book a demo, and we’ll walk through gating one of your own pipelines.
Want to stay ahead on best practices and product insights? Click here to subscribe to our newsletter for expert guidance on building reliable, AI-ready data pipelines.
- On this page
See what’s possible with Telmai
Request a demo to see the full power of Telmai’s data observability tool for yourself.