Inferensys

Glossary

Data Quality Rule

A data quality rule is a declarative or programmatic statement that defines a specific condition data must satisfy to be considered valid, such as a column being non-null or values falling within an expected range.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
AUTOMATED DATA TESTING

What is a Data Quality Rule?

A foundational concept in automated data testing, a data quality rule is a formalized condition that data must satisfy to be considered valid and fit for use.

A Data Quality Rule is a declarative or programmatic statement that defines a specific condition data must satisfy to be considered valid, such as a column being non-null, values falling within a predefined range, or adhering to a complex business logic. These rules are the executable specifications of data quality, transforming abstract requirements into automated checks. They serve as the core building blocks within frameworks like Great Expectations, dbt tests, and Soda Core, enabling test-driven development for data pipelines.

Implemented as assertions or unit tests, data quality rules act as quality gates within pipelines, preventing invalid data from propagating. They validate everything from basic schema integrity to complex business rule validation using static or dynamic thresholds. By codifying expectations, these rules make data quality objective, automatable, and integral to the software development lifecycle, forming the basis for data reliability engineering and continuous testing.

AUTOMATED DATA TESTING

Core Characteristics of Data Quality Rules

Data Quality Rules are the fundamental building blocks of automated data testing. They are declarative or programmatic statements that define the conditions data must meet to be considered valid and trustworthy for downstream consumption.

01

Declarative vs. Programmatic

Data quality rules exist on a spectrum from declarative to programmatic.

  • Declarative Rules specify what condition the data must satisfy using configuration (e.g., YAML, SQL). Examples include column X must be non-null or values in column Y must be between 1 and 100. Frameworks like dbt tests and Soda Core use this approach.
  • Programmatic Rules define how to check the condition using code (e.g., Python, Scala). This allows for complex, custom logic, such as validating business-specific calculations or multi-column relationships. Libraries like Great Expectations support both paradigms.

The choice depends on the complexity of the validation and the need for custom logic versus simplicity and maintainability.

02

Scope and Granularity

Rules can be applied at different levels of a dataset, each serving a distinct purpose in the validation hierarchy.

  • Schema-Level: Validate structural integrity, such as column existence, data types, and primary/foreign key constraints.
  • Column-Level: Check properties of individual fields, including value ranges, allowed enumerations, format patterns (e.g., email, date), and nullability.
  • Row-Level: Enforce conditions that apply to each record, like if column A = 'X', then column B must be > 10.
  • Dataset-Level: Assess aggregate properties of the entire table or batch, such as row count thresholds, uniqueness of a composite key, or statistical summaries like mean and standard deviation.

Effective test coverage requires a mix of rules across all granularities.

03

Static vs. Dynamic Thresholds

A critical characteristic is whether a rule's pass/fail criteria are fixed or adaptive.

  • Static Thresholds use hard-coded, absolute values (e.g., error_rate < 0.01%, latency < 500ms). They are simple to implement but can become brittle if underlying data patterns naturally evolve.
  • Dynamic Thresholds are calculated automatically based on historical data, often using statistical process control (SPC) methods. For example, a rule might flag a value if it falls outside 3 standard deviations of the 30-day rolling mean. This adapts to seasonality and legitimate data drift, reducing false positives.

Dynamic thresholds are essential for monitoring metrics like daily row counts or aggregate sums in production environments.

04

Deterministic vs. Probabilistic

Rules differ in their certainty of identifying an issue.

  • Deterministic Rules produce a binary, unambiguous result. A value either conforms to a regex pattern or it does not; a foreign key either has a match in the parent table or it does not. These are used for enforcing absolute business logic and contractual guarantees.
  • Probabilistic Rules identify anomalies or outliers based on statistical likelihood. They answer "is this data point unusual given historical context?" These are crucial for anomaly detection in metrics like transaction volumes or sensor readings, where some variation is expected, but significant deviations may indicate problems.

Most robust data quality postures employ a combination of both types.

05

Actionability and Severity

Not all rule violations are equal. A core characteristic is defining the consequence of a failure.

  • Severity Levels classify a rule's importance (e.g., BLOCKER, WARNING). A BLOCKER failure on a pipeline-gated test halts the data flow to prevent corrupt data from propagating. A WARNING may log an alert for investigation but allows the pipeline to proceed.
  • Actionability dictates the response. Rules should be designed to trigger specific, useful actions:
    • Alert: Notify a team via Slack, PagerDuty, etc.
    • Quarantine: Route failing records to a holding area for manual review.
    • Block: Fail the pipeline job entirely.
    • Auto-remediate: Trigger a predefined corrective workflow.

Clear severity and action links are key to effective data incident management.

06

Metadata and Lineage Integration

Modern data quality rules are not isolated checks; they are enriched with context and connected to the broader data ecosystem.

  • Rule Metadata: Includes the rule's author, creation date, last modified timestamp, business owner, and associated SLAs or SLOs. This is vital for governance and accountability.
  • Lineage Awareness: Rules should be linked to the specific data assets (tables, columns) they validate. When a rule fails, data lineage and dependency mapping tools can instantly visualize all downstream consumers impacted, drastically reducing triage time.
  • Integration with Catalogs: Rule definitions and historical pass/fail results should be visible within enterprise metadata management and catalogs, providing a single pane of glass for data health.

This integration transforms rules from simple validators into intelligent components of a data observability platform.

AUTOMATED DATA TESTING

