Integrating Automated Rule Discovery with Great Expectations Using SDK

Integrating Automated Rule Discovery with Great Expectations Using DataBuck SDK

By Sri Harsha Tanmalla

Great Expectations (GX) makes it straightforward to validate data, but defining the right Expectations is often where much of the engineering effort goes.

For a handful of tables, manually creating Expectations is manageable. But when you’re working with hundreds of datasets, identifying and maintaining those rules becomes more challenging.

I recently explored whether we could simplify this process by using DataBuck SDK to discover data quality rules automatically and then execute them through an existing GX pipeline.

The goal wasn’t to replace Great Expectations. It was to see how automated rule discovery could fit into a workflow that already uses GX for validation.

How the Integration Works

DataBuck SDK analyzes datasets and generates candidate data quality rules, including completeness, uniqueness, validity, and SQL-based conditions.

The workflow is straightforward:

Dataset → DataBuck SDK → Discovered Rules → Great Expectations → Validation Results

We tested two approaches to executing these rules using GX on Databricks.

Approach 1: Converting Rules into Native GX Expectations

In the first approach, we mapped discovered rules to standard GX Expectations wherever possible.

For example, a not-null constraint could be mapped to ExpectColumnValuesToNotBeNull.

More complex conditions that couldn’t be translated directly were handled using GX’s UnexpectedRowsExpectation with custom SQL.

Of the 96 row-level rules we tested:

  • 18 mapped to native GX Expectations.
  • 78 required custom SQL.

This approach worked well for readability and compatibility with existing GX workflows. However, translating complex rules required additional logic, especially to preserve SQL NULL semantics.

Approach 2: Validating Boolean Results with GX

For the second approach, we let Spark execute the discovered SQL rules directly.

Each rule generated a Boolean result column indicating whether the record satisfied the condition. We then used GX’s ExpectColumnValuesToBeInSet to validate that these columns contained only True.

This removed the need to translate individual rules into native Expectations.

The trade-off was that the GX results contained generic Boolean-column checks rather than descriptive native Expectation types. We retained rule metadata to make the results understandable.

What We Observed

We tested both approaches on Databricks Runtime 17.3 LTS ML with Spark 4.0.0 and Great Expectations 1.24.1.

The test dataset contained 10,000 rows and 50 columns, with 96 row-level rules and one dataset-level check.

Both approaches produced identical validation results.

Metric Native GX Boolean Columns
Passed checks 72 72
Failed checks 25 25
Execution errors 0 0
Quality-gate breaches 8 8
Median execution time 87.56 sec 52.91 sec

The Boolean-column approach was approximately 40% faster in our experiment.

We ran each approach once for warm-up, followed by three timed executions. These findings are specific to our test environment and workload.

What We Learned

Both integration approaches worked, but they serve slightly different needs.

Native GX Expectations are useful when teams want readable, reusable Expectation Suites.

The Boolean-column approach is useful when working with many complex SQL-based rules, particularly when exact native GX mappings aren’t available.

For our use case, the Boolean-column approach offered a simpler integration and better execution performance.

One important consideration is that automatically discovered rules should still be reviewed before being used in production. A rule that describes existing data patterns isn’t necessarily a valid business constraint.

Final Thoughts

This experiment showed that automated rule discovery and data validation can be handled independently.

DataBuck SDK can help identify candidate rules, while Great Expectations continues to execute validations within the existing data pipeline.

For teams already using GX, this offers a possible way to reduce manual rule creation without changing their validation framework.

I’d be interested to hear how others in the GX community handle automated Expectation generation or complex SQL-based validations.

Have you tried a similar approach?