SHACL 1.2 Inference Rules

W3C Working Draft

More details about this document
This version:
https://www.w3.org/TR/2026/WD-shacl12-inference-rules-20261119/
Latest published version:
https://www.w3.org/TR/shacl12-inference-rules/
Latest editor's draft:
https://w3c.github.io/data-shapes/shacl12-inference-rules/
History:
https://www.w3.org/standards/history/shacl12-inference-rules/
Commit history
Test suite:
https://github.com/w3c/data-shapes/tree/gh-pages/shacl12-test-suite
Editors:
(TopQuadrant, Inc.)
(Corning)
(JPMorgan Chase & Co.)
(Swansea University)
Simon Steyskal (Siemens AG)
Feedback:
GitHub w3c/data-shapes (pull requests, new issue, open issues)
public-shacl@w3.org with subject line [shacl12-inference-rules] (archives)

Abstract

This document defines the Inference Rules support of SHACL, the Shapes Constraint Language. While the Core part of SHACL focuses on the basic syntax of shapes and constraint validation of data graphs, the SHACL Inference Rules cover features that can be used to infer new triples from existing triples in the data graph.

Status of This Document

This section describes the status of this document at the time of its publication. A list of current W3C publications and the latest revision of this technical report can be found in the W3C standards and drafts index.

This document was published by the Data Shapes Working Group as a Working Draft using the Recommendation track.

Publication as a Working Draft does not imply endorsement by W3C and its Members.

This is a draft document and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to cite this document as other than a work in progress.

This document was produced by a group operating under the W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent that the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

This document is governed by the 18 August 2025 W3C Process Document.

SHACL Specifications

This specification is part of the SHACL 1.2 family of specifications. See the SHACL 1.2 Overview for a more detailed introduction to them.

The specifications are as follows:

Working Drafts:

SHACL 1.2 Core
defines the Core of SHACL
SHACL 1.2 Node Expressions
defines expressions used to derive focus nodes and value nodes in SHACL
SHACL 1.2 SPARQL-Related Features
defines SPARQL-related extensions of SHACL
SHACL 1.2 Inference Rules
defines SHACL's framework of rule-based inference
SHACL 1.2 Profiling
defines the use of SHACL for profiling data, including SHACL data
SHACL 1.2 User Interfaces
defines SHACL's use for User Interface generation
SPARQL 1.2 RL
defines a Datalog-style rules language for RDF that can be used with SHACL 1.2 Inference Rules

Editor's Drafts:

SHACL 1.2 Overview
overviews the set of SHACL specifications
SHACL 1.2 Compact Syntax
defines an RDF syntax for expressing SHACL concepts
Note

Implementers can partially check their level of conformance with the above specifications by testing themselves with the test cases each presents, linked to in their metadata. Note, however, that passing all the tests in a test suite does not imply complete conformance to the specifications, it only implies that the implementation conforms to the aspects tested by the test suite.

1. Introduction

This document specifies the Inference Rules support of the Shapes Constraint Language (SHACL).

1.1 Terminology

Throughout this document, the following terminology is used.

The SHACL inference rules defined in this document are sometimes simply called SHACL rules or even rules. SHACL SPARQL rules are sometimes simply called SPARQL rules.

Note

Inference rules should not be confused with constraints. Constraints define conditions that a data graph should conform to, while rules define how additional (implicit) statements can be derived/inferred from the statements that are explicitly asserted in a data graph.

Terminology that is linked to portions of RDF 1.2 Concepts and Abstract Syntax is used in SHACL Inference Rules as defined there. Terminology that is linked to portions of other SHACL 1.2 documents is used in SHACL Inference Rules as defined there. A single linkage is sufficient to provide a definition for all occurrences of a particular term in this document.

Definitions are complete within this document, i.e., if there is no rule to make some situation true in this document then the situation is false.

Basic RDF Terminology
This document uses the terms RDF graph, RDF triple, IRI, literal, blank node, node of an RDF graph, datatype, reifier, triple annotation, RDF term, and subject, predicate, and object of RDF triples as defined in RDF 1.2 Concepts and Abstract Syntax [rdf12-concepts].
Basic SHACL-SPARQL Terminology
This document uses the terms binding, pre-binding, as defined in the SHACL 1.2 SPARQL specification [shacl12-sparql].

1.2 Document Conventions

The syntax of SHACL is RDF. The examples in this document use Turtle [rdf12-turtle]. Other RDF serializations such as RDF/XML may be used in practice. The reader should be familiar with basic RDF concepts [rdf12-concepts] such as triples and with SPARQL [sparql12-query].

