Quality & Governance

This guide covers creating and managing quality rules and governance policies. You will define validation rules, attach them to data products, and monitor ongoing data quality.

Create Quality Rules

Quality rules define assertions that data must satisfy to be considered valid. Catalog rules are definitions: they run only after the producing workflow deploys a quality-rule evaluator node.

Create a quality rule that validates order amounts are positive:

loxtep quality-rules create --file ./positive-order-amount.json

Rules support comparison operators (eq, neq, gt, gte, lt, lte), pattern matching (regex), null checks (not_null), and custom expressions.

Test Rules Before Deployment

Validate the rule definition in source control and inspect the saved rule before attaching it to a live data product:

loxtep quality-rules get qr_positive_amount

The test returns which records pass and which fail, along with the specific assertion that triggered each failure. This prevents accidental data loss from overly strict rules.

Rule Severity Levels

Each rule specifies a severity that determines what happens on failure:

  • reject — the record is discarded and logged as a validation failure
  • flag — the record is ingested but flagged for manual review
  • warn — the record is ingested and an alert is emitted to monitoring

Attach Rules to Data Products

Inline validation nodes can reject or flag records in the workflow graph, but they are separate from catalog quality-rule measurement. A validation node sits between an upstream node (connection or transformation) and a downstream data product, checking every record that flows through. To measure the effective catalog rules and write a pass rate, also deploy the quality-rule node described in How rules run.

Workflow Graph Position

A typical ingestion workflow graph with validation looks like:

Connection → Transformation → Validation → Data Product

The validation node inspects each record after transformation and before it lands in the data product. Records that fail are handled according to the rule severity (reject, flag, or warn).

Adding a Validation via Graph Patch

Use patch_workflow_graph to add a validation node and connect it in the correct position:

{
  "operation": "patch_workflow_graph",
  "project_id": "proj_...",
  "workflow_id": "wf_...",
  "operations": [
    {
      "op": "add_node",
      "entity_type": "validations",
      "entity": {
        "name": "positive-order-amount",
        "validation_type": "completeness",
        "severity": "error",
        "rules": {
          "condition": "total_amount >= 0",
          "rule_type": "comparison"
        },
        "upstream_entity_id": "<transformation_id>",
        "upstream_entity_type": "transformations"
      }
    },
    {
      "op": "connect_nodes",
      "from_entity_id": "<transformation_id>",
      "to_entity_id": "<validation_id>"
    },
    {
      "op": "connect_nodes",
      "from_entity_id": "<validation_id>",
      "to_entity_id": "<data_product_id>"
    }
  ]
}

Adding a Validation Node

Include validation nodes in the workflow bundle (validations/{validation_id}.json) and save with save_workflow_bundle (dry run first):

{
  "operation": "save_workflow_bundle",
  "project_id": "proj_...",
  "dry_run": true,
  "files": {
    "workflows/wf_.../validations/val_....json": {
      "validation_id": "val_...",
      "name": "positive-order-amount",
      "validation_type": "comparison",
      "rules": { "condition": "total_amount >= 0" }
    }
  }
}

Multiple Validations

Chain multiple validation nodes in sequence for a validation pipeline. Each validation node connects to the next:

Connection → Transformation → Validation (required fields) → Validation (amount check) → Data Product

Rules execute in graph order — the first validation that rejects a record prevents it from reaching downstream nodes.

PII Governance

Identify and protect personally identifiable information across your data layer by tagging PII fields in schemas. Governance applies by default, so agents reading over the MCP server only see what they are allowed to.

Tag PII Fields

Mark schema fields that contain PII with loxtep_define:

{
  "operation": "tag_pii_fields",
  "schema_version_id": "<schema-version-uuid>",
  "field_names": ["customer_email", "shipping_address"]
}

PII tags trigger governance policies including encryption at rest, access logging, retention limits, and automatic redaction in analytics queries for unauthorized users.

Audit PII Exposure

Search the catalog for all data products exposing PII:

{ "operation": "search_catalog", "query": "*", "type": "data_product", "include_evidence": true }

Policy Writing Patterns

Freshness Rules

Ensure data products maintain acceptable freshness by defining time-based quality rules:

{
  "field": "_ingested_at",
  "operator": "age_lt",
  "value": "24h",
  "severity": "flag"
}

