Inferensys

Glossary

Declarative Data Tests

Declarative Data Tests are quality validation rules defined in a high-level, configuration-based language that specify expected data conditions without detailing the procedural steps for checking them.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
DATA OBSERVABILITY AND QUALITY POSTURE

What is Declarative Data Tests?

A core methodology for ensuring data integrity through configuration-driven validation.

Declarative Data Tests are automated quality validation rules defined in a high-level, configuration-based language (e.g., YAML, SQL) that specify expected data conditions—such as uniqueness, freshness, or referential integrity—without detailing the procedural steps for checking them. This approach separates the 'what' (the business logic) from the 'how' (the execution engine), enabling data engineers to define constraints like column_X must be non-null in a portable, version-controlled file. The underlying Data Quality Rule Engine then interprets and executes these statements, making validation scalable and maintainable across complex pipelines.

This paradigm is foundational to modern Data Observability Platforms and practices like Data Monitoring as Code, where tests are treated as declarative infrastructure. By codifying expectations for schema, statistical distribution, and custom business rules, teams establish Data Quality Gates that prevent faulty data from propagating. This shifts data validation from ad-hoc scripting to a systematic engineering discipline, directly supporting Data Reliability Engineering (DRE) objectives and enabling automated enforcement of Data Contracts between producers and consumers.

DATA OBSERVABILITY PLATFORMS

Key Characteristics of Declarative Data Tests

Declarative Data Tests define validation rules in a high-level configuration language, specifying what data conditions must be true without detailing how to check them. This approach enables scalable, maintainable, and portable data quality assurance.

01

Configuration-Driven Definition

Tests are defined as configuration artifacts (e.g., YAML, JSON, SQL snippets) rather than imperative code. This separates the validation logic from the execution engine, enabling:

  • Portability: The same test definition can be executed across different runtime environments (Spark, Snowflake, BigQuery).
  • Version Control: Test logic is stored in Git, enabling code review, rollback, and audit trails.
  • Centralized Management: A single source of truth for all data quality rules across an organization.
02

Separation of Logic and Execution

The declarative model enforces a clean separation between the what (the validation rule) and the how (the execution engine). The test author specifies the expected condition (e.g., column X must be unique), and the underlying Data Quality Rule Engine determines the optimal execution path. This abstraction:

  • Simplifies authoring for data practitioners who understand business logic but not distributed computing.
  • Enables engine optimization, as the platform can choose the most efficient query or algorithm.
  • Facilitates tool agnosticism, allowing organizations to switch execution backends without rewriting tests.
03

Composable and Reusable Rules

Declarative tests are built from atomic, reusable components. Common patterns include:

  • Schema Validations: Checks for data type, nullability, and allowed values.
  • Freshness Checks: Ensures data is updated within a specified time window.
  • Volume Anomalies: Detects unexpected spikes or drops in row counts.
  • Custom SQL Assertions: Allows for complex business logic validation. These components can be composed into test suites applied to multiple tables or datasets, ensuring consistent quality standards. Changes to a base rule propagate automatically to all dependent tests.
04

Integration with CI/CD and Data Pipelines

Declarative tests are designed to be executed as automated checkpoints within modern data workflows:

  • CI/CD for Data: Tests run automatically in pre-merge checks for schema changes or new data pipeline code.
  • Data Quality Gates: Tests act as gates in orchestration tools (e.g., Airflow, Dagster), preventing downstream processes from consuming invalid data.
  • Shift-Left Testing: Quality rules are applied to development and staging environments, catching issues before they reach production. This practice is foundational to Data Reliability Engineering (DRE).
05

Declarative vs. Imperative Testing

This contrasts with imperative data testing, where validation logic is written as procedural code (e.g., Python scripts with explicit loops and conditionals).

Declarative (YAML Example):

yaml
test_type: uniqueness
table: orders
columns: [order_id]

Imperative (Python Pseudocode):

python
def test_uniqueness():
    df = spark.table('orders')
    duplicate_count = df.groupBy('order_id').count().filter('count > 1').count()
    assert duplicate_count == 0

The declarative approach is more concise, less error-prone, and easier for non-engineers to audit and modify.

06

Core Quality Dimensions Addressed