Within this document, the following namespace prefix bindings are used:

Prefix Namespace
owl: http://www.w3.org/2002/07/owl#
rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
rdfs: http://www.w3.org/2000/01/rdf-schema#
sh: http://www.w3.org/ns/shacl#
shnex: http://www.w3.org/ns/shacl-node-expr#
sparql: http://www.w3.org/ns/sparql#
xsd: http://www.w3.org/2001/XMLSchema#
ex: http://example.com/ns#

Within this document, the following JSON-LD context is used:

{
  "@context": {
    "owl": "http://www.w3.org/2002/07/owl#",
    "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
    "sh": "http://www.w3.org/ns/shacl#",
    "shnex": "http://www.w3.org/ns/shacl-node-expr#",
    "sparql": "http://www.w3.org/ns/sparql#",
    "xsd": "http://www.w3.org/2001/XMLSchema#",
    "ex": "http://example.com/ns#"
  }
}

Note that the URI of the graph defining the SHACL vocabulary itself is equivalent to the namespace above, i.e. it includes the #. References to the SHACL vocabulary, e.g. via owl:imports should include the #.

Throughout the document, color-coded boxes containing RDF graphs in Turtle will appear. These fragments of Turtle documents use the prefix bindings given above.

Grey boxes such as this include syntax rules that apply to the shapes graph.

SPARQL variables using the $ marker represent external bindings that are pre-bound in the SPARQL query before execution.

true denotes the RDF term "true"^^xsd:boolean. false denotes the RDF term "false"^^xsd:boolean.

1.3 Conformance

As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.

The key words MAY, MUST, MUST NOT, and SHOULD in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.

This document defines the SHACL Inference Rules framework that extends SHACL Core. This specification describes conformance criteria for:

Also see the discussion of well-formedness in the Conformance section of SHACL Core.

2. Getting Started with SHACL Inference Rules

SHACL defines an RDF vocabulary to describe shapes - collections of constraints that apply to a set of nodes. Shapes can be associated with nodes using a flexible target mechanism, e.g. for all instances of a class. One focus area of SHACL is data validation. However, the same principles of describing data patterns in shapes can also be exploited for other purposes. SHACL rules build on SHACL to form a light-weight RDF vocabulary for the exchange of rules that can be used to derive inferred RDF triples from existing asserted triples.

The SHACL rules feature defined in this document includes a general framework using properties such as sh:rule and sh:condition, plus an extension mechanism for specific rule types. This document defines two such rule types: SHACL SPARQL rules and triple rules. This document also defines a declarative mechanism for SPARQL rule templates.

2.1 An Example SPARQL Rule

This section is non-normative.

The following example illustrates a simple use case of a SPARQL rule that applies to all instances of the class ex:Rectangle and computes the values of the ex:area property by multiplying the rectangle's width and height:

An engine that is capable of executing such rules uses the target statements associated with the shapes in the shapes graph to determine which rules need to be executed on which target nodes. For those target nodes that conform to all condition shapes, it executes the provided CONSTRUCT queries to produce the inferred triples. During the execution of the query, the variable this has the current focus node as pre-bound variable.

For the following data graph, the triples below would be produced.

2.2 An Example Triple Rule

This section is non-normative.

In addition to SPARQL-based inference rules, this document introduces triple rules. These rules rely on node expressions instead of SPARQL queries to compute the inferred triples. Here is the same scenario as the previous example, using a triple rule.

3. Syntax of SHACL Rules

The SHACL instances of sh:Rule, including its subclasses sh:SPARQLRule and sh:TripleRule, are called SHACL rules. SHACL has a flexible, extensible design in which multiple types of rules can be supported, but this document only defines two of them (SPARQL rules and triple rules) and a mechanism to declare SPARQL rule templates.

Each SHACL rule has at least one rdf:type which is an IRI.

3.1 Rule Types

A rule type is identified by an IRI. Each rule type defines execution instructions that can be implemented by rule engines through the function execute(rule, focusNodes) -> inferredTriples where rule is the rule to execute, focusNodes is a set of nodes provided by a rule engine, and inferredTriples is the graph of (output) triples that are not in the base graph. The function is invoked as part of the execution of a rule set, which supplies the evaluation graph that the execution instructions read from.

