· Updated

Business Rules, Data Tests, and Ontology Reasoning Are Different Tools

By Arshad Ansari

These are three different tools, and they answer three different questions.

  • A transactional invariant asks: may this write happen?
  • A pipeline test asks: is this batch of data fit to use?
  • Ontology reasoning asks: what else must be true, given what we know?

Teams mix them up because all three get called "business rules". Then a rule lands in the wrong layer. It fails late, or it never fails at all.

Transactional invariants: refuse the write

An invariant is a statement that must hold at every moment. An account balance cannot go below zero. An order total equals the sum of its lines. A payment cannot point to an invoice that does not exist.

The right place is the system that takes the write. That means database constraints, foreign keys, and transactions. The check runs before the data is stored, and a violation rejects the write. Bad data never enters.

Two properties matter here:

  • It is synchronous. The caller finds out now, and can fix it or give up.
  • It sees the whole truth. The database knows the current state, so it can say no with certainty.

If a rule must never be broken, put it here. A test that runs tonight is too late for it.

Pipeline validation: judge the batch

Data that arrives from outside your control cannot be refused at the door. Files, exports, API pulls and vendor feeds show up as they are. You find out what is wrong after you have it.

This is the job of data tests in a pipeline: not null, unique, accepted values, row counts, freshness, and relationships between tables. They run on a batch, after load or before publish.

The outcome is a decision about the batch, not about a single write. You fail the run, quarantine the bad rows, or pass with a warning. The test does not fix anything and does not know why the data is wrong. It tells you that it is.

The common mistake is to rely on this layer for a rule that should have been an invariant. If your own application writes the data, a nightly test only tells you that the damage already happened.

Ontology reasoning: derive what follows

A reasoner is a different kind of tool. It does not guard anything. It takes facts and rules about the world and works out further facts.

Say your model states that every Supplier is an Organisation, and that suppliesTo links a supplier to a customer. If a record says Acme suppliesTo Globex, the reasoner can conclude that Acme is a Supplier and an Organisation, without anyone writing that down. Transitive properties, subclass hierarchies and property domains and ranges all work this way.

This is what OWL is for. It is useful when meaning is spread across many sources, and you want queries to see facts that no single source states.

One property of OWL catches people out: it assumes an open world. If a fact is absent, OWL treats it as unknown, not false. So if you declare that every order has at least one line, and an order has none, a reasoner does not report an error. It concludes that a line exists somewhere that you have not listed.

That is correct behaviour for inference. It is the wrong behaviour for validation.

Where SHACL fits

SHACL covers the validation job for graph data. You describe a shape: an order needs at least one line, a date must be a date, a supplier needs exactly one tax ID. SHACL then checks the graph against the shape and reports each violation.

In plain terms, SHACL is to an RDF graph what a data test is to a table. It judges data that already exists, and it reports. It does not infer, and it does not block a write unless you build that around it.

So the split inside the graph world is:

  • OWL to derive new facts.
  • SHACL to check that the facts you have are complete and well formed.

Using OWL where you wanted SHACL is the most common error I see. The model looks strict, and nothing ever fails.

A quick way to choose

If the rule says...It isPut it in
This must never be storedInvariantDatabase constraints and transactions
This batch looks wrongValidationPipeline tests, or SHACL on a graph
This must also be trueInferenceAn OWL reasoner, or a plain view or query

The last row has a plain alternative. Much of what people want from reasoning, such as "every supplier is an organisation", can be a view or a join. A reasoner earns its place only when the rules are many, shared across sources, and change often enough that hand-written joins become the problem.

Who this is not for

If you have one database and a modest number of tables, you need constraints and tests. You do not need a reasoner. Do not hire me to build an ontology for its own sake. I would tell you to start with the first two layers and add the third only when a real question needs it.

Check your own platform

A useful first step is to list the rules you rely on and ask of each one: is this an invariant, a validation, or an inference? Then check that it lives in the matching layer. The free Data Platform Teardown is a checklist you can run yourself on your own platform.

Common questions

Is SHACL a replacement for data tests?
For RDF graphs, yes. SHACL checks a graph against shapes and reports violations, which is the same job a data test does on a table. If your data is in tables, you do not need SHACL.
Can OWL reject bad data?
Not by design. OWL reasoning works under an open-world assumption. A missing fact is unknown, not false, so a reasoner infers new facts instead of rejecting records. Use SHACL when you want a failed check.
Do I need an ontology reasoner to enforce business rules?
No. Most business rules that must never be broken belong in the database as constraints and transactions. A reasoner is for deriving new facts, not for guarding writes.

Get new posts by email

Data engineering notes like this one — what breaks and what it costs, in production.

What breaks and what it costs — pipelines, warehouse bills, and the failures that only show up in production. A few a month, never padded to hit a schedule. No sequence, no pitch deck. Reply 'stop' once and you're off — it reaches me, not a queue.

Want the whole playbook?

If this was useful, the long version is my book. Local-First Analytics — 313 pages, runnable code for every chapter — is the full build: DuckDB, Parquet and Arrow, from install to production. On Amazon, and chapter 1 is free to read here.

Not ready to buy? Read chapter 1 free — the whole chapter, no email required.

Rather talk it through? Book a free 30-minute call. No slot that suits your time zone? Email info@hikmahtech.in.