Why should you believe your reasoner?
Ask an RDFS reasoner whether Tom is a mammal and it will answer. It will not tell you why you should believe it.
A reasoner is a large program. It has an optimizer, an index, a rule engine and years of fixes. Any of them can contain a bug, and a bug in a reasoner does not crash. It quietly gives you a wrong triple.
That matters more now than it used to. Knowledge graphs feed agent memory, retrieval and decisions. When a model or an agent acts on an inferred fact, “the reasoner said so” is a weak reason.
LeanRDF is my answer to that problem. It is a Lean 4 library for RDF and RDFS in which an inferred fact can come with a proof that a computer has checked.
What “entails” actually means
The W3C does not define RDFS by a list of rules. It defines it by meaning.
An interpretation is a possible world. It says which things exist, which IRI names which thing, and which pairs of things each property relates. A graph is true in an interpretation when every triple in it holds there. Blank nodes are “some thing”: the graph is true if some choice of things for them makes every triple hold.
An RDFS interpretation is one that also respects the RDFS vocabulary. If A is a subclass of B, everything in A is in B. If a property has a domain, everything it starts from is in that class.
Then comes the key definition. Graph g entails graph q when q is true in every RDFS interpretation in which g is true.
This is a clean definition, but it is not something you can run. There are infinitely many interpretations, and you cannot check them all. Rules exist to bridge that gap.
Elpi finds, Lean checks
LeanRDF splits the work in two.
- 1.
The search side, not trusted. Elpi, a λProlog engine that runs inside Lean, computes the RDFS closure of your graph using 67 rules. It records which rule produced each new triple and from which premises.
- 2.
The checking side, trusted. A small checker written in Lean replays that record. Lean has proven, once and for all, that whatever this checker accepts is entailed in the W3C sense.
The search side can be clever, fast, buggy or swapped for another engine. None of that touches correctness. The worst a bad search can do is produce a certificate the checker rejects.
What “certified” means
A certified answer is an answer that comes with a certificate, which a verified checker has accepted.
Here is a real one. The data is a small pet ontology with 11 triples. The question is: “Is there a person who has a pet that is a mammal?” The person and the pet are blank nodes, so the query asks whether such things exist.
$ lake exe leanrdf-demo examples/pets.nt examples/query-mammal-owner.nt
LeanRDF: 11 data triples, 3 query triples
Elpi closure under 67 rules: 201 triples
Query instance: _:owner ↦ <http://example.org/bob>
Query instance: _:pet ↦ <http://example.org/tom>
Certificate: 6 nodes, goals [1, 4, 5]
[0] Cat rdfs:subClassOf Mammal (fact)
[1] bob hasPet tom (fact)
[2] hasPet rdfs:domain Person (fact)
[3] tom rdf:type Cat (fact)
[4] bob rdf:type Person (rdfs2 [2, 1])
[5] tom rdf:type Mammal (rdfs9 [0, 3])
Verdict: ENTAILED. The certificate was accepted by the verified checker (compiled).Elpi derived 190 new triples. The certificate keeps only the 6 that the answer needs. Each step is either a fact from your graph or names a rule and the earlier steps it uses. Step 4 says: hasPet has domain Person, and bob hasPet tom, so by rule rdfs2 bob is a Person.
The checker accepts a certificate only if all of these hold:
Every fact really is in the graph.
Every rule name is one of the 67 known rules.
Every premise points to an earlier step, so there are no cycles.
Each conclusion is exactly what the named rule gives from those premises.
Side conditions hold. For example, a container rule fires only on real rdf:_1, rdf:_2 style IRIs.
The query, with its blank nodes mapped (owner to bob, pet to tom), is among the proven steps.
The guarantee comes from a chain of proofs, each checked by Lean’s kernel:
- 1.
Each of the 67 rules is sound: in every RDFS interpretation, if its premises hold, so does its conclusion.
- 2.
Therefore any derivation built from those rules is sound.
- 3.
The checker is proven correct: if it accepts a certificate, a derivation exists.
- 4.
The query step is proven too: an accepted certificate for q means g entails q.
In Lean, the whole pipeline ends in one line:
theorem g_entails_q : g.RDFSEntails q :=
checkQueryB_sound (c := cert) (by native_decide)That is what “certified” means. The answer is not “our engine thinks so”. It is a theorem that q holds in every RDFS world where your data holds.
And a certificate is portable. It is plain JSON. Any engine can produce one, whether Elpi, a Datalog engine or an LLM that wrote it out by hand, and the same checker decides. LeanRDF can also export it to the CertifyingDatalog format from TU Dresden.
What “certified” does not mean
A proof is only as good as what it rests on, so here is the honest list.
The definitions. The theorem talks about RDFS interpretations as I wrote them in Lean. I transcribed the W3C conditions one field per condition, and every place where I simplified is documented. But a mistake in a definition would make the theorem prove the wrong thing.
The parser. The theorem is about the graph as parsed. The N-Triples and Turtle parsers pass all W3C tests (70/70 and 313/313), but they are tested, not proven.
The tools. Lean’s kernel checks every proof. Running the checker as compiled code, as the demo and
native_decidedo, also trusts the Lean compiler. The library itself uses nosorryand only Lean’s three standard axioms:propext,Quot.soundandClassical.choice.“Not found” is not “false”. If Elpi finds no derivation, LeanRDF says “not derived”, never “not entailed”. Completeness is not proven. To show that something is not entailed, you need a countermodel.
No value reasoning. Literals are compared as written, so “01” and “1” as integers are different terms.
Proving the semantics is not empty
There is a classic trap in formal work. If your definition of an RDFS interpretation were contradictory, no interpretation would exist. Then every graph would entail everything, and every certificate would be “true” for a silly reason.
LeanRDF closes that hole with proofs in the other direction. It builds a concrete RDFS interpretation, which shows that one exists. It also builds countermodels: worlds where the data holds and the query fails. Three non-entailments are proven this way, also checked by the kernel. So the semantics is neither empty nor trivial.
What is in the library
A native RDF 1.1 data model: IRIs, blank nodes, literals that cannot be malformed, and graphs. No FFI and no dependencies.
N-Triples and Turtle parsers, with line and column in every error and RFC 3986 IRI resolution.
The model theory of RDF 1.1: simple, D-, RDF and RDFS interpretations, and the entailment relation for each.
67 RDFS rules and axiomatic triples as data, each with a soundness proof.
Certificates in JSON, a verified checker, and a demo executable.
The site has a ten-chapter mini-book that works through all of this in order, from triples to interpretations, rules, countermodels, Elpi and certificates. It also has worked examples you can paste into Lean.
Try it
git clone https://github.com/Volland/rdf-lean
cd rdf-lean/elpi
lake exe leanrdf-demo examples/pets.nt examples/query-mammal-owner.ntSite, book and examples: https://volland.github.io/rdf-lean/
Code: https://github.com/Volland/rdf-lean
What comes next
RDFS is the foundation, not the goal. The same pattern of untrusted search plus a verified checker is the plan for the next layers: OWL EL and ALC, SHACL validation, and SPARQL rewriting. Each will reuse the certificate machinery built here.
If knowledge graphs are going to be the memory of AI systems, their inferences should be things we can check, not things we have to trust.
Originally published on Sovereign Agentic AI on Substack.