Rule R has rule type T if R is a SHACL instance of T. Rules can have multiple types, e.g., to provide instructions that work either in SPARQL or JavaScript, depending on the capabilities of the engine. The creator of rules with multiple types needs to make sure that such rules have consistent semantics.

3.2 Shape Rules (sh:rule) and Global Rules

The property sh:rule can be used to link a shape (subject) with a shape rule (object). The subjects of sh:rule triples are IRIs. The objects of sh:rule triples are rules.

SHACL rules can be divided into two categories:

A shape rule is evaluated individually for each of its focus nodes. For example, a SPARQL rule that is a shape rule is evaluated with the variable $this pre-bound to each focus node, while a global SPARQL rule has no such pre-binding. In this sense, a shape rule is "local" to each of its focus nodes. However, the triples inferred by a shape rule are not local: both shape rules and global rules read from the same evaluation graph and contribute to the same inference graph, so the triples inferred by any rule are visible to subsequently executed rules and to the subsequent validation of all shapes.

An example of a shape rule was shown above in Example 1.

The following example illustrates a global rule.

3.3 Conditions on Shape Rules (sh:condition)

A shape rule may have values for the property sh:condition to specify shapes that the target nodes must conform to before they become focus nodes for the rule. Since global rules are executed without focus nodes, values of sh:condition have no effect on them.

The values of sh:condition at a rule must be well-formed shapes.

If the conformance check for a sh:condition at a rule produces a failure then the rule execution also reports a failure.

If the value C of sh:condition is a SHACL instance of both sh:NodeShape and rdfs:Class, then the target nodes must also conform to the constraints of the non-deactivated SHACL superclasses of C that are also SHACL instances of both sh:NodeShape and rdfs:Class. This is similar to how Implicit Class Targets are interpreted during validation.

3.4 Deactivated Rules (sh:deactivated)

Rules may be deactivated by setting sh:deactivated to true. Deactivated rules are ignored by the rules engine.

Each rule may have at most one value for the property sh:deactivated. The values of sh:deactivated are either of the xsd:boolean literals true or false.

3.5 Grouping of Rules into Layers (sh:layer)

Rules may be grouped into layers, identified by a numeric value. During execution, a SHACL rules engine will iterate over all rules with the same numeric layer value before moving to the next layer. Layers with a smaller numeric value will be executed before those with a larger number. Two rules are in the same layer if their layer values are equal as numbers, so that for example 1 and 1.0 identify the same layer.

Each rule may have at most one value for the property sh:layer. The values of sh:layer at rules are literals with datatype xsd:integer or xsd:decimal.

If unspecified and unless it has been computed by a custom rule processor, the default layer of a rule is 0.

An example of sh:layer to control the execution order of rules is provided in Example 6.

3.6 Ordering of Rules within a Layer (sh:order)

Rules may specify their relative execution order within the same layer as defined in this section.

Each rule may have at most one value for the property sh:order. The values of sh:order at rules are literals with datatype xsd:decimal or xsd:integer.

If unspecified and unless it has been computed by a custom rule processor, the default execution order is 0. In each iteration within a layer, rules are executed in ascending order of their sh:order values. These values are compared as numbers, so that for example 1 and 1.0 are the same order. The inferred triples of one rule (or group of same-order rules) become immediately visible to the subsequent rule (or group of same-order rules) in the order. Rules with the same order are executed concurrently: a rule does not see the triples newly inferred by other rules with the same order during the current iteration. The sets of triples individually inferred by these rules are added to the inference graph once all rules with that order have been executed. This is defined in detail in 8. General Execution Instructions for SHACL Rules.

Note

The property sh:order may also be used on shapes (see Non-Validating Shape Characteristics). However, such values have no effect on the execution of a rule set: the order of a shape rule is determined only by the sh:order value of the rule itself, not by that of the shape it is attached to.

3.7 Run-once Rules (sh:runOnce)

A SHACL rules engine iterates over the rules, allowing the same rule to be executed multiple times until no further triples are inferred. However, some rules may produce fresh blank nodes with each execution and therefore cause infinite iterations.

Rules may use the property sh:runOnce to instruct a rules engine that the rule is only executed once and before the other rules in the same layer.

Each rule may have at most one value for the property sh:runOnce. The values of sh:runOnce at rules are literals with datatype xsd:boolean.

A run-once rule is a rule that is executed in only one iteration, which takes place before the first iteration over the other rules of its layer. All other rules are called iterating rules. A rule that has true as its value for sh:runOnce is a run-once rule. Custom rule processors may compute additional run-once rules when sh:runOnce is absent.

