---
title: "How to Test Knowledge Graph Relationship Integrity"
description: "Test knowledge graph relationship integrity with validation queries and regression tests that catch bad edges before they reach production."
url: "https://certant.ai/blog/how-to-test-knowledge-graph-relationship-integrity"
author: "Dan Voyce"
date: "2026-11-26"
tags: ["knowledge graph", "how to test knowledge graph relationship integrity", "knowledge graph validation queries", "knowledge graph relationship testing examples"]
section: "informational"
words: 2198
---

# How to Test Knowledge Graph Relationship Integrity

Test knowledge graph relationship integrity with validation queries and regression tests that catch bad edges before they reach production.

_Last Updated: 25 November 2026_

**Quick Summary**

To test knowledge graph relationship integrity, write integrity constraints as queries and run them after every build: cardinality, domain and range, referential integrity, and temporal validity. Turn competency questions into test cases with human-checked answers, then diff the results after each rebuild.

- A knowledge graph relationship is a typed edge with a direction, a label and its own properties.
- A constraint you cannot express as a query is a wish, not a test.
- One SQL query can catch orphan edges and temporal contradictions together.
- Add a known-false relationship and confirm the graph does not assert it.
- Set thresholds per relationship type rather than one global number.

**Can you prove every edge in your graph?**Certant Strata builds and monitors your knowledge graph, with every figure traced to its source page.

