Mehdi Akiki
Published on

Validating a Knowledge Graph at Its Product Boundary

Authors
  • Mehdi Akiki avatar
    Name
    Mehdi Akiki
    Twitter

Reference

A knowledge graph can be logically meaningful and still unusable by the product consuming it.

The product may require every account to have one canonical identifier, a supported state, and a country code. RDF's open-world model does not make absence prove falsity, and an ontology is not automatically an input-validation schema.

I add explicit shapes at the product boundary.

Ontology and boundary validation answer different questions

An ontology can say:

PremiumAccount is a subclass of Account
ownsAccount relates a Customer to an Account

The product boundary may need:

every imported Account has exactly one canonical ID
state is one of active, held, closed
closedAt exists when state is closed
provider reference is unique inside a provider scope

These constraints express what this application accepts now. They do not redefine universal truth.

SHACL gives the boundary a concrete language

The W3C Shapes Constraint Language validates a data graph against a shapes graph and returns a validation report.

A compact shape can be:

ex:AccountShape
    a sh:NodeShape ;
    sh:targetClass ex:Account ;
    sh:property [
        sh:path ex:canonicalId ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:datatype xsd:string ;
    ] ;
    sh:property [
        sh:path ex:state ;
        sh:minCount 1 ;
        sh:in (ex:active ex:held ex:closed) ;
    ] .

The shape identifies focus nodes and produces machine-readable results with paths, values, source constraints, severities, and messages.

Validate at named boundaries

“The graph is valid” is too broad. I name the operation:

provider import candidate
canonical write
public API projection
search-index projection
analytics export

Each boundary can have a different shapes graph. An import may accept incomplete candidates into quarantine, while the canonical product graph requires stronger invariants.

This prevents one giant validation policy from either rejecting useful raw evidence or accepting weak canonical data.

Closed shapes need care

SHACL can reject properties not listed by a closed shape. This is useful for strict API payloads and risky for an extensible RDF graph.

A new harmless property can make an older closed consumer reject the node. I use closed shapes only where the product truly owns the complete representation, and I list ignored RDF vocabulary such as rdf:type when needed.

For integration boundaries, I usually validate required known properties while tolerating additional statements that remain governed elsewhere.

Cross-property rules express state

Cardinality and datatype are not enough. A closed account may require closedAt, while an active one must not have it.

I express conditional constraints with SHACL logical components or a focused SPARQL constraint when Core cannot state the rule clearly.

The validation result uses a stable reason code in addition to human text:

ACCOUNT_CLOSED_AT_MISSING
focus node: account/17
path: closedAt
shape version: product-account-shapes/6
severity: violation

Stable codes support metrics and repair queues; messages support people.

Severity is a product decision

I classify shape results:

violation: reject or quarantine the write
warning: accept but create bounded repair work
info: measure a future migration requirement

Not every data-quality preference should stop production. Not every security invariant should be downgraded to a warning to keep a dashboard green.

The mapping from SHACL severity to product action is versioned and tested.

Validate affected neighbourhoods, not random fragments

Validating only the new triples can miss a maximum cardinality violation created beside an existing value. Validating the whole graph after every write may be too expensive.

I derive an affected set:

changed subjects
objects whose inverse constraints are affected
nodes reached by paths used in relevant shapes
identity-equivalent nodes when canonicalization applies

For high-risk writes, validation happens in the same transactional boundary as activation or against an immutable candidate graph before an atomic swap.

A later asynchronous validator is useful for repair, but it cannot protect a decision already made from invalid data.

Open-world inference changes what is visible

A shape may target or validate inferred types and properties depending on the processor and entailment setup.

I record:

data graph version
shapes graph version
ontology/import closure version
entailment regime
validator implementation version

Otherwise the same stored triples can produce a different validation result after an ontology or reasoner update.

Reports need privacy boundaries

Validation reports may include the failing value. That value can be a personal identifier or secret.

In ordinary logs I keep:

shape and constraint code
opaque focus-node ID
path
severity
value datatype and bounded metadata
trace and import IDs

The full report goes to a protected repair store with its retention policy. I do not make a knowledge graph easier to query by leaking its rejected values into observability.

My boundary test

I create graph fixtures for:

  • missing required identity;
  • duplicate identity values;
  • unsupported state;
  • conditional property missing;
  • extra harmless property;
  • inferred type that activates another shape;
  • update that conflicts with an existing triple;
  • two simultaneous individually-valid writes that become invalid together;
  • malformed shapes graph;
  • validator resource exhaustion.

I assert the product action, report code, and activated graph version. A validator failure is not the same as “data conforms”; high-risk boundaries fail closed.

Keep shapes beside product decisions

Shapes are executable product contracts. I review them with the application code that depends on them, version them, and test old data against new versions before rollout.

Migrating an Ontology Without Rewriting Reality in Place covers the next problem: changing the vocabulary while old assertions and readers still exist.

An ontology helps a system reason about meaning. Boundary shapes say what one product can safely consume. Keeping both roles explicit makes a graph flexible without making production behaviour vague.