← All blogs

How NOT to do automated data validation

A validation system can tick every "automated" box, coverage, scheduling, results tables, and still end up the most expensive part of your project. I reviewed a real setup like that: it worked, it got used, and using it cost more than anything else in the migration. This post walks through its three anti-patterns, what each one cost, and the system I built instead.

TL;DR Three anti-patterns from a real setup: four tables per validated table, a five-step path to run a validation, and failures reported as row dumps with no diagnosis. The system I built instead: two shared tables total, a macro that validates everything automatically at run end, and ten sample rows showing the exact mismatch. Plus two details that matter at scale: don't hash what isn't pre-hashed, and log a ready-to-run query with every failure.

The setup I reviewed

On paper it was complete. In practice, validating one table meant four tables: one per side to store row hashes, one to list the differences, and a summary table, per comparison. Getting a validation meant five steps: go through the application, generate the queries, fetch them from GitHub, and run them one by one, times sixty models if your change touched sixty models. And when a validation failed, finding the actual issue meant walking the difference table for a key, looking that key up in both hash tables, and digging through the rows to guess what didn't match.

None of that is a bug. Every piece worked as designed, and the system did get used; the migration demanded it. That is exactly what made it expensive: all that friction, paid in full on every change, made validation the most costly part of the entire project. That theme runs through all three anti-patterns.

DO NOT multiply tables

Four tables per validated table falls to almost nothing in three moves:

  • Don't store hashes, compute them on the fly. The two hash tables exist only to feed the comparison; calculate in the query and write only differences. Half the tables gone.
  • One summary for everything. A summary per comparison means knowing where to look, times every comparison. One general summary table answers "is everything okay?" with one query. Another quarter gone.
  • One shared difference table. Differences from every comparison land in the same table, tagged by comparison, instead of a table per run. The last quarter gone.

What's left is two shared tables for the entire system: one summary, one difference store. The obvious objection is that a shared difference table grows too big to query. It doesn't, because of how failures get reported; that's the third anti-pattern.

DO NOT make people work to be validated

Five steps to get a validation, times sixty models per change, and people actually walked that path, because they had no choice. Friction in a mandatory check doesn't block adoption; it converts straight into cost, hours of developer time per change spent on steps a machine should own.

The whole path can be a macro (a function, whatever your stack calls it) that needs nothing from the developer:

  • it starts automatically at run end,
  • walks the models that ran successfully, filtered to the project's scope,
  • does the table mapping and column mapping,
  • runs the validation queries and writes the results.

No lists of sixty model names, no fetching queries, no running them one by one. The developer's only interaction is seeing results right after their run. Being validated is a side effect of doing your job, and that is the only version of "automated" that gets used.

DO NOT raise alarms without a diagnosis

In the reviewed setup, a failure meant archaeology: difference table, key, two hash tables, guesswork. And when the answer finally surfaced, it was a dump of every problematic row with no hint of what about them was wrong.

What actually gets fixed: about five rows per side, ten total, showing exactly which values don't match. That's enough to spot the pattern (a truncated column, a timezone shift, a missing filter) and it's the reason the shared difference table from the first section stays small: ten rows per unmatched table, not 10 million.

The hard part of showing exact mismatches is the join key: you need to know which column pairs the two sides, and sometimes it doesn't cleanly exist. My suggestion: have Claude go through both schemas and draft a YAML key book mapping the pairs; done properly it covers something like 90% of cases. But errors happen, so two things are not optional: proper logging of which key was used, and an easy way for developers to correct a wrong key. An automated mapping you can't override is just a new source of mysterious failures.

Two details that matter at scale

Don't hash what isn't pre-hashed

Hash comparison sounds fast until you notice that on large tables you're computing hashes on both sides and then doing the comparison. If the hashes aren't precalculated, skip them: run the EXCEPT directly on the columns and save the extra pass. The one real upside of hashing is that you can compute column hashes alongside the row hash, so when a table is close to fully matching, you can pinpoint the problematic columns at scale. Use it when that's the question you're asking, not by default.

Log the query, not just the verdict

Developers should never write a query per validation to investigate a failure. The macro already knows the tables, the mapping, and the key it used, so it logs a ready-to-run query along with the result: how to get the summary, how to pull the differences, how to reproduce the check. Investigation starts with copy and paste, not with composing SQL from memory.

Side by side

The setup I reviewedThe system I built
4 tables per validated table2 shared tables for the whole system
5 steps to validate, 4 more to investigatezero steps: a macro validates everything at run end
every problematic row, no explanation5 rows per side showing the exact mismatch
developer writes investigation queriesready-to-run queries logged with every failure
the most costly part of the projectin daily use at near-zero developer cost: validation as a side effect of every run

I learned these the long way. The first validation system I built, during our own 600+ table migration, got the core right: a macro at run end, filtered comparisons, one summary broken down by source. The system on this page is its successor, built after seeing the opposite design up close, and it's what we work with now: validation just happens, and finding an issue starts from the answer instead of the question. The first version has its own write-up: We Migrated 600+ Tables to dbt. Here's How I Made Sure Nothing Broke.

What I learned

  • Validation is a product, and its user is a developer in a hurry. Judge it by what it costs that user, not by its coverage.
  • Friction converts into cost. A mandatory check behind five steps still gets run; you just pay for those steps on every single change.
  • Storage design is UX. Two shared tables people actually query beat hundreds of per-comparison tables nobody opens.
  • Show the diff, not the dump. Five rows per side with the exact mismatch beat 10 million rows with no explanation, and they keep your tables small enough to stay queryable.
  • Automate the mapping, keep the override. An LLM-drafted key book covers most of it; logging and a human-editable escape hatch cover the rest.
Written from a validation system I reviewed and one I built and run in production on a large dbt + Snowflake project. No names, real patterns. Related posts: the validation framework itself, Your dbt run succeeded. Was it built on fresh data?