Declarative tests are used to enforce key dimensions of the Data Health Score:

  • Accuracy: Data correctly reflects the real-world entity it represents (e.g., price > 0).
  • Completeness: Mandatory fields are populated (e.g., customer_id IS NOT NULL).
  • Consistency: Data conforms to uniform formats and units across systems.
  • Timeliness/Freshness: Data is available within an expected timeframe (e.g., max(timestamp) >= NOW() - INTERVAL '1 hour').
  • Uniqueness: No unintended duplicate records exist.
  • Validity: Data adheres to defined business rules and domain constraints.
DATA QUALITY VALIDATION

How Declarative Data Tests Work

Declarative Data Tests are a core component of modern data observability, enabling automated quality validation through configuration rather than custom scripting.

Declarative Data Tests are quality validation rules defined in a high-level, configuration-based language (e.g., YAML, SQL) that specify what conditions data must meet—such as uniqueness, freshness, or referential integrity—without detailing the how of the procedural verification steps. This abstraction separates the business logic of data quality from the underlying execution engine, allowing data engineers to define rules like column_X must be non-null in a portable, version-controlled format. The data quality rule engine then interprets these declarations, executes the necessary queries or checks against the target dataset, and produces a pass/fail result, often integrated into a CI/CD for Data pipeline or a data quality gate.

The operational workflow begins when a data observability platform or scheduler triggers the test suite, typically after a data pipeline execution. The engine parses the declarative rules, which may include statistical checks (e.g., mean value within range), schema validations, or custom SQL assertions. It executes these checks efficiently, often leveraging metadata and automated data profiling to optimize queries. Results are logged, and failures generate alerts routed through a data incident triage workflow. This model promotes scalability, reusability, and clear ownership, as the intent of each test is explicitly documented in the configuration, making data quality a transparent, engineering-managed concern rather than an opaque, script-heavy process.

IMPLEMENTATION PARADIGM

Declarative vs. Imperative Data Testing

A comparison of the two primary programming paradigms for defining data quality validation rules, focusing on their core characteristics and operational impact within data observability platforms.

Feature / CharacteristicDeclarative Data TestsImperative Data Tests

Definition

Specifies what the expected data condition is (the goal) without detailing the procedural steps.

Specifies how to perform the validation through explicit, step-by-step control flow and logic.

Primary Abstraction

Configuration (e.g., YAML, JSON, domain-specific language).

General-purpose programming code (e.g., Python, Java, SQL scripts).

Implementation Example

validates_uniqueness_of: user_id or expect_column_values_to_be_between: {column: price, min_value: 0}.

A Python function with loops, conditionals, and custom exception handling to check uniqueness or value ranges.

Test Logic Location

Encapsulated within the testing framework/engine. Logic is interpreted from config.

Explicitly written by the developer within the test code itself.

Code Volume & Complexity

Low. Typically 1-5 lines per test rule.

High. Can be tens to hundreds of lines for complex business logic.

Maintainability & Readability

High. Intent is clear and separate from execution mechanics. Easier to review and audit.

Variable. Depends heavily on code quality and documentation. Logic is intertwined with control flow.

Portability & Reusability

High. Declarative rules are often engine-agnostic and can be shared across pipelines and teams.

Low. Tightly coupled to the specific execution environment and codebase.

Execution Control

Managed by the framework. Optimizations (e.g., parallel execution, query push-down) are handled automatically.

Controlled by the developer. Requires manual optimization for performance and resource management.

Integration with CI/CD & Orchestrators

Seamless. Config files are easily versioned and integrated as pipeline dependencies.

Possible but more complex. Requires managing and deploying code artifacts and their dependencies.

Learning Curve for Data Practitioners

Low. Accessible to data analysts, engineers, and stewards with domain knowledge.

High. Requires software engineering skills and knowledge of the specific programming ecosystem.

Flexibility for Edge Cases

Moderate. Limited by the expressiveness of the declarative language. May require custom SQL snippets.

Very High. Can implement any arbitrarily complex validation logic the language supports.

Typical Performance Profile

Optimized by the engine. Often translates to efficient single-pass SQL queries over the dataset.

Determined by the developer's code. Can be inefficient without careful optimization (e.g., N+1 query problems).

Primary Use Case

Standard data quality dimensions: nullness, uniqueness, referential integrity, freshness, distributional checks.

Complex, multi-step business logic validation, data reconciliation across systems, and custom anomaly detection.