How Data Quality Rules Are Implemented

A Data Quality Rule is a declarative or programmatic statement that defines a condition data must satisfy to be considered valid. Implementation involves embedding these rules into automated testing frameworks to enforce integrity throughout the data lifecycle.

Implementation begins by codifying rules as declarative tests or programmatic assertions within a data pipeline. These rules, which define constraints like non-null values or valid ranges, are executed by a test execution engine at specific stages, such as during ingestion or transformation. A failing rule can trigger a pipeline-gated test, halting the workflow to prevent corrupt data from propagating downstream. This practice, known as Data Quality as Code, ensures rules are version-controlled, reviewable, and reproducible.

Effective implementation requires test orchestration to schedule validations and test result aggregation for monitoring. Rules are often grouped into an expectation suite and run via a checkpoint. Advanced implementations use dynamic thresholds calculated from historical data, rather than static values, to adapt to changing data patterns. This systematic approach, integral to Continuous Testing, provides deterministic quality control, transforming subjective assessments into automated, auditable guarantees.

TAXONOMY

Common Types and Examples of Data Quality Rules

Data quality rules are categorized by the specific dimension of data integrity they enforce. This taxonomy organizes rules from foundational structural checks to complex business logic validation.

01

Completeness & Validity Rules

These rules enforce the presence and basic correctness of data values. They are the most fundamental checks in any data quality suite.

  • Non-null Rule: Ensures a required column contains no null or empty values (e.g., customer_id IS NOT NULL).
  • Format Validity Rule: Validates that string data matches a defined pattern, such as an email address, phone number, or UUID regex.
  • Domain Validity Rule: Checks that a value exists within a predefined set of allowed values (e.g., status IN ('active', 'inactive', 'pending')).
02

Accuracy & Conformity Rules

These rules verify that data correctly represents real-world entities and adheres to defined standards and schemas.

  • Referential Integrity Rule: Ensures foreign key values in one table have a corresponding primary key in a related table, maintaining relational consistency.
  • Schema Conformity Rule: Validates that a dataset's structure (column names, data types, nullability) matches a declared contract or expected schema.
  • Cross-field Validation Rule: Checks logical relationships between columns (e.g., end_date must be after start_date, discount_amount cannot exceed total_amount).
03

Uniqueness & Consistency Rules

These rules prevent data duplication and ensure uniform representation of information across the system.

  • Primary Key Uniqueness Rule: Guarantees that a column or combination of columns meant to be a unique identifier contains no duplicate values.
  • Business Key Uniqueness Rule: Ensures uniqueness on a domain-specific natural key (e.g., combination of user_email and signup_date).
  • Consistency Rule: Validates that the same entity is represented identically across different tables or systems (e.g., a customer's name is spelled the same in all records).
04

Timeliness & Freshness Rules

These rules monitor the currency and delivery speed of data, which is critical for time-sensitive analytics and decision-making.

  • Data Latency Rule: Measures the time elapsed between a real-world event and its availability in the data warehouse (e.g., event_ingestion_timestamp - event_occurred_timestamp < 5 minutes).
  • Pipeline Freshness Rule: Checks that a table or data asset has been updated within an expected time window (e.g., MAX(updated_at) > CURRENT_TIMESTAMP - INTERVAL '1 hour').
  • SLA/SLO Rule: A business-oriented rule defining the acceptable thresholds for data delivery, often tied to formal service-level agreements.
05

Statistical & Distribution Rules

These rules use statistical methods to monitor the shape and properties of data, detecting anomalies and drift.

  • Value Range Rule: Ensures numerical values fall within a minimum and maximum bound (e.g., age BETWEEN 0 AND 120). Can use dynamic thresholds based on historical percentiles.
  • Statistical Distribution Rule: Monitors that the distribution of values in a column (mean, median, standard deviation) remains within expected bounds, a core technique for data drift detection.
  • Volume/Row Count Rule: Validates that the number of records in a dataset is within an expected range (e.g., daily_record_count BETWEEN 1000 AND 1500), alerting to ingestion failures or surges.
06

Business Logic & Custom Rules

These are complex, domain-specific rules that encode critical business knowledge and calculations.

  • Calculated Metric Rule: Validates the correctness of a derived metric against its constituent parts (e.g., total_revenue = SUM(line_item_price * quantity)).
  • Multi-Table Business Rule: Enforces logic spanning multiple datasets (e.g., the sum of all regional sales in a fact table must equal the company-wide total in a separate summary table).
  • Compliance Rule: Encodes regulatory or legal requirements (e.g., data_retention_days >= 7 years for financial records). These are often implemented as business rule validation suites.
DATA QUALITY RULE

Frequently Asked Questions

A data quality rule is a declarative or programmatic statement that defines a condition data must satisfy to be considered valid. These rules are the foundational building blocks of automated data testing, enabling engineers to enforce integrity, consistency, and business logic across data pipelines.

A data quality rule is a formal, executable statement that defines a condition or constraint data must meet to be considered valid, such as a column being non-null or values falling within a specific range. It works by being evaluated against a dataset, producing a pass/fail result or a quantitative metric. In practice, a rule like column 'customer_id' must be unique is codified using a framework like Great Expectations or dbt Tests, which executes a SQL query or a Python function to check for duplicates. The rule engine compares the actual data state against the declared expectation, logging failures and often blocking pipeline progression if critical rules are violated, thus acting as an automated gatekeeper for data integrity.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.