Skip to content

Testing generated DQX rules against a country policy

Ihor Seleznov6 min read

A data quality rule can hold back a valid order when it treats yesterday's country codes as the list a business accepts. If a rule is generated from earlier orders, a first order from a newly opened market could be rejected because that country never appeared in the history.

At TechFabric, we'd approve a generated country rule against the business's permitted markets before letting it reject records. We tested that decision with Databricks Labs DQX, a library that can inspect data and propose quality checks. In a synthetic country-code experiment on Databricks Free Edition, the rules from the default sample rejected two of four valid test values. Profiling the complete history recovered one of them, but also admitted an error we'd planted in the source.

The country policy and the test data

We wrote the expected answers before generating any rules. Our test business accepts the United States, United Kingdom, New Zealand and Australia, represented by US, GB, NZ and AU. A country is required, and the stored code must match exactly. ZZ, a missing value, an empty string and a string of spaces are invalid under that policy.

The synthetic history holds 10,002 rows. There are 5,000 US rows and 5,000 GB rows, plus one NZ row and one deliberately invalid ZZ row. Australia is permitted but has no rows at all. With that mix, a reviewer can tell an uncommon valid value apart from a valid value with no history and from an error already present in the source. We put the rare records at the end of one Spark partition, a single chunk of the input, to exercise the sampling limit deliberately. This arrangement demonstrates a failure case; it doesn't estimate how often a random production dataset would encounter it. Eight separate acceptance cases, four valid and four invalid, stayed fixed throughout the run.

What each profiling input produced

The DQX profiler first samples 30% of the input and then caps the result at 1,000 rows by default. Its documentation calls the generated rules candidates and recommends reviewing them before use. We used DQX 0.17.2, fixed the sampling seed at 42 and disabled AI-assisted primary-key detection, so the country rules came from statistical profiling without an LLM call. DQX profiling documentation

We compared the default sampling settings with a deliberately selected sample and the complete history. The selected sample contained 150 US rows, 150 GB rows and the one NZ row, with the planted ZZ error excluded. For both that sample and the complete history, we disabled sampling and the row cap so DQX could inspect every supplied row.

Input used to generate rules Rows profiled Country codes allowed by the generated rule Valid cases accepted, out of 4 Invalid cases rejected, out of 4
Default sampling, fixed seed 1,000 US, GB 2 4
Selected sample 301 US, GB, NZ 3 4
Complete history 10,002 US, GB, NZ, ZZ 3 3
Explicit business policy, checked with DQX Not generated US, GB, NZ, AU 4 4

The default sample contained US and GB, so its membership rule rejected NZ and AU. The selected sample admitted NZ, as intended, but still rejected AU. Seeing every historical row didn't resolve that absence, and it added ZZ to the permitted values. We also ran a fifth variant that raised the sampling fraction to 100% while leaving the cap at 1,000, and DQX still profiled 1,000 rows and produced the same permitted codes as the default sample.

Raising the fraction alone didn't reach the rare records at the end of our input.

Why the complete history still got it wrong

A complete history can answer which country codes have occurred. Our acceptance cases asked a different question, which codes the business permits. Australia had no historical row to contribute, while the planted ZZ error did, so more input gave the generator a more complete account of the source, including its mistake.

The selected sample already involved human judgment. We included New Zealand because the policy permitted it and removed ZZ because the policy didn't. That improved the candidates, but the missing Australian case still caught an incomplete rule. We'd keep the permitted-market list with the team that owns that decision and use the profiler's suggestions to identify differences worth reviewing. DQX executed the generated checks consistently with their definitions. The failure was treating observed values as the business policy.

This extends our earlier work on testing quality rules against deliberate defects. Here the acceptance set also includes valid records that a restrictive rule would wrongly reject.

Keeping generated country rules under review

We replaced the inferred list with the four countries in the written policy, kept a separate check for missing values and ran those checks through the same DQX engine, which accepted all four valid cases and rejected all four invalid cases. The membership check we ran was:

{
  "name": "country_approved",
  "criticality": "error",
  "check": {
    "function": "is_in_list",
    "arguments": {
      "column": "country",
      "allowed": [
        "'US'",
        "'GB'",
        "'NZ'",
        "'AU'"
      ]
    }
  }
}

The inner single quotes make those values string literals in this DQX version. We retained each generated rule and the per-case errors alongside the final policy checks, so a reviewer can trace a rejected value to the rule that rejected it. The comparison uses the same eight cases for every rule set.

For a reporting pipeline, we'd keep candidate rules in review while comparing them with an approved country reference. The acceptance cases then test the reviewed rules. A rule that rejects a permitted case or accepts a forbidden one returns to review; a passing set can be approved for the pipeline. That review sequence is the process we'd use to keep a changed sample from silently changing which orders reach a report.

Any wrong decision

All cases correct

Historical data

Generate candidate rules

Review against approved country reference

Approved country reference

Run acceptance cases

Valid and invalid cases

Approve rules for pipeline

Generated candidates are reviewed against the approved country reference and acceptance cases before approval for a pipeline.

Start with one generated country rule and ask the report owner for a permitted market that hasn't appeared in recent data. Add that value to the acceptance cases before changing the rule, and retain it when the business expands its approved list. That gives the next reviewer a concrete reason to preserve the new market.

Frequently asked questions

Should we disable sampling whenever DQX generates rules?

No. A complete scan can be useful for a manageable dataset, but our complete-history run still rejected Australia and accepted the planted ZZ error. Choose input that covers the relevant cases, then compare the candidates with the business's definition of valid data. Scanning more rows doesn't supply that definition.

Does this result apply to AI-generated DQX rules?

We tested DQX's statistical profiler and rule generator. AI-assisted rule generation is a separate path and wasn't part of this run. The same acceptance cases could test its output, but its results would need to be measured separately.

What did the Free Edition run actually test?

One serverless notebook generated candidate rules and evaluated five rule sets against eight cases, including the extra sampling-fraction check. The notebook used DQX 0.17.2 and synthetic data generated in the notebook. It tested rule decisions; deployment into a scheduled pipeline and the proposed approval process weren't part of the run.