VALIDATION PATTERNS

Common Examples of Declarative Data Tests

Declarative data tests define expected data conditions using configuration files (e.g., YAML, SQL). These are the most common patterns used to enforce data quality and business logic.

01

Schema and Type Validation

Ensures data adheres to expected structural formats and data types. This foundational test prevents downstream errors caused by malformed data.

  • Column Existence: Verifies a required column is present in a table.
  • Data Type Conformance: Checks that values in a column (e.g., customer_id) match the declared type (e.g., INTEGER, TIMESTAMP).
  • Nullability Constraints: Enforces whether a column can contain NULL values.

Example YAML rule: assert_column_exists: table: orders, column: order_id

02

Freshness and Latency Checks

Monitors the timeliness of data updates to ensure information is current and meets Service Level Objectives (SLOs) for delivery.

  • Maximum Allowable Delay: Asserts that the most recent record in a table is no older than a threshold (e.g., updated_at >= NOW() - INTERVAL '1 hour').
  • Ingestion Heartbeat: Validates that a pipeline has successfully written data within a scheduled window.

These tests are critical for time-sensitive use cases like dashboards and real-time analytics, directly impacting data downtime metrics.

03

Volume and Completeness Tests

Validates that data arrives in expected quantities and is not missing critical segments.

  • Row Count Boundaries: Declares that a table should have between an expected minimum and maximum number of rows after a refresh (e.g., row_count between 1000 and 5000).
  • Non-Null Completeness: Ensures a critical column has no missing values (e.g., non_null_count(email) = total_row_count).
  • Uniqueness: Asserts that values in a key column are distinct (e.g., unique_count(order_id) = total_row_count).

These tests catch pipeline breaks, incomplete loads, and duplicate generation issues.

04

Referential Integrity Tests

Enforces consistency and valid relationships between different datasets, a core principle of data reliability engineering.

  • Foreign Key Validity: Verifies that all values in a child table's column (e.g., orders.customer_id) exist in the parent table (customers.id).
  • Orphan Record Detection: Identifies records in a reference table that are no longer linked to any primary record.

Declarative SQL example: SELECT COUNT(*) FROM orders o LEFT JOIN customers c ON o.customer_id = c.id WHERE c.id IS NULL must equal 0.

05

Statistical Distribution Tests

Uses statistical methods to validate that data values fall within expected numerical ranges and distributions, often leveraging dynamic baselines.

  • Value Range: Asserts that a numeric column's values (e.g., transaction_amount) stay within a sane min/max (e.g., 0 <= value <= 1000000).
  • Average/Median Stability: Checks that aggregate metrics do not deviate beyond a percentage threshold from a rolling historical average.
  • Standard Deviation Bound: Flags if the dispersion of a column's values exceeds an expected limit, which can indicate data corruption.

These tests are proactive guards against data drift and subtle quality degradation.

06

Custom Business Logic Validation

Encodes domain-specific rules that data must satisfy to be considered accurate for business operations.

  • Calculated Field Accuracy: Validates that a derived column (e.g., total_price) correctly equals unit_price * quantity - discount for all rows.
  • State Transition Validity: Ensures status fields follow a permitted sequence (e.g., an order cannot move from shipped back to pending).
  • Cross-Table Consistency: Asserts that aggregated metrics in a summary table match the sum of granular records in a source table.

These declarative rules move critical business knowledge out of application code and into observable, version-controlled data monitoring as code.

DECLARATIVE DATA TESTS

Frequently Asked Questions

Declarative Data Tests are a core component of modern data observability, enabling automated quality validation through configuration rather than procedural code. This FAQ addresses common questions about their implementation, benefits, and role in a data quality posture.

A Declarative Data Test is a quality validation rule defined in a high-level, configuration-based language (e.g., YAML, SQL) that specifies the expected state or condition of data without detailing the procedural steps for checking it. The system's execution engine interprets the declaration to perform the validation. This contrasts with imperative testing, where the exact sequence of operations is manually coded. For example, a declarative test for a customers table might be written as column: id, test: unique or as a SQL assertion like SELECT COUNT(*) FROM customers HAVING COUNT(*) = COUNT(DISTINCT email). The test declares what the data condition should be (e.g., uniqueness, non-null, referential integrity), not how to verify it.

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.