Data contracts without tests are a description
Data contracts are great. Without tests, they’re a description. A contract can say order_total is a number and customer_id is required, and still sign off on data that is wrong in every way that matters.
So how do you fill in the tests? You can write them by hand. Our tools get you 80% of the way there. The rest comes from an LLM using MCP, plus your business users working in the open source TestGen UI. If you would rather hear and watch this than read about it, go check out my demo on how to do data contracts.
Here is what the demo turned up. The 67 tests TestGen generated all passed. The data had 483 orders with no items in them and a customer whose name was “name.”
One messy data set, three steps
We built TestGen to get you 80% of the tests you need, based on profiling your data, a semantic data model, and the decades of history our team has in testing data. That takes about 60 seconds.
Figure 1: The plan for the demo: 80% in 60 seconds, 90% in five minutes, 100% with business users.
Getting the rest is much harder. An LLM with better context about your business and how the data is used gets you to 90% in about five minutes. That is step two: add your LLM and the open source TestGen MCP server.
The last 10% needs the business, because so much contextual knowledge sits in people’s heads. Business users add the final rules in the UI, with no SQL.
You need both. You need a technical view, where you create contracts in YAML and run things through MCP or scripts. And you need a UI view, where a business person can click, revise, and add tests.
The data: the Jaffle Shop sample
The data is the standard dbt sample: a made-up e-commerce business with six stores selling jaffles and drinks.
Figure 2: Six tables, 26 columns, 153,866 rows, and messier than it looks.
That is six tables, 26 columns, and 153,866 rows. raw_orders has 61,948 rows, one per order. raw_items has 90,901 order line items. raw_customers has 936 rows, raw_products has 10 (the menu), raw_stores has 6 (stores and tax rates), and raw_supplies has 65 (ingredients per product).
It is messy like real raw data. Money and dates are stored as text. Two tables still have columns named c1, c2, and c3.
The first thing I typed in Claude was a question:
where is the jaffle data?
Then I gave it the Postgres host, database, and login. Claude found the original CSVs, a 16 MB Postgres dump, and the loaded copy in local Postgres 17. Any Postgres, Snowflake, Databricks, or file source works the same way.
60 seconds to 80%: ask for a contract, get v1
Two prompts get you a first contract.
Figure 3: Two prompts, seven MCP tools, 67 tests.
lets create a data contract for the jaffleshop data, all tables, using testgen
create tests in testgen and add to contract
Claude chose and ran seven TestGen MCP tools. test_connection checked the Postgres login. create_connection saved the connection as “jaffle.” create_table_group grouped the 6 tables. run_profiling profiled 153,866 rows in 10 seconds. create_test_suite made a Contract declaring all 6 tables. generate_tests, run by the second prompt, brought the contract to 67 tests from the profile. run_tests previewed the result: 67 of 67 passed.
The contract is a TestGen test suite of type Contract. Creating it with table names generates the schema, the catalog metadata, and the Contract generation set right away (43 tests). The second prompt added the Standard set (24). 43 plus 24 is 67.
Figure 4: The Jaffle Shop contract in the TestGen UI: the tests on the Quality Rules tab (left) and the contract metadata on its own tab (right).
TestGen profiles 60 characteristics and runs about two dozen hygiene checks. On the Jaffle data, profiling identified PII and some names with near-duplicate problems. In the UI you see the contract: the quality rules for each table, plus the contract metadata. The result is a v1 draft with 67 tests, all passing.
Five minutes to 90%: freeze v1, add business rules as v2
Now the LLM does what a generator cannot: it uses judgment about the business.
Figure 5: Claude tested each candidate rule in SQL, then added the 14 that mattered.
freeze v1, then create a v2, and use your judgement to add a new set of tests to v2. jaffle is ecommerce data
put v2 in force
Claude called freeze_contract_version, which made v1 the version in force. get_test_type chose a test type for each rule. Then create_test ran 14 times, adding 14 rules and opening the v2 draft. A run_tests preview showed 77 passing and 4 failing. Another freeze_contract_version made v2 the version in force, and a final run_tests was the official v2 run, with the failures on record.
Claude tested each candidate rule in plain SQL against the data first, then added the 14 that mattered. The result: v2 in force, 81 tests, 4 failing on real defects.
Frozen versions never change. Any edit to a frozen contract opens the next draft automatically, so versioning costs nothing. You can compare version one to version three and see it as a diff view, like a git diff.
The 14 e-commerce rules Claude wrote for v2
This is the slide to linger on. Profiling describes the data you have. These rules say what it should be.
Figure 6: Ten rules passed. Four failed, and the 67 generated tests had passed all four.
Ten rules passed. Five are Reference Match tests: “the order’s customer exists,” “the order’s store exists,” “the line item’s order exists,” “the line item’s SKU is a real product,” and “the supply’s SKU is a real product.” A Custom Condition checks that “order_total equals subtotal plus tax_paid.” Three Custom Tests check that “the subtotal equals the sum of item prices,” that “tax equals subtotal times the store rate within 1 cent,” and that “no order predates the store opening.” Another Custom Condition checks that “no order is future-dated.”
Four rules failed. “Subtotal greater than $0” failed on 483 rows. “Every order has an item” failed on the same 483 rows. “No CSV header row in customers” failed on 1 row, and “No CSV header row in items” failed on 1 row.
Generated tests in v1 passed all four. Those 483 ghost orders have a $0 subtotal and no line items. The CSV header rows were loaded as data, which is how you get a customer named “name.” Profiling learned both as normal, so the generated tests passed them. The business rules caught both on the first run.
That is not a bug in test generation. It did its job. Generated tests describe the data you have. Business rules say what it should be. You need both.
Claude already has a general idea of what e-commerce data looks like. Adding business context makes its queries more accurate and its understanding of your data better.
You can give it that context at every layer. On the back end, that is data lineage or your Git repo, where your dbt SQL lives. On the front end, it is query history and some background on your business. In the middle is what we add: profiling information and metadata that comes from tests.
That leaves a lot of room to improve automatic test generation in your organization. Gather all this contextual metadata, ontologies and the rest, in one place and give it to the model.
Step 3: add business metadata as v3, export ODCS
The contract now explains itself to the next reader.
Figure 7: The contract now explains itself to the next reader.
add some contract metadata to v2
export yaml.
Claude used get_contract_metadata to read what was there, then update_contract_metadata to add context, which opened the v3 draft. freeze_contract_version made v3 the version in force. export_contract wrote ODCS v3.2.0 YAML.
The metadata Claude added covers purpose, usage, and limitations, including the known defects. It wrote names and descriptions for 6 tables and 26 columns (c1 is now “Customer ID”). It also removed a wrong PII flag on product names. Metadata edits version the same way tests do.
The export is a standard ODCS document. Tests become quality rules, and you can hand the file to a supplier or import it into another TestGen. Custom SQL rules travel as written and are not translated between database dialects (see the limits in the import section below). It validates against the ODCS v3.2.0 schema with zero errors.
The last 10%: business users finish the contract
A business user creates or configures a rule in the TestGen UI, without SQL and without a ticket to the data team.
Figure 8: The last rules come from the people who know the business.
Here is how I put it: “the last 10% I just don’t think… you’re still going to need to collaborate with your business because there’s so much contextual knowledge that’s in people’s heads.”
A UI gives you somewhere to do that. You can send your business customer a link and say, “What do you think of this test? We just had an issue. I’m going to add a new test. Can you review it? Should this be 5%? Should this be 2%?” That improves communication over the contract. In my words: “So instead of having Hatfields and McCoys, or ‘I hate my data providers, they’re idiots’ or ‘I hate my customers, they’re idiots’, it provides a very concrete way for you to collaborate.”
If your business customer doesn’t think a test is good, you deactivate it in the contract. That makes a new version you can freeze and share.
Already have a contract? Import it, run it, improve it
Treat this part as a recipe: we did not run it for this post. Start with two prompts:
Figure 9: The round trip: a contract written anywhere comes in as tests and goes back out as ODCS.
import supplier_orders.odcs.yaml as a contract on the jaffle table group. preview it first
run it, then use your judgement to improve it
The first import_contract call is a preview only, and nothing is saved. A second call applies it, and the rules become locked tests. Then run_tests runs them. generate_tests fills gaps from profiling, and create_test adds your own rules in a new draft. diff_contract_versions shows what changed, and export_contract hands the improved file back.
Imported tests are locked, so regenerating from profiling never overwrites them.
Three limits, stated plainly. Rules TestGen cannot check stay in the file, marked unverifiable. SQL is not translated between database dialects. And the ODCS standard has minimal expressivity, so a lot of the tests in a TestGen contract are custom tests, written as plain SQL where the team could.
The whole session: six prompts, three contract versions
From first profile to v3 in force took about 15 minutes.
Figure 10: About 15 minutes from the first profile to v3 in force.
The six prompts below are the contract prompts. Finding the data and giving Claude the Postgres login came first.
| Prompt | Contract state after |
|---|---|
lets create a data contract for the jaffleshop data, all tables, using testgen | v1 draft |
create tests in testgen and add to contract | v1 draft, 67 tests |
freeze v1, then create a v2, and use your judgement to add a new set of tests to v2. jaffle is ecommerce data | v2 draft, 81 tests |
put v2 in force | v2 in force |
add some contract metadata to v2 | v3 in force |
export yaml. | ODCS v3.2.0 file |
You can repeat all of this on any database TestGen connects to. The TestGen MCP cheat sheet lists the tools, and installing TestGen takes a few minutes.
I also ran it live on a copy of AdventureWorks, with one sentence:
create a data contract for Adventure Works copy, make tests, run them, and version it
The contract suite ended with 650 test definitions. That is the “hundreds” in the title.
A contract that only knows what your data looks like today will sign off on 483 orders with nothing in them.
Other tools help you write the contract YAML by hand. DataKitchen builds an enforceable contract quickly and easily, with your business users collaborating on it.
FAQ
What are the key points in this blog?
A data contract without tests is only a description. In the demo, 67 generated TestGen tests all passed on 483 orders with no items. Four of the 14 LLM-written business rules failed, catching 483 ghost orders and CSV header rows loaded as data. Business users finish the last 10% in the UI, and the contract exports as ODCS v3.2.0 YAML.
Why do data contracts need tests?
Without tests, a data contract only describes the data and enforces nothing. It can declare every field and type and still pass bad rows. In the Jaffle Shop sample, 483 orders had no items, and a customer was named “name.”
How fast can you get from zero to a data contract with TestGen?
From first profile to version 3 in force took about 15 minutes. Profiling 153,866 rows took 10 seconds, and the first 67 tests took about 60 seconds. Claude then added 14 business rules in about five minutes through the TestGen MCP tools, bringing the contract to 81 tests.
What did the generated tests miss?
The 67 generated tests missed 483 orders with a $0 subtotal and no line items, plus two CSV header rows loaded as data, which is how you get a customer named “name.” Profiling learned both as normal, so the generated tests passed them. The LLM’s business rules caught both on the first run.
How do business users add rules to a data contract?
Business users create or configure rules in the TestGen UI, without SQL and without a ticket to the data team. You can send a business customer a link and ask whether a threshold should be 5% or 2%. If they reject a test, you deactivate it, which makes a new version you can freeze and share.
Can you import an existing contract or export one?
Yes. TestGen exports a contract as ODCS v3.2.0 YAML that validates with zero errors, and import turns an existing file’s rules into locked tests. The import steps are a recipe: we did not run them for this post. Import previews first and saves nothing until a second call applies it. Rules TestGen cannot check stay in the file, marked unverifiable. Installing TestGen takes a few minutes.