3.8 Expected Derived Triples (sh:expectedPredicate)

SHACL Core includes the following properties to derive property values that are not necessarily asserted in the data graph:

Both properties can use node expressions including those defined in SHACL 1.2 Node Expressions. Both properties can only be used to compute the objects of a given predicate for the subjects that are targeted by shapes. This means that sh:defaultValue and sh:values describe implicit triples that are similar to inferences produced by rules.

When a rule refers to a certain property, it is reasonable for the rule to expect that these implicit triples are present. This section explains how rules can make sure that such derived triples are present before the rule executes.

For a given predicate p and a (non-deactivated) property shape in the shapes graph that has p as its value of sh:path, the derived value nodes of a focus node of the property shape are the value nodes that are added by the steps for sh:values and sh:defaultValue defined by SHACL 1.2 Core. As defined by these steps, the values of sh:defaultValue are only used if the focus node has no other value nodes, neither as triples in the graph nor computed by sh:values. For each derived value node v of a focus node f, there is a derived triple with f as the subject, p as the predicate and v as the object.

The derived triples of a layer are computed once before its first iteration using the evaluation graph as the data graph, and are added to the inference graph. They are not recomputed during the iterations of the layer, even if rules of that layer infer triples that would change them.

The expected derived triples of a rule are the derived triples for all values of the property sh:expectedPredicate at the rule.

The values of sh:expectedPredicate at a rule are IRIs.

All this is best explained by an example:

A SHACL rules engine will remove the derived triples from the inference graph at the end of processing each layer, except those triples that have also been inferred by rules. Some engines may have a setting to keep all derived triples, for example when data is exported to systems that do not support SHACL.

4. Rule Sets

The input to a SHACL rules engine is a set of rules called a rule set. Except for the default rule set, a rule set is identified by an IRI that is a SHACL instance of sh:RuleSet. The property sh:hasRule can be used to declare that a rule set has a given rule as a member. A rule set may contain both shape rules and global rules. The default rule set of a graph is the set of all rules in the graph, regardless of whether they are also members of other rule sets. Rule sets can use the property sh:includesRuleSet to (transitively) include other rule sets.

All SHACL instances of sh:RuleSet are IRIs. The values of sh:hasRule at a rule set are rules. The values of sh:includesRuleSet at a rule set are IRIs.

Note

Rule sets may contain rules of different rule types. However, the behaviour and effects of such a rule set could be difficult to predict and control, particularly when a custom rule processor computes the values of sh:order or sh:layer for some of its rules. Users are therefore advised against mixing rules of different types within the same rule set.

5. Rules Graph

A rules graph is a shapes graph that contains SHACL rules.

The sh:RulesGraph class MAY be used as an rdf:type of the IRI of a graph acting in the role of a rules graph.

The remainder of this section is non-normative.

The graph type classes (sh:DataGraph, sh:ShapesGraph, sh:RulesGraph) represent roles that are not mutually exclusive; a single graph may be typed with more than one of these classes. Rules graphs may contain sh:rule triples that reference shapes defined in other graphs, allowing rules to be managed independently of shape and ontology definitions.

6. Rule Entailment Regimes

SHACL Core defines the property sh:entailment to link a shapes graph with entailment regimes. This section defines two kinds of values of sh:entailment that instruct a SHACL validation engine to execute SHACL rules prior to starting the validation: the IRI sh:RulesEntailment, which executes all rules of the shapes graph, and rule sets, which execute only the rules of the given rule set.

After these entailments have been executed, the data graph that gets validated by the SHACL validation engine is the evaluation graph, i.e. the union of the base graph and the inference graph. The original data graph from the validation becomes the base graph and is not modified.

Following the general policy for SHACL, validation engines that do not support a given entailment regime MUST signal a failure if the shapes graph uses it as a value of sh:entailment.

6.1 The sh:RulesEntailment Regime

The IRI sh:RulesEntailment represents the SHACL rules entailment regime. In the following example, the shapes graph indicates to a SHACL validation engine that the SHACL rules inside of the shapes graph need to be executed prior to starting the validation.

Validation engines that do support the SHACL rules entailment regime execute the default rule set of the shapes graph following the rules execution instructions prior to performing the actual validation.

6.2 Entailment using Rule Sets

Any rule set can be used as a value of sh:entailment, i.e. any IRI that is a SHACL instance of sh:RuleSet in the shapes graph. Validation engines that support this regime execute the given rule set following the rules execution instructions prior to performing the actual validation. Only the rules of that rule set are executed, including those of the rule sets that it includes via sh:includesRuleSet. Other rules in the shapes graph are ignored.