[Test your graph](https://certant.ai)

## Table of Contents

- What a Knowledge Graph Relationship Actually Is
  - Nodes, Edges and Properties
  - Why Edges Fail More Often Than Entities
- Knowledge Graph Integrity Constraints You Can Enforce
- Writing Knowledge Graph Validation Queries That Catch Bad Edges

## What a Knowledge Graph Relationship Actually Is

A knowledge graph relationship is a typed link between two entities, stored as an edge with a direction, a label and its own properties. Testing relationship integrity means checking that every edge in the graph is supported by evidence, points at the right entities, and still holds after the data is rebuilt.

[Certant.ai - Whitelabel AI Platform](https://www.youtube.com/embed/HXqcDzHO_aM?rel=0&modestbranding=1)

#### [Certant.ai - Whitelabel AI Platform](https://www.youtube.com/watch?v=HXqcDzHO_aM)

Dan V

Most teams test the nodes and trust the edges. That is backwards. A wrong entity is easy to spot in a search result. A wrong edge sits quietly between two correct entities and poisons every answer that walks across it. This guide covers how to test the relationships inside one.

### Nodes, Edges and Properties

A node is a thing: a member, a contract, an invoice, a site. An edge is the link between two of them, such as "contract signed by member" or "invoice raised against contract". A property is a fact attached to either, like a start date or a pay rate.

The graph model matters more than the schema document. Two graphs can share an identical schema and still disagree about which member signed which contract.

### Why Edges Fail More Often Than Entities

Entity extraction gets the attention. Edge extraction is where the errors hide.

- A PDF table splits across two pages and the link lands on the wrong row.
- Two people share a name, so entity resolution joins the wrong records.
- A contract references an old site code that no longer exists.
- A date range on an edge contradicts the date range on the node at either end.

Each of those produces a graph that looks complete and answers questions incorrectly.

## Knowledge Graph Integrity Constraints You Can Enforce

Integrity constraints are the rules a graph must satisfy before you trust a query against it. Write them down, run them after every build, and treat a failure as a blocker.

The constraints that catch the most bad edges fall into four groups:

- **Cardinality:** one invoice belongs to exactly one contract. Two parents means a bad edge.
- **Domain and range:** a "signed by" edge must start at a contract and end at a person, not at a site.
- **Referential integrity:** every edge endpoint must exist as a node. Orphans are silent killers.
- **Temporal validity:** an edge's dates must sit inside the dates of the nodes it connects.

A constraint you cannot express as a query is a wish, not a test. If your graph tool cannot run the check, that is a reason to change the tool. Our own [step-by-step guide to auditing AI knowledge graphs](https://certant.ai/blog/how-to-audit-ai-knowledge-graphs) walks through where these constraints sit in a wider audit.

The constraints that catch the most bad edges fall into four groups.

| Constraint | What it checks | Example of a failure |
|---|---|---|
| Cardinality | One invoice belongs to exactly one contract | Two parents means a bad edge |
| Domain and range | A "signed by" edge starts at a contract and ends at a person | Edge ending at a site |
| Referential integrity | Every edge endpoint exists as a node | Orphan edges |
| Temporal validity | An edge's dates sit inside the dates of the nodes it connects | Dates contradict the nodes at either end |

## Writing Knowledge Graph Validation Queries That Catch Bad Edges

A validation query is a check written against the graph itself, returning the edges that break a rule. The output should be a list of offending edges with enough detail to trace each one back to its source.

Here is the shape we use. It is plain SQL against an edge table, which is how we ended up running these checks after [replacing a graph extension with direct SQL](https://certant.ai/blog/graph-retrieval-was-70x-slower-than-it-needed-to-be) to get lookups under a second.

```sql
SELECT e.id, e.from_id, e.to_id, e.rel_type
FROM edges e
LEFT JOIN nodes n1 ON n1.id = e.from_id
LEFT JOIN nodes n2 ON n2.id = e.to_id
WHERE n1.id IS NULL
   OR n2.id IS NULL
   OR e.valid_from > n1.valid_to
   OR e.valid_to < n2.valid_from;
That single query catches orphans and temporal contradictions together. Add one query per constraint, keep them in version control, and run the set as a suite.

### Competency Questions as Test Cases

A competency question is a question the graph must be able to answer, written before the graph is built. "Which contracts expire this quarter and who signed them?" is a competency question. So is "which sites have no current monitoring reading?"

Turn each one into a test case with a known correct answer from a human-checked source. If the graph's answer differs, you have found either a missing relationship or an unsupported one. 

## Knowledge Graph Relationship Testing Examples

Data analyst examining a knowledge graph network and query editor on dual monitors in a bright office

Take a worked example. A member record links to three contracts, two of which overlap in date. The cardinality test flags it. The fix is not to delete an edge but to check the source documents, because the overlap usually means one contract was superseded and the old edge was never retired.

Three more tests we run on every graph:

- **Negative edges:** add a known-false relationship and confirm the graph does not assert it.
- **Missing relationships:** take a node you know has a parent and confirm the edge exists.
- **Supporting path:** for any answer the graph gives, confirm a path exists from the question's entities to the answer's entities.

That last one is the test that matters most for AI answers. A grounded answer with a supporting path can be checked. An answer without one is a guess with good grammar.

## Knowledge Graph Regression Testing After Every Rebuild

Regression testing is the practice of re-running your full validation suite after each rebuild and comparing the results to the last run. A graph that passed on Monday and fails on Friday has a change you need to explain.

Store three things per run: the constraint results, the count of edges by type, and the output of every competency question. Diff them. A drop in edge count for one relationship type usually means a parser change broke a table extraction. A rise means something new got promoted without review.

Set thresholds per relationship type rather than one global number. Precision on a high-stakes edge like "invoice paid against contract" deserves a tighter bar than a soft link like "document mentions site". Track provenance coverage too: the share of edges whose source page you can point to.

## How Certant Strata Builds and Monitors Relationship Integrity

This is where the test suite meets a product that runs it. Certant Strata builds an ontology of your business from the sources you already have. An ontology, in plain words, is a working model of the business: the object types, their properties, and the links between them.

Strata reads documents and the tables inside PDFs, spreadsheets, SharePoint, Xero and iMIS, and proposes the model. The owner reviews it, and corrections made in plain English are kept and reapplied on every rebuild. That review step is the first integrity check, because proposed links wait for approval before anything uses them.

From there the loop is:

1. Connect sources and map them into the model.
2. Build the ontology and resolve the same person or organisation across sources.
3. Ask questions, with the query shown and every figure traced to its table and page.
4. Monitor rules that compare one object with another, such as a pay rate against the award minimum for that classification.
5. See which records an alert affects and how many, computed from the data.
6. Approve the action, with a reason and a risk tier, and write it back to the system of record.

You can see what the build produces on the [one model page](/strata/model), and how a broken relationship turns into an alert that counts the customers and orders it reaches on the [monitoring page](/strata/alerts). Strata declines to answer when the data cannot support one, which is the behaviour you want from a graph you are testing.

Agencies and integrators can white-label the same platform and deliver this to their own clients under their own brand.

## Put Your Own Graph Through the Test Suite

Start with one problem and one set of sources. Get the ontology right for those, then add monitors and actions. Do not try to model the whole business on day one.

Four things to do this week:

- Write five competency questions with human-checked answers.
- Turn each integrity constraint into a query and put the queries in version control.
- Run the suite, save the results, and rebuild to see what changes.
- Test on your worst document, not the clean sample.

When you are ready to run a graph on your own hardware or cloud account, the [sovereign deployment page](/on-premise-knowledge-graph) covers how that works. Then take the next step on [certant.ai](https://certant.ai) and start free.

---

A graph you cannot test is a graph you cannot defend to an auditor. Certant Strata builds the ontology from your existing sources, monitors the relationships inside it, and traces every figure back to the page it came from. It runs air-gapped on hardware you own, with row rules, history and an audit trail on every agent. Get started with Certant and put your relationships through a suite that holds up.

<section style="margin:3rem 0 2rem 0;" itemscope itemtype="https://schema.org/FAQPage"><h2 style="font-weight:700; margin:0 0 4px 0;">Frequently Asked Questions</h2><div style="padding:20px 0; border-bottom:1px solid #e5e7eb;" itemscope itemprop="mainEntity" itemtype="https://schema.org/Question"><h3 style="font-weight:600; margin:0 0 8px 0;" itemprop="name">How do you test whether two entities in a knowledge graph are linked correctly?</h3><div style="line-height:1.7;" itemscope itemprop="acceptedAnswer" itemtype="https://schema.org/Answer"><p itemprop="text" style="margin:0;">Pull the edge and check its provenance first. Every relationship should point back to the table, page or field that justified it, so you can open the source and confirm the link by hand. Then run a query that asks for the supporting path between the two entities. If the graph can only reach one from the other through a chain of guesses, the edge is weak. Spot-check a sample of edges per relationship type rather than every edge, and keep the sample fixed so you can compare results across rebuilds.</p></div></div><div style="padding:20px 0; border-bottom:1px solid #e5e7eb;" itemscope itemprop="mainEntity" itemtype="https://schema.org/Question"><h3 style="font-weight:600; margin:0 0 8px 0;" itemprop="name">What does relationship integrity mean in a knowledge graph?</h3><div style="line-height:1.7;" itemscope itemprop="acceptedAnswer" itemtype="https://schema.org/Answer"><p itemprop="text" style="margin:0;">It means every edge is supported by evidence, points at the right entities, and does not contradict another edge or property in the graph. Three things break it: an edge with no source, an edge between the wrong pair (entity resolution failure), and an edge that conflicts with a constraint you have defined, such as a contract linked to two different start dates. Integrity is a property of the edges, not the nodes, which is why testing entity counts alone tells you very little.</p></div></div><div style="padding:20px 0; border-bottom:1px solid #e5e7eb;" itemscope itemprop="mainEntity" itemtype="https://schema.org/Question"><h3 style="font-weight:600; margin:0 0 8px 0;" itemprop="name">How often should you check knowledge graph relationship integrity?</h3><div style="line-height:1.7;" itemscope itemprop="acceptedAnswer" itemtype="https://schema.org/Answer"><p itemprop="text" style="margin:0;">Run the full suite on every rebuild or re-ingestion, because extraction changes can quietly alter edges. Run the cheap constraint checks (orphan edges, missing required links, duplicate relationships) on a schedule, daily if the graph is fed by change streams. Keep a fixed set of regression tests and compare pass rates between runs so you notice drift. If a monitor can watch a rule continuously, use it, and let the alert tell you which records are affected and how many.</p></div></div><div style="padding:20px 0; border-bottom:1px solid #e5e7eb;" itemscope itemprop="mainEntity" itemtype="https://schema.org/Question"><h3 style="font-weight:600; margin:0 0 8px 0;" itemprop="name">How do you find missing or invalid edges in a knowledge graph?</h3><div style="line-height:1.7;" itemscope itemprop="acceptedAnswer" itemtype="https://schema.org/Answer"><p itemprop="text" style="margin:0;">Missing edges are harder than invalid ones because there is no row to inspect. Start from constraints: if every invoice must link to a contract, query for invoices with no such edge and you have your candidates. For invalid edges, check type compatibility and cardinality, then check provenance. Negative edges help too, meaning pairs you know should not be linked. Sample those and confirm the graph agrees. A worked example: query for pay rates with no link to an award classification, then check the source agreement page for each.</p></div></div></section>
```

[![Google](https://app.grandranker.com/images/google-g.svg)Add **certant.ai** as a preferred source on Google →](https://www.google.com/preferences/source?q=certant.ai)

[Video](https://www.youtube-nocookie.com/embed/HXqcDzHO_aM)