This flags any record older than 24 hours, surfacing stale data for investigation without blocking ingestion.

Uniqueness Constraints

Prevent duplicate records by enforcing uniqueness on key fields:

{
  "field": "order_id",
  "operator": "unique_within",
  "value": "partition",
  "severity": "reject"
}

Referential Integrity

Validate that foreign key references resolve to existing records in upstream products:

{
  "field": "customer_id",
  "operator": "exists_in",
  "value": "dp_customers.customer_id",
  "severity": "flag"
}

Monitor Data Quality

Track quality metrics across your data layer using the catalog governance view.

View Quality Scores

Check the aggregate quality score for a data product:

{ "operation": "get_quality_score", "data_product_id": "<data-product-uuid>" }

The quality score represents the percentage of records passing all attached rules over a rolling 7-day window.

Set Quality Thresholds

Configure alerts when quality scores drop below acceptable thresholds. Quality degradation often signals upstream schema changes, connector failures, or source system issues that need attention.

Live quality-rule inheritance

Catalog quality rules inherit live from Data Council → domain ancestors → product. The resolver never copies parent rows onto the product. Product rows are additions, overrides, or suppressions only.

loxtep_define → list_quality_rules takes view=owned|effective:

  • owned (default) — rows this Council, domain, or product owns.
  • effective — the live merged set for one product. Requires data_product_id.

Override or suppress an inherited rule only when that parent has allow_exceptions: true. A suppress row must set overrides_rule_id. Empty applies_to on a Council-owned rule is org-wide. Empty applies_to on a domain-owned rule is that domain's subtree, not org-wide — a domain rule cannot replace a no-exception Council gate.

Create accepts exactly one of data_product_id or domain_id. The following list request returns the live set the quality-rules promotion gate evaluates:

{
  "operation": "list_quality_rules",
  "data_product_id": "dp_...",
  "view": "effective"
}

How rules run

A catalog quality rule is a definition; creating or inheriting it does not run the rule. Live measurement requires this complete path:

Catalog rule → quality-rule node → evaluator bot → quality_metrics → pass rate

Add one quality-rules/{id}.json node for each produced data product to the workflow bundle. The node identifies the product's output through upstream_entity_id and upstream_entity_type, reads batches from that output queue, and evaluates the product's effective rules. The deployed evaluator writes quality_metrics, which supplies the rule's last-run time and pass rate. One node per product evaluates all of that product's effective rules; do not add one node per catalog rule.

Without the node, catalog and Data Council rules still count toward readiness, but they never run: the Quality tab stays at Never, and readiness reports no_quality_evaluator_deployed. Add the node in Studio or with save_workflow_bundle, deploy the workflow, send a batch through the producing workflow, and then use get_quality_score to confirm at least one measured metric. If the node is deployed but no batch has reached it yet, readiness instead reports awaiting_live_measurement.

The quality-rules promotion gate

checkQualityRules uses per-rule evidence from the effective set:

  • Each enabled, non-suppressed rule with blocks_promotion: true is compared to its own threshold (0–100).
  • Zero blocking rules satisfies the gate (not_applicable: true).
  • Blocking rules with no live measurement do not block Ready. Readiness distinguishes a missing evaluator (no_quality_evaluator_deployed: true) from a deployed evaluator that is waiting for its first batch (awaiting_live_measurement: true).
  • A measured score below that rule's threshold fails the gate.

Seeded Data Council defaults (getDefaultQualityRules / GOVERNANCE_TIERS) are starting thresholds, not a second org-wide score. Every tier's freshness window is the quality_thresholds.freshness_hours value:

TierFreshness windowSeeded rulesallow_exceptions
flexiblenullnonen/a
standard48 hourscompleteness 90, timeliness 95, uniqueness 95true
strict4 hourscompleteness 99, timeliness 95, uniqueness 99.9, accuracy 99.5false

Timeliness threshold is hardcoded 95 on both standard and strict; only the window changes (updated_at WITHIN 172800 seconds vs 14400 seconds). Flexible seeds no Council rules. See Readiness Operations.

Maintaining Data Products

Regular maintenance ensures data products remain trustworthy over time:

  • Review quality scores weekly and investigate any downward trends
  • Update rules when business requirements change (new fields, stricter thresholds)
  • Archive deprecated products to keep the catalog current
  • Audit PII tags after schema changes to ensure new fields are properly classified