If the shapes graph has more than one such value for sh:entailment, or also has the value sh:RulesEntailment, then the rules of all of them are executed together as a single rule set, and the values of sh:ruleProcessor of all of them apply to that rule set.

In the following example, which uses the rule sets from Example 8, only ex:Rule2 is executed prior to validation, while ex:Rule1 is ignored.

7. Temporary Triples

It is sometimes useful for inference rules to produce triples that are only visible during the execution of other rules but do not end up in the final inferences. A temporary triple is an inferred triple for which the inference graph contains a reifier with the value sh:tempTriple true. Temporary triples and their triple annotations are visible to executing rules. Rules can produce such triples as illustrated in the following example:

Creating temporary triples can be helpful when a computation is too complex to be carried out by a single rule. The complex computation can then be decomposed into multiple rules: some rules infer partial results, from which other rules derive the final results. The partial results are only functional to the computation of the final results and are no longer needed once the latter have been obtained. By marking these partial results as temporary triples, they are automatically removed after the final results have been computed.

8. General Execution Instructions for SHACL Rules

A SHACL rules engine is a computer procedure that takes as input a data graph called the base graph, a shapes graph, and an optional rule set (defaulting to the default rule set of the shapes graph) and is capable of producing triples that are not in the base graph. The new triples that are produced by a rules engine are called the inferred triples. The inference graph consists of these inferred triples. The evaluation graph is the union of the base graph and the inference graph. The base graph and the shapes graph are immutable.

An execution of a rule is the process that produces inferred triples from the rule based on the execution instructions of any one of its rule types:

During the execution of a rule set, the evaluation graph takes the role of the data graph: the target nodes of the shapes, the conformance of these nodes to the conditions, and the results of queries and node expressions are all determined using the evaluation graph as it is when the execution of the rule starts. This means that nodes that only exist in the inference graph can become focus nodes, and that the focus nodes of a rule can change from one iteration to the next. The evaluation graph does not change during the execution of a rule: the triples that are inferred for one focus node are not visible while the rule is executed for its other focus nodes.

For a given rule set in the shapes graph, an iteration over a set of rules consists of the following steps, skipping the rules that are deactivated:

The execution of a rule set is defined as follows:

For all layers in the rule set (in ascending order):
	Compute the expected derived triples for all non-deactivated rules in the layer
	Execute one iteration over all run-once rules in the layer
	do
		Execute one iteration over all iterating rules in the layer
	while the iteration has produced newly inferred triples
	Delete the derived triples (except those that were also inferred by rules)
		and their triple annotations

Delete the temporary triples and their triple annotations

Note that in this algorithm, adding and deleting triples is only performed on the inference graph.

If any of the rules reports a failure during execution, then the execution of a rule set also produces a failure.

If a rules engine is not able to execute a given rule because it does not support any of the rule types of the rule, then it reports a failure.

Rule engines MAY also report a failure after a pre-configured maximum iteration count has been exceeded or a pre-configured maximum number of inferred triples has been produced. This can help as a guard to avoid out-of-memory problems and infinite loops.

9. Tracking the Rule that has produced a Triple (sh:sourceRule)

Rule engines MAY have an option to generate additional triples that can be used to track which rules have produced the inferred triples. The property sh:sourceRule can be used in a reifier of a triple in the inference graph to link the triple with the rule. The values of sh:sourceRule SHOULD be IRIs.

The following example indicates that the triple ex:Alice ex:friend ex:Bob has been inferred by the rule ex:SymmetryRule.

<< ex:Alice ex:friend ex:Bob >> sh:sourceRule ex:SymmetryRule .

Fully expanded into RDF triples this is equivalent to:

_:id rdf:reifies <<( ex:Alice ex:friend ex:Bob )>> .
_:id sh:sourceRule ex:SymmetryRule .

If a rule engine adds these triples, the triples MUST NOT be visible to executing rules.

10. Custom Rule Processors (sh:ruleProcessor)

The general execution algorithm described above assumes that the author of the rules is responsible for selecting a suitable ordering and layering/grouping of rules to achieve the desired outcome.

Some SHACL rule implementations MAY implement different algorithms to determine:

This can, for example, be used by engines that support controlled subsets of SHACL rules for which it is possible to compute rule dependencies automatically. Another example is a rule engine that automatically prevents infinite loops because rules generate blank nodes.

Some SHACL rule implementations MAY also report additional failures that are not reported by the default algorithm.

The property sh:ruleProcessor can be used at rule sets or rules to instruct a rules engine that non-standard processing is required for the given rules.

The values of sh:ruleProcessor are IRIs, or literals with datatype xsd:string.

When used in a rule set, the values of sh:ruleProcessor from an included rule set also apply to the including rule set. A rules engine that encounters rules or rule sets with a value for sh:ruleProcessor that they are unable to handle MUST report a failure.

Issue 1202: Establish Link(s) between the two Rules documents SPARQL-RLSHACL Rules

This would be a good place to cross-reference the ongoing SPARQL-RL work, if this integrates naturally with SHACL Inference Rules. For example we could add an example with sh:ruleProcessor "SRL 1.2".

11. Built-in Rule Types

The SHACL inference rules framework defines a general syntax of rules and their execution algorithm. This document defines the two rule types from the following two subsections.

Note that not all implementations are required to implement both of these types for conformance. A rules engine that encounters a rule for which it does not implement any rule type reports a failure, as defined in 8. General Execution Instructions for SHACL Rules.

11.1 SHACL SPARQL Rules

This section defines a rule type called SHACL SPARQL rules, often just "SPARQL Rules", identified by the IRI sh:SPARQLRule. SPARQL rules have the following properties:

Property Summary and Syntax Rules
sh:construct The SPARQL CONSTRUCT query. SPARQL rules must have exactly one value for the property sh:construct. The values of sh:construct are literals with datatype xsd:string. Using the prefix handling rules, the value of sh:construct is a valid SPARQL 1.2 CONSTRUCT query.
sh:prefixes The prefixes to use to turn the sh:construct into a SPARQL query. SPARQL rules may use the property sh:prefixes to declare a dependency on prefixes based on the mechanism defined in Prefix Declarations for SPARQL Queries. This mechanism allows users to abbreviate URIs in the sh:construct strings.
EXECUTION OF SPARQL RULES
Let Q be the SPARQL CONSTRUCT query derived from the values of the properties sh:construct and sh:prefixes of the SPARQL rule in the shapes graph.

The SPARQL function NOW returns the same result in all SPARQL rules during the execution of a rule set.

Note

For SPARQL rules that are shape rules (i.e., linked to a shape with sh:rule), a SHACL rules engine also counts as a SHACL-SPARQL processor (as defined by SHACL 1.2 SPARQL-Related Features) and the syntax limitations required by pre-binding do apply to shape rules. Since global SPARQL rules do not use pre-binding, the syntax limitations required by pre-binding do not apply to them.

11.2 Triple Rules

This section defines a rule type called triple rules, identified by the IRI sh:TripleRule. Triple rules have the following properties:

Property Summary and Syntax Rules
sh:subject The node expression used to compute the subjects of the triples. Each triple rule must have at most one value of the property sh:subject (which must be a well-formed node expression).
sh:predicate The node expression used to compute the predicates of the triples. Each triple rule must have at most one value of the property sh:predicate (which must be a well-formed node expression).
sh:object The node expression used to compute the objects of the triples. Each triple rule must have at most one value of the property sh:object (which must be a well-formed node expression).
EXECUTION OF TRIPLE RULES
Let S, P and O be the output nodes of evaluating the node expressions that are the values of sh:subject, sh:predicate and sh:object respectively at the triple rule, using evalExpr(expr, evaluation graph, focusNode, {}) as defined in SHACL 1.2 Core, where focusNode is the current focus node (no value for global rules). If any of these evaluations produces an evaluation failure, then the execution of the triple rule produces a failure. Where sh:subject, sh:predicate, or sh:object are absent, use the list consisting of the current focus node (which is empty for global rules). For each combination of members s of S, p of P and o of O, infer a triple with subject s, predicate p and object o. Duplicate combinations produce the same triple. Skip ill-formed triples, for example when a blank node is used as predicate.

12. SPARQL Rule Templates

The class sh:SPARQLRuleTemplate can be used to declare new rule types called SPARQL rule templates. Each SPARQL rule template is itself a class and therefore denotes a set of rules: the SHACL instances of a template are the individual rules (see examples below). These rule types define a (reusable) SPARQL CONSTRUCT query and can take parameters that are mapped to pre-bound variables in the CONSTRUCT query. This mechanism allows similar rules to reuse the same CONSTRUCT query while the user only needs to specify the parameter values, without even having to write or understand SPARQL.

Each SPARQL rule template is an IRI. Each SPARQL rule template is a SHACL subclass of sh:Rule. The values of sh:parameter at a SPARQL rule template are parameter declarations that follow the same syntax rules as the parameter declarations of SPARQL-based constraint components. Each SPARQL rule template has exactly one value of sh:construct and that value is a literal with datatype xsd:string. Using the prefix handling rules, the value of sh:construct at a SPARQL rule template is a valid SPARQL 1.2 CONSTRUCT query.

Like SPARQL rules, a SPARQL rule template can use the property sh:prefixes to declare prefixes to be used with the sh:construct.

EXECUTION OF RULES BASED ON SPARQL RULE TEMPLATES
Let R be a SHACL instance of the SPARQL rule template T. Let Q be the SPARQL CONSTRUCT query that is produced from the value of sh:construct at T in the shapes graph, using the prefix declarations at T. For each parameter declaration P of T (i.e., each value of sh:parameter) for which R has a value for the property that is the sh:path of P, the variable with the parameter name of P is pre-bound to that value. The variables of the other parameters remain unbound. Evaluate Q like a corresponding SPARQL Rule but using these extra pre-bound variables. Report a failure if any of the declared parameters that are not declared as sh:optional true have no value in R.

In the example below, the CONSTRUCT query is executed with the SPARQL variable $property pre-bound to the value of ex:property.

Note

The instances of sh:SPARQLRuleTemplate (the SPARQL rule templates) are classes. The instances of those classes are the actual rule instances. SPARQL rule templates need to be declared as rdfs:subClassOf sh:Rule so that their instances are SHACL rules. This also places them into the class hierarchy alongside the other rule types such as sh:SPARQLRule.

The following example uses a SPARQL rule template as a shape rule, meaning that the variable $this will point at the current focus node when the rule executes.

Appendix

A. Summary of Syntax Rules

This section enumerates all normative syntax rules of this document. This section is automatically generated from other parts of this spec and hyperlinks are provided back into the prose if the context of the rule is unclear. Nodes that violate these rules in a shapes graph are ill-formed.

Syntax Rule Id Syntax Rule Text
rule-typeEach SHACL rule has at least one rdf:type which is an IRI.
ruleThe property sh:rule can be used to link a shape (subject) with a shape rule (object). The subjects of sh:rule triples are IRIs.
rule-objectThe objects of sh:rule triples are rules.
condition-nodeThe values of sh:condition at a rule must be well-formed shapes.
deactivated-maxCountEach rule may have at most one value for the property sh:deactivated.
deactivated-inThe values of sh:deactivated are either of the xsd:boolean literals true or false.
rule-layer-maxCountEach rule may have at most one value for the property sh:layer.
rule-layer-datatypeThe values of sh:layer at rules are literals with datatype xsd:integer or xsd:decimal.
rule-order-maxCountEach rule may have at most one value for the property sh:order.
rule-order-datatypeThe values of sh:order at rules are literals with datatype xsd:decimal or xsd:integer.
run-once-maxCountEach rule may have at most one value for the property sh:runOnce.
run-once-datatypeThe values of sh:runOnce at rules are literals with datatype xsd:boolean.
expectedPredicate-nodeKindThe values of sh:expectedPredicate at a rule are IRIs.
RuleSet-nodeKindAll SHACL instances of sh:RuleSet are IRIs.
hasRuleThe values of sh:hasRule at a rule set are rules.
includesRuleSet-nodeKindThe values of sh:includesRuleSet at a rule set are IRIs.
ruleProcessorThe values of sh:ruleProcessor are IRIs, or literals with datatype xsd:string.
construct-countSPARQL rules must have exactly one value for the property sh:construct.
construct-datatypeThe values of sh:construct are literals with datatype xsd:string.
construct-query-validUsing the prefix handling rules, the value of sh:construct is a valid SPARQL 1.2 CONSTRUCT query.
TripleRule-subjectEach triple rule must have at most one value of the property sh:subject (which must be a well-formed node expression).
TripleRule-predicateEach triple rule must have at most one value of the property sh:predicate (which must be a well-formed node expression).
TripleRule-objectEach triple rule must have at most one value of the property sh:object (which must be a well-formed node expression).
SPARQLRuleTemplate-nodeKindEach SPARQL rule template is an IRI.
SPARQLRuleTemplate-subClassOfEach SPARQL rule template is a SHACL subclass of sh:Rule.
SPARQLRuleTemplate-parameterThe values of sh:parameter at a SPARQL rule template are parameter declarations that follow the same syntax rules as the parameter declarations of SPARQL-based constraint components.
SPARQLRuleTemplate-constructEach SPARQL rule template has exactly one value of sh:construct and that value is a literal with datatype xsd:string.
SPARQLRuleTemplate-construct-query-validUsing the prefix handling rules, the value of sh:construct at a SPARQL rule template is a valid SPARQL 1.2 CONSTRUCT query.

B. Security and Privacy Considerations

This section is non-normative.

Applying a SHACL inference rule set to a data graph can result in significant computation and memory usage, which may be exploited to cause denial of service. Applications should take care to limit the amount of computation and memory usage that can be caused by applying such rule sets.

SHACL inference rules can be used to process and create arbitrary application data; security considerations will vary by domain of use. Security/privacy protocols should be imposed which reflect the sensitivity of the information in the outcome of rule set evaluation, including potentially sensitive information exposed through the expected derived triples mechanism.

Security considerations of this document include all the security considerations of SHACL SPARQL, SHACL Node Expressions and SHACL Core.

C. Acknowledgements

This section is non-normative.

Original SHACL core specifications were produced by the RDF Data Shapes Working Group. See the Core specification's Acknowledgements section and the Advanced Features specification's Acknowledgements section.

D. References

D.1 Normative references

[rdf12-concepts]
RDF 1.2 Concepts and Abstract Data Model. Gregg Kellogg; Olaf Hartig; Pierre-Antoine Champin; Andy Seaborne. W3C. 16 November 2026. CRD. URL: https://www.w3.org/TR/rdf12-concepts/
[rdf12-turtle]
RDF 1.2 Turtle. Gregg Kellogg; Andy Seaborne; Dominik Tomaszuk. W3C. 11 November 2026. W3C Working Draft. URL: https://www.w3.org/TR/rdf12-turtle/
[RFC2119]
Key words for use in RFCs to Indicate Requirement Levels. S. Bradner. IETF. March 1997. Best Current Practice. URL: https://www.rfc-editor.org/info/rfc2119/
[RFC8174]
Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words. B. Leiba. IETF. May 2017. Best Current Practice. URL: https://www.rfc-editor.org/info/rfc8174/
[shacl12-core]
SHACL 1.2 Core. Holger Knublauch; Thomas Bergwinkl; Yousouf Taghzouti; Jesse Wright. W3C. 16 November 2026. W3C Working Draft. URL: https://www.w3.org/TR/shacl12-core/
[shacl12-node-expr]
SHACL 1.2 Node Expressions. Robert David; Holger Knublauch; Simon Steyskal. W3C. 16 November 2026. W3C Working Draft. URL: https://www.w3.org/TR/shacl12-node-expr/
[shacl12-sparql]
SHACL 1.2 SPARQL-Related Features. Holger Knublauch; Matt Goldberg; Scott Henninger; Livio Robaldo. W3C. 22 October 2026. W3C Working Draft. URL: https://www.w3.org/TR/shacl12-sparql/
[sparql12-query]
SPARQL 1.2 Query Language. Olaf Hartig; Andy Seaborne; Ruben Taelman; Gregory Williams; Thomas Pellissier Tanon. W3C. 19 November 2026. W3C Working Draft. URL: https://www.w3.org/TR/sparql12-query/

D.2 Informative references

[shacl12-inference-rules]
SHACL 1.2 Inference Rules. Holger Knublauch; Matt Goldberg; Scott Henninger; Livio Robaldo; Simon Steyskal. W3C. 10 November 2026. W3C Working Draft. URL: https://www.w3.org/TR/shacl12-inference-rules/
[shacl12-profiling]
SHACL 1.2 Profiling. Nicholas Car; Scott Henninger; Yousouf Taghzouti; Alexander Nelson; Matt Goldberg. W3C. 2 July 2026. FPWD. URL: https://www.w3.org/TR/shacl12-profiling/
[shacl12-ui]
SHACL 1.2 User Interfaces. Edmond Chuc; Thomas Bergwinkl; Ieben Smessaert; Daniël Beeke. W3C. 19 November 2026. W3C Working Draft. URL: https://www.w3.org/TR/shacl12-ui/
[sparql12-rl]
SPARQL 1.2 RL. Robert David; David Habgood; Andy Seaborne; Simon Steyskal. W3C. 15 November 2026. W3C Working Draft. URL: https://www.w3.org/TR/sparql12-rl/