#1306: WG New Spec: SPARQL RL

Visit on Github

Opened Nov 8, 2026

Specification

https://www.w3.org/TR/sparql-rl/

Explainer

https://w3c.github.io/data-shapes/shacl12-overview/#whatsnew

Links

An introduction to the feature, aimed at unfamiliar audiences:

This document defines SPARQL-RL, a Datalog-style rules language for RDF.

SPARQL-RL generates new RDF data by evaluating a set of declarative rules against an input RDF graph. Rules are written in a SPARQL-like text syntax.

SPARQL-RL supports negation as failure, which could lead to different inference graphs depending on the order in which rules are evaluated. To avoid this, rules are evaluated using the technique of stratification, which establishes an ordering among rules, ensuring that the same inference graph is always produced.

SPARQL-RL provides grouping and aggregation, with assignment of the aggregation function result to a variable in the body of a rule.

For information about SPARQL-RL in the context of SHACL 1.2, see SHACL 1.2 Overview's What's New in SHACL 1.2 section. In particular:

SHACL 1.2 Inference Rules defines an extension to SHACL for representing inference rules, in particular rules that can be linked to shapes. It was inspired by the SPARQL-based rules introduced by the SHACL Advanced Features and older technologies such as SPIN.

SPARQL 1.2 RL allows the representation and execution of Datalog-based rules using a SPARQL-like syntax. These have a straight-forward mapping to SPARQL CONSTRUCT statements and can be executed within a SHACL Inferencing Rules envelope, allowing for integration with other SHACL features such as node expressions.

A description of the problems that end-users were facing before this proposal:

  • inability to stratify (order) SPARQL inference statements
  • inability to ensure SPARQL inferencing run-once
  • inability to exchange RDF reasoning rules with a standard format
    • since the W3C's Rule Interchange Format (RIF) has not see wide/any adoption

Alternatives considered:

A SHACL-specific rules language which was to be a direct evolution of SHACL-AF. That has been published as SHACL 1.2 Inference Rules but it was still thought necessary, or at least useful, to publish a ruls language for RDF inference without dependence on SHACL.

A mapping to SPARQL is given in this document and, through that, integration with SHACL is achieved too.

  • Examples of how to use the proposal to solve the end-users' problems:

Encode RDF inference rules in stratified and terminating-guaranteed SPARQL-like syntax. These can be stored in .srl files and exchanged. This can replace the various custom rules languages that RDF DB vendors implement.

What do the end-users experience with this proposal:

A new specification for SPARQL rules that can be stratified (ordered, with dependence) and with execution guarantees. This lets reasoning rules be packaged and reused with much more confidence than just SPARQL files which have no ordering or execution guarantees.

User research you did to validate the problem and/or design, if any:

This specification was built on top of the previous Data Shapes WG NOTE output of SHACL Advanced Features. SHACL-AF was never made into a REC in 2017 and yet the SHACL Rules part of it was implemented by vendors and open source communities. We included implementers in this WG to try and improve on SHACL AF and this SPARQL RL specification is one output of improvement, alongside SHACL 1.2 Inference Rules.

We also consulted with SPARQL and SPARQL-like rule implementor communities such as Apache Jena, Python's RDFLib and GraphDB. All were in favor of a tightly specified datalog-style SPARQL-like rules language.

Web Platform Tests:

N/A - this is not a browser specification

The specification

Where and by whom is the work is being done?

  • GitHub repo: https://github.com/w3c/data-shapes/
  • Primary contacts:
    • Andy Seaborne (@afs), Apache Foundation, lead editor
    • David Habgood (recalcitrantsupplant), KurrawongAI, editor
    • Nicholas Car (@nicholascar), KurrawongAI, WG co-chair
  • Organization/project driving the specification:
    • Apache Foundation
    • KurrawongAI
    • GraphWise
    • Siemens
  • This work is being funded by:
    • -
  • Primary standards group developing this feature:
  • Data Shapes WG
  • Incubation and standards groups that have discussed the design:
    • RDF & SPARQL Working Group

Feedback so far

You should also know that...

No response

Discussions