Please check the errata for any errors or issues reported since publication.
See also translations.
Copyright © 2017 W3C® (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and document use rules apply.
This document defines the SHACL Shapes Constraint Language, a language for validating RDF graphs against a set of conditions. These conditions are provided as shapes and other constructs expressed in the form of an RDF graph. RDF graphs that are used in this manner are called "shapes graphs" in SHACL and the RDF graphs that are validated against a shapes graph are called "data graphs". As SHACL shape graphs are used to validate that data graphs satisfy a set of conditions they can also be viewed as a description of the data graphs that do satisfy these conditions. Such descriptions may be used for a variety of purposes beside validation, including user interface building, code generation and data integration.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at https://www.w3.org/TR/.
This document was published by the RDF Data Shapes Working Group as a Recommendation. Comments regarding this document are welcome. Please send them to public-rdf-shapes@w3.org (subscribe, archives).
Please see the Working Group's implementation report.
This document has been reviewed by W3C Members, by software developers, and by other W3C groups and interested parties, and is endorsed by the Director as a W3C Recommendation. It is a stable document and may be used as reference material or cited from another document. W3C's role in making the Recommendation is to draw attention to the specification and to promote its widespread deployment. This enhances the functionality and interoperability of the Web.
This document was produced by a group operating under the 5 February 2004 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 which 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 1 March 2017 W3C Process Document.
The introduction includes a Terminology section.
The sections 2 - 4 cover the SHACL Core language and may be read independently from the later sections.
The sections 5 and 6 are about the features that SHACL-SPARQL has in addition to the Core language. These advanced features are SPARQL-based constraints and constraint components.
The syntax of SHACL is RDF. The examples in this document use Turtle [turtle] and (in one instance) JSON-LD [json-ld]. Other RDF serializations such as RDF/XML may be used in practice. The reader should be familiar with basic RDF concepts [rdf11-concepts] such as triples and, for the advanced concepts of SHACL, with SPARQL [sparql11-query].
This document specifies SHACL (Shapes Constraint Language), a language for describing and validating RDF graphs. This section introduces SHACL with an overview of the key terminology and an example to illustrate basic concepts.
Throughout this document, the following terminology is used.
Terminology that is linked to portions of RDF 1.1 Concepts and Abstract Syntax is used in SHACL as defined there. Terminology that is linked to portions of SPARQL 1.1 Query Language is used in SHACL as defined there. A single linkage is sufficient to provide a definition for all occurences 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.
n has a value v for property p in an RDF graph if there is an RDF triple in the graph with subject n, predicate p,
and object v. The phrase "Every value of P in graph G ..." means "Every object of a triple in G with predicate P ...". (In this document, the verbs specify or declare are sometimes used to express the fact that an RDF term has values for a given predicate in a graph.)
n has value v for
SPARQL property path expression
p in an RDF graph G if there is a solution mapping in the result of the SPARQL query
SELECT ?s ?o WHERE { ?s p' ?o } on G that binds ?s to
n and ?o to v, where p' is SPARQL surface syntax for p.
G is an IRI or a blank node
that is either rdf:nil (provided that rdf:nil has no value
for either rdf:first or rdf:rest), or has exactly one value
for the property rdf:first in G and exactly one value
for the property rdf:rest in G that is also a SHACL list in G,
and the list does not have itself as a value of the property path rdf:rest+ in G.
rdf:nil in an RDF graph G consist of its value for rdf:first in G followed by the members
in G of its value for rdf:rest in G. The SHACL list rdf:nil has no members in any RDF graph.
Sub in an RDF graph is a SHACL subclass of another node Super in the graph if there is a sequence of triples in the graph each with predicate rdfs:subClassOf such that the subject of the first triple is Sub, the object of the last
triple is Super, and the object of each triple except the last is the subject of the next. If Sub is a SHACL subclass of Super in an RDF graph then Super is a SHACL superclass of Sub in the graph.
n in an RDF graph G is a SHACL instance of a SHACL class C in G if one of the SHACL types of n in G is C.
Within this document, the following namespace prefix bindings are used:
| Prefix | Namespace |
|---|---|
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# |
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.
# This box represents an input shapes graph
# Triples that can be omitted are marked as grey e.g.
<s> <p> <o> .
# This box represents an input data graph. # When highlighting is used in the examples: # Elements highlighted in blue are focus nodes ex:Bob a ex:Person . # Elements highlighted in red are focus nodes that fail validation ex:Alice a ex:Person .
# This box represents an output results graph
SHACL Definitions appear in blue boxes:
# This box contains SPARQL or textual definitions.
Grey boxes such as this include syntax rules that apply to the shapes graph.
true denotes the RDF term "true"^^xsd:boolean.
false denotes the RDF term "false"^^xsd:boolean.
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 are to be interpreted as described in [RFC2119].
This document defines the SHACL Core language, also referred to as just SHACL, as described in Part A, and the SHACL-SPARQL language that extends SHACL Core with constructs described in Part B. This specification describes conformance criteria for:
This document includes syntactic rules that shapes and other nodes need to fulfill in the shapes graph. These rules are typically of the form A shape must have... or The values of X are literals or All objects of triples with predicate P must be IRIs. The complete list of these rules can be found in the appendix. Nodes that violate any of these rules are called ill-formed. Nodes that violate none of these rules are called well-formed. A shapes graph is ill-formed if it contains at least one ill-formed node.
The remainder of this section is informative.
SHACL Core processors that do not also support SHACL-SPARQL ignore any SHACL-SPARQL constructs such as sh:sparql triples.
This section is non-normative.
The following example data graph contains three SHACL instances of the class ex:Person.
ex:Alice a ex:Person ; ex:ssn "987-65-432A" . ex:Bob a ex:Person ; ex:ssn "123-45-6789" ; ex:ssn "124-35-6789" . ex:Calvin a ex:Person ; ex:birthDate "1971-07-07"^^xsd:date ; ex:worksFor ex:UntypedCompany .
The following conditions are shown in the example:
ex:Person can have at most one value for the property ex:ssn,
and this value is a literal with the datatype xsd:string that matches a specified regular
expression.
ex:Person can have unlimited values for the property ex:worksFor,
and these values are IRIs and SHACL instances of ex:Company.
ex:Person cannot have values for any other property apart
from
ex:ssn, ex:worksFor and rdf:type.
The aforementioned conditions can be represented as shapes and constraints in the following shapes graph:
ex:PersonShape
a sh:NodeShape ;
sh:targetClass ex:Person ; # Applies to all persons
sh:property [ # _:b1
sh:path ex:ssn ; # constrains the values of ex:ssn
sh:maxCount 1 ;
sh:datatype xsd:string ;
sh:pattern "^\\d{3}-\\d{2}-\\d{4}$" ;
] ;
sh:property [ # _:b2
sh:path ex:worksFor ;
sh:class ex:Company ;
sh:nodeKind sh:IRI ;
] ;
sh:closed true ;
sh:ignoredProperties ( rdf:type ) .
The example below shows the same shape definition as a possible JSON-LD [json-ld] fragment. Note that we have left out a @context declaration, and depending on the
@context the rendering may look quite different. Therefore this example should be understood as an illustration only.
{
"@id" : "ex:PersonShape",
"@type" : "NodeShape",
"targetClass" : "ex:Person",
"property" : [
{
"path" : "ex:ssn",
"maxCount" : 1,
"datatype" : "xsd:string" ,
"pattern" : "^\\d{3}-\\d{2}-\\d{4}$"
},
{
"path" : "ex:worksFor",
"class" : "ex:Company",
"nodeKind" : "sh:IRI"
}
],
"closed" : true,
"ignoredProperties" : [ "rdf:type" ]
}
We can use the shape declaration above to illustrate some of the key terminology used by SHACL. The target for the shape ex:PersonShape is the set of all SHACL instances of the class ex:Person.
This is specified using the property sh:targetClass. During the validation, these target nodes become focus nodes for the shape. The shape ex:PersonShape is a node shape, which means that it applies to the focus nodes. It declares constraints on the focus nodes, for example using the parameters sh:closed and sh:ignoredProperties. The node shape also declares two other constraints with the property sh:property, and each
of these is backed by a property shape. These property shapes declare additional constraints using parameters such as sh:datatype and sh:maxCount.
Some of the property shapes specify parameters from multiple constraint components in order to restrict multiple aspects of the property values. For example, in the property shape for ex:ssn, parameters from three constraint components are used. The parameters of these constraint components are sh:datatype, sh:pattern and sh:maxCount. For each focus node the property values of ex:ssn will be validated against all three components.
SHACL validation based on the provided data graph and shapes graph would produce the following validation report. See the section Validation Report for details on the format.
[ a sh:ValidationReport ; sh:conforms false ; sh:result [ a sh:ValidationResult ; sh:resultSeverity sh:Violation ; sh:focusNode ex:Alice ; sh:resultPath ex:ssn ; sh:value "987-65-432A" ; sh:sourceConstraintComponent sh:RegexConstraintComponent ; sh:sourceShape ... blank node _:b1 on ex:ssn above ... ; ] , [ a sh:ValidationResult ; sh:resultSeverity sh:Violation ; sh:focusNode ex:Bob ; sh:resultPath ex:ssn ; sh:sourceConstraintComponent sh:MaxCountConstraintComponent ; sh:sourceShape ... blank node _:b1 on ex:ssn above ... ; ] , [ a sh:ValidationResult ; sh:resultSeverity sh:Violation ; sh:focusNode ex:Calvin ; sh:resultPath ex:worksFor ; sh:value ex:UntypedCompany ; sh:sourceConstraintComponent sh:ClassConstraintComponent ; sh:sourceShape ... blank node _:b2 on ex:worksFor above ... ; ] , [ a sh:ValidationResult ; sh:resultSeverity sh:Violation ; sh:focusNode ex:Calvin ; sh:resultPath ex:birthDate ; sh:value "1971-07-07"^^xsd:date ; sh:sourceConstraintComponent sh:ClosedConstraintComponent ; sh:sourceShape sh:PersonShape ; ] ] .
The validation results are enclosed in a validation report. The first validation result is produced because ex:Alice has a value for ex:ssn that does not match the regular
expression specified by the property sh:regex. The second validation result is produced because ex:Bob has more than the permitted
number of values for the property ex:ssn as specified by the sh:maxCount of 1. The third validation result is produced because ex:Calvin has a value for ex:worksFor that does not have an rdf:type triple that makes it a SHACL instance of ex:Company. The forth validation result is produced because the shape ex:PersonShape has the property sh:closed set to true but ex:Calvin uses the property ex:birthDate which is neither one of the predicates from any of the
property shapes of the shape, nor one of the properties listed using sh:ignoredProperties.
SHACL uses the RDF and RDFS vocabularies, but full RDFS inferencing is not required.
However, SHACL processors MAY operate on RDF graphs that include entailments [sparql11-entailment] - either pre-computed before being
submitted to a SHACL processor or performed on the fly as part of SHACL processing (without modifying either data graph or shapes graph). To support processing of entailments, SHACL includes the property
sh:entailment to indicate what inferencing is required by a given shapes graph.
The values of the property sh:entailment are IRIs. Common values for
this property are covered by [sparql11-entailment].
SHACL implementations MAY, but are not required to, support entailment regimes. If a shapes graph contains any triple with the predicate sh:entailment and object E and the SHACL processor does not support E as an entailment regime for the given data graph then the processor MUST signal a failure. Otherwise, the SHACL processor MUST provide the entailments for all of the values of sh:entailment in the shapes graph, and any inferred triples MUST be returned by all queries against the data graph during the validation process.
This section is non-normative.
For SHACL Core this specification uses parts of SPARQL 1.1 in non-normative alternative definitions of the semantics of constraint components and targets. While these may help some implementers, SPARQL is not required for the implementation of the SHACL Core language.
SHACL-SPARQL is based on SPARQL 1.1 and uses it as a mechanism to declare constraints and constraint components. Implementations that cover only the SHACL Core features are not required to implement these mechanisms.
SPARQL variables using the $ marker represent external bindings that are pre-bound or, in the case of $PATH, substituted in the SPARQL query before execution (as explained in 6.3 Validation with SPARQL-based Constraint Components).
The definition of some constraints requires or is simplified through access to the shapes graph during query execution. SHACL-SPARQL processors MAY pre-bind the variable shapesGraph to provide access
to the shapes graph. Access to the shapes graph is not a requirement for supporting the SHACL
Core language. The variable shapesGraph can also be used in SPARQL-based constraints and SPARQL-based constraint components. However, such constraints may not be interoperable across different SHACL-SPARQL processors or not applicable to remote RDF datasets.
Note that at the time of writing, SPARQL EXISTS has been imperfectly defined and implementations vary. While a W3C Community Group is working on improving this situation, users of SPARQL are advised that the use of EXISTS may have inconsistent results and should be approached with care.
The following introduction is non-normative.
The following informal diagram provides an overview of some of the key classes in the SHACL vocabulary. Each box represents a class. The content of the boxes under the class name lists some of the properties that instances of these classes may have, together
with their value types. The arrows indicate rdfs:subClassOf triples.
The Turtle serialization of the SHACL vocabulary contains the complete SHACL vocabulary.
s that fulfills
at least one of the following conditions in the shapes graph:
s is a SHACL instance of sh:NodeShape or sh:PropertyShape.
s is subject of a triple that has sh:targetClass, sh:targetNode,
sh:targetObjectsOf or sh:targetSubjectsOf as predicate.
s is subject of a triple that has a parameter as predicate.
s is a value of a shape-expecting, non-list-taking parameter such as sh:node, or a member of a SHACL list that is a value of a shape-expecting and list-taking parameter such as sh:or.
Note that the definition above does not include all of the syntax rules of well-formed shapes. Those are found throughout the document and summarized in Appendix
B. Summary of SHACL Syntax Rules. For example, shapes that have literals as values for sh:targetClass are ill-formed.
Informally, a shape determines how to validate a focus node based on the values of properties and other characteristics of the focus node. For example, shapes can declare the condition that a focus node be an IRI or that a focus node has a particular value for a property and also a minimum number of values for the property.
The SHACL Core language defines two types of shapes:
sh:Shape is the SHACL superclass of those two shape types in the SHACL vocabulary. Its subclasses sh:NodeShape and sh:PropertyShape can be used as SHACL type of node and property shapes, respectively.
Shapes can declare constraints using the parameters of constraint components.
A constraint component is an IRI. Each constraint component has one or more mandatory parameters, each of which is a property. Each constraint component has zero or more optional parameters, each of which is a property. The parameters of a constraint component are its mandatory parameters plus its optional parameters.
For example, the component sh:MinCountConstraintComponent declares the parameter sh:minCount to represent the restriction that a node has at least a minimum number of values for a particular property.
For a constraint component C with mandatory parameters p1,
... pn, a shape s in a shapes graph SG declares a constraint that has kind C with mandatory parameter values <p1,v1>, ... <pn,vn> in SG when s has vi as a value for pi in SG. For constraint components with optional parameters, the constraint declaration consists
of the values that the shape has for all mandatory and optional parameters of that component.
Some constraint components declare only a single parameter. For example sh:ClassConstraintComponent has the single parameter sh:class. These parameters may be used multiple
times in the same shape, and each value of such a parameter declares an individual constraint.
The interpretation of such declarations is conjunction, i.e. all constraints apply. The following example specifies that the values of ex:customer have to be SHACL instances of both
ex:Customer and ex:Person.
ex:InvoiceShape a sh:NodeShape ; sh:property [ sh:path ex:customer ; sh:class ex:Customer ; sh:class ex:Person ; ] .
Some constraint components such as sh:PatternConstraintComponent declare more than one parameter. Shapes that have more than one value for any of the parameters of such components
are ill-formed.
One way to bypass this syntax rule is to spread the constraints across multiple (property) shapes, as illustrated in the following example.
ex:MultiplePatternsShape a sh:NodeShape ; sh:property [ sh:path ex:name ; sh:pattern "^Start" ; sh:flags "i" ; ] ; sh:property [ sh:path ex:name ; sh:pattern "End$" ; ] .
Constraint components are associated with validators, which provide instructions (for example expressed via SPARQL queries) on how the parameters are used to validate data. Validating an RDF term against a shape involves validating the term against each constraint where the shape has values for all mandatory parameters of the component of the constraint, using the validators associated with the respective component.
The list of constraint components included in SHACL Core is described in section 4. SHACL-SPARQL can be used to declare additional constraint components based on SPARQL.
An RDF term that is validated against a shape using the triples from a data graph is called a focus node.
The remainder of this section is informative.
The set of focus nodes for a shape may be identified as follows:
sh:node)
Target declarations of a shape in a shapes graph are
triples with the shape as the subject and certain properties described in this document (e.g., sh:targetClass) as predicates. Target declarations can be used to produce focus nodes for a shape. The target of a target declaration is the set of RDF terms produced by applying the rules described in the remainder of this section to the data graph.
The target of a shape is the union of all RDF terms produced by the individual
targets that are declared by the shape in the shapes graph.
SHACL Core includes the following kinds of targets: node targets, class-based targets (including implicit class-based targets), subjects-of targets, and objects-of targets.
The remainder of this introduction is informative.
RDF terms produced by targets are not required to exist as nodes in the data graph. Targets of a shape are ignored whenever a focus node is provided directly as
input to the validation process for that shape. This includes the cases where the shape is a value of one of the
shape-expecting constraint parameters (such as sh:node) and a focus node is determined during the validation of the corresponding
constraint component (such as sh:NodeConstraintComponent). In such cases, the provided focus node does not need to be in the target of the shape.
A node target is specified using the sh:targetNode predicate.
Each value of sh:targetNode in a shape is either an IRI or a literal.
s is a shape in a shapes graph SG and s has
value t for sh:targetNode in SG then { t } is a target from any data graph for s in SG.
The remainder of this section is informative.
With the example data below, only ex:Alice is the target of the provided shape:
ex:PersonShape a sh:NodeShape ; sh:targetNode ex:Alice .
ex:Alice a ex:Person .
ex:Bob a ex:Person .
The following query expresses a potential definition of node targets in SPARQL. The variable targetNode will be pre-bound to the given value of sh:targetNode. All bindings of the variable this from the solution become focus nodes.
SELECT DISTINCT ?this # ?this is the focus node WHERE { BIND ($targetNode AS ?this) # $targetNode is pre-bound to ex:Alice }
A class target is specified with the sh:targetClass predicate.
Each value of sh:targetClass in a shape is an IRI.
s is a shape in a shapes graph SG and s has value c for
sh:targetClass in SG then the set of SHACL instances of c in a data graph
DG is a target from DG for s in SG.
The remainder of this section is informative.
ex:PersonShape a sh:NodeShape ; sh:targetClass ex:Person .
ex:Alice a ex:Person . ex:Bob a ex:Person . ex:NewYork a ex:Place .
In this example, only ex:Alice and ex:Bob are focus nodes. Note that, according to the SHACL instance definition, all the rdfs:subClassOf declarations needed to walk the class hierarchy need to exist in the data graph. However, the ex:Person a rdfs:Class triple is not required to
exist in either graphs.
In the following example, the selected focus node is only ex:Who.
ex:Doctor rdfs:subClassOf ex:Person .
ex:Who a ex:Doctor .
ex:House a ex:Nephrologist .
The following query expresses a potential definition of class targets in SPARQL. The variable targetClass will be pre-bound to the given value of sh:targetClass. All bindings of the variable this from the solutions become focus nodes.
SELECT DISTINCT ?this # ?this is the focus node WHERE { ?this rdf:type/rdfs:subClassOf* $targetClass . # $targetClass is pre-bound to ex:Person }
Informally, if a shape is also declared to be a class in the shapes graph then all SHACL instances of this class are a target for the shape.
If s is a SHACL instance of sh:NodeShape or sh:PropertyShape in an RDF graph G and s is
also a SHACL instance of
rdfs:Class in G and s is not an IRI then s is an ill-formed shape in G.
s is a SHACL instance of sh:NodeShape or sh:PropertyShape in a shapes graph SG and s is also a SHACL instance of rdfs:Class in SG then the
set of SHACL instances of s in a data graph DG is a target from DG for s in SG.
The remainder of this section is informative.
In the following example, ex:Alice is a focus node, because it is a SHACL instance of
ex:Person which is both a class and a shape in the shapes graph.
ex:Person a rdfs:Class, sh:NodeShape .
ex:Alice a ex:Person .
ex:NewYork a ex:Place .
A subjects-of target is specified with the predicate sh:targetSubjectsOf.
The values of sh:targetSubjectsOf in a shape are IRIs.
s is a shape in a shapes graph SG and s has value
p for sh:targetSubjectsOf in SG then the set of nodes in a data graph DG that are subjects of triples in DG with predicate
p is a target from DG for s in SG.
The remainder of this section is informative.
ex:TargetSubjectsOfExampleShape a sh:NodeShape ; sh:targetSubjectsOf ex:knows .
ex:Alice ex:knows ex:Bob .
ex:Bob ex:livesIn ex:NewYork .
In the example above, only ex:Alice is validated against the given shape, because it is the subject of a triple that has ex:knows as its predicate.
The following query expresses a potential definition of subjects-of targets in SPARQL. The variable targetSubjectsOf will be pre-bound to the given value of sh:targetSubjectsOf.
All bindings of the variable this from the solutions become focus nodes.
SELECT DISTINCT ?this # ?this is the focus node WHERE { ?this $targetSubjectsOf ?any . # $targetSubjectsOf is pre-bound to ex:knows }
An objects-of target is specified with the predicate sh:targetObjectsOf.
The values of sh:targetObjectsOf in a shape are IRIs.
s is a shape in a shapes graph SG and s has value
p for sh:targetObjectsOf in SG then the set of nodes in a data graph DG that are objects of triples in DG with predicate
p is a target from DG for s in SG.
The remainder of this section is informative.
ex:TargetObjectsOfExampleShape a sh:NodeShape ; sh:targetObjectsOf ex:knows .
ex:Alice ex:knows ex:Bob .
ex:Bob ex:livesIn ex:NewYork .
In the example above, only ex:Bob is validated against the given shape, because it is the object of a triple that has ex:knows as its predicate.
The following query expresses a potential definition of objects-of targets in SPARQL. The variable targetObjectsOf will be pre-bound to the given value of sh:targetObjectsOf.
All bindings of the variable this from the solutions become focus nodes.
SELECT DISTINCT ?this # ?this is the focus node WHERE { ?any $targetObjectsOf ?this . # $targetObjectsOf is pre-bound to ex:knows }
Shapes can specify one value for the property sh:severity in the shapes graph.
Each value of sh:severity in a shape is an IRI.
The values of sh:severity are called severities. SHACL includes the three IRIs listed in the table below to represent severities.
These are declared in the SHACL vocabulary as SHACL instances of sh:Severity.
| Severity | Description |
|---|---|
sh:Info |
A non-critical constraint violation indicating an informative message. |
sh:Warning |
A non-critical constraint violation indicating a warning. |
sh:Violation |
A constraint violation. |
The remainder of this section is informative.
The specific values of sh:severity have no impact on the validation, but MAY be used by user interface tools to categorize validation results. The values of sh:severity are used by SHACL processors to populate the sh:resultSeverity field of validation results, see section on severity in validation results. Any IRI can be used as a severity.
For every shape, sh:Violation is the default if sh:severity is unspecified. The following example illustrates this.
ex:MyShape
a sh:NodeShape ;
sh:targetNode ex:MyInstance ;
sh:property [ # _:b1
# Violations of sh:minCount and sh:datatype are produced as warnings
sh:path ex:myProperty ;
sh:minCount 1 ;
sh:datatype xsd:string ;
sh:severity sh:Warning ;
] ;
sh:property [ # _:b2
# The default severity here is sh:Violation
sh:path ex:myProperty ;
sh:maxLength 10 ;
sh:message "Too many characters"@en ;
sh:message "Zu viele Zeichen"@de ;
] .
ex:MyInstance ex:myProperty "http://toomanycharacters"^^xsd:anyURI .
[ a sh:ValidationReport ; sh:conforms false ; sh:result [ a sh:ValidationResult ; sh:resultSeverity sh:Warning ; sh:focusNode ex:MyInstance ; sh:resultPath ex:myProperty ; sh:value "http://toomanycharacters"^^xsd:anyURI ; sh:sourceConstraintComponent sh:DatatypeConstraintComponent ; sh:sourceShape _:b1 ; ] , [ a sh:ValidationResult ; sh:resultSeverity sh:Violation ; sh:focusNode ex:MyInstance ; sh:resultPath ex:myProperty ; sh:value "http://toomanycharacters"^^xsd:anyURI ; sh:resultMessage "Too many characters"@en ; sh:resultMessage "Zu viele Zeichen"@de ; sh:sourceConstraintComponent sh:MaxLengthConstraintComponent ; sh:sourceShape _:b2 ; ] ] .
Shapes can have values for the property sh:message.
The values of sh:message in a shape are either xsd:string literals or literals with a language tag. A shape should not have
more than one value for sh:message with the same language tag.
If a shape has at least one value for sh:message in the shapes graph, then all validation results produced as a result of the shape will have
exactly these messages as their value of sh:resultMessage, i.e. the values will be copied from the shapes graph into the results graph. (Note that in SHACL-SPARQL, SPARQL-based constraints and SPARQL-based constraint components provide additional means to declare such messages.)
The remainder of this section is informative.
The example from the previous section uses this mechanism to supply the second validation result with two messages. See the section on sh:resultMessage in the validation results on further
details on how the values of sh:resultMessage are populated.
Shapes can have at most one value for the property sh:deactivated.
The value of sh:deactivated in a shape must be either true or false.
A shape that has the value true for the property sh:deactivated is called deactivated.
All RDF terms conform to a deactivated shape.
The remainder of this section is informative.
Use cases of this feature include shape reuse and debugging. In scenarios where shapes from other graphs or files are imported into a given shapes graph,
sh:deactivated can be set to true in the local shapes graph for imported shapes to exclude shapes that do not apply in the current application context. This makes it possible to reuse SHACL graphs developed
by others even if you disagree with certain assumptions made by the original authors. If a shape author anticipates that a shape may need to be disabled or modified by others, it is a good practice to use IRIs instead of blank nodes for the actual shapes. For example, a property shape for the property ex:name at the shape ex:PersonShape may have the IRI ex:PersonShape-name. Another typical use case of sh:deactivated is during the development and testing of shapes,
to (temporarily) disable certain shapes.
The following example illustrates the use of sh:deactivated to deactivate a shape. In cases where shapes are imported from other graphs, the sh:deactivated true triple would be in the importing graph.
ex:PersonShape
a sh:NodeShape ;
sh:targetClass ex:Person ;
sh:property ex:PersonShape-name .
ex:PersonShape-name
a sh:PropertyShape ;
sh:path ex:name ;
sh:minCount 1 ;
sh:deactivated true .
With the following data, no constraint violation will be reported even though the instance does not have any value for ex:name.
ex:JohnDoe a ex:Person .
A node shape is a shape in the shapes graph that
is not the subject of a triple with sh:path as its predicate. It is recommended, but not required, for a node shape to be declared as a SHACL instance of sh:NodeShape.
SHACL instances of sh:NodeShape cannot have a value for the property sh:path.
Informally, node shapes specify constraints that need to be met with respect to focus nodes. In contrast to property shapes they primarily apply to the focus node itself, not to its property values.
A property shape is a shape in the shapes graph
that is the subject of a triple that has sh:path as its predicate.
A shape has at most one value for sh:path.
Each value of sh:path in a shape must be a well-formed SHACL property path. It is recommended, but not required, for a property shape to be declared as a SHACL instance of sh:PropertyShape.
SHACL instances of sh:PropertyShape have one value for the property sh:path.
Informally, property shapes specify constraints that need to be met with respect to nodes that can be reached from the
focus node either by directly following a given property (specified as an IRI) or any other SHACL property path, specified using sh:path.
Note that the definitions of well-formed property shapes and node shapes make these two sets of nodes disjoint.
The following example illustrates some syntax variations of property shapes.
ex:ExampleNodeShapeWithPropertyShapes a sh:NodeShape ; sh:property [ sh:path ex:email ; sh:name "e-mail" ; sh:description "We need at least one email value" ; sh:minCount 1 ; ] ; sh:property [ sh:path (ex:knows ex:email) ; sh:name "Friend's e-mail" ; sh:description "We need at least one email for everyone you know" ; sh:minCount 1 ; ] . ex:ExamplePropertyShape a sh:PropertyShape ; sh:path ex:email ; sh:description "We need at least one email value" ; sh:minCount 1 .
SHACL includes RDF terms to represent the following subset of SPARQL property paths:
PredicatePath, InversePath, SequencePath, AlternativePath,
ZeroOrMorePath, OneOrMorePath and ZeroOrOnePath.
The following sub-sections provide syntax rules of well-formed SHACL property paths together with mapping rules to SPARQL 1.1 property paths. These rules define the path mapping path(p,G) in an RDF graph G of an RDF term p that is a SHACL property path in G. Two SHACL property paths are considered equivalent paths when they
map to the exact same SPARQL property paths.
A node in an RDF graph is a well-formed SHACL property path p if it satisfies exactly one of the syntax rules in the following sub-sections.
A node p is not a well-formed SHACL property path if p is a blank node and any path mappings of p directly or transitively reference p.
The following example illustrates some valid SHACL property paths, together with their SPARQL 1.1 equivalents.
SPARQL Property path: ex:parent SHACL Property path: ex:parent SPARQL Property path: ^ex:parent SHACL Property path: [ sh:inversePath ex:parent ] SPARQL Property path: ex:parent/ex:firstName SHACL Property path: ( ex:parent ex:firstName ) SPARQL Property path: rdf:type/rdfs:subClassOf* SHACL Property path: ( rdf:type [ sh:zeroOrMorePath rdfs:subClassOf ] ) SPARQL Property path: ex:father|ex:mother SHACL Property path: [ sh:alternativePath ( ex:father ex:mother ) ]
A predicate path is an IRI.
If p is a predicate path then path(p,G) is a SPARQL PredicatePath with p as iri.
A sequence path is a blank node that is a SHACL list with at least two members and each member is a well-formed SHACL property path.
If p is a sequence path in G with list members
v1, v2, ..., vn then path(p,G) is a SPARQL SequencePath of
path(v1,G) as elt1, and the results of the path mapping of the list node of v2 as elt2.
Informal note: the nodes in such a SHACL list should not have values for other properties beside rdf:first and rdf:rest.
An alternative path is a blank node that is the subject of exactly one triple in G. This
triple has sh:alternativePath as predicate, L as object, and L is a SHACL list with at least two members and each member of L is a well-formed SHACL property path.
If p is an alternative path in G then, for the members of its SHACL list L:
v1, v2, ..., vn,
path(p,G) is a SPARQL AlternativePath with
path(v1,G) as elt1 followed by an AlternativePath for v2 as elt2, ..., up to path(vn,G).
An inverse path is a blank node that is the subject of exactly one triple in G. This triple has sh:inversePath as predicate, and the object v is a well-formed SHACL property path.
If p is an inverse path in G then path(p,G) is a SPARQL InversePath with path(v,G) as its
elt.
A zero-or-more path is a blank node that is the subject of exactly one triple in G. This triple has sh:zeroOrMorePath as predicate,
and the object v is a well-formed SHACL property path.
If p is a zero-or-more path in G then path(p,G) is a SPARQL ZeroOrMorePath with path(v,G) as its elt.
A one-or-more path is a blank node that is the subject of exactly one triple in G. This triple has sh:oneOrMorePath as predicate,
and the object v is a well-formed SHACL property path.
If p is a one-or-more path in G then path(p,G) is a SPARQL OneOrMorePath with path(v,G) as its elt.
A zero-or-one path is a blank node that is the subject of exactly one triple in G. This triple has sh:zeroOrOnePath as predicate,
and the object v is a well-formed SHACL property path.
If p is a zero-or-one path in G then path(p,G) is a SPARQL ZeroOrOnePath with path(v,G) as its elt.
This section is non-normative.
While the previous sections introduced properties that represent validation conditions, this section covers properties that are ignored by SHACL processors. The use of these so-called non-validating properties is entirely optional and not subject to formal interpretation contracts. They MAY be used for purposes such as form building or predictable printing of RDF files.
Property shapes may have one or more values for sh:name to provide human-readable labels for the property in the target where it appears. If present,
tools SHOULD prefer those locally specified labels over globally specified labels at the rdf:Property itself. For example, if a form displays a node that is in the target of
a given property shape with an sh:name, then the tool SHOULD use the provided name. Similarly, property shape may have values for sh:description to provide descriptions of the property in the given context. Both sh:name and sh:description may have multiple values, but should only
have one value per language tag.
Property shapes may have one value for the property sh:order to indicate the relative order of the property shape for purposes such as form building.
The values of sh:order are decimals.
sh:order is not used for validation purposes and may be used with any type of subjects. If present at property shapes, the recommended use of sh:order is to sort the property shapes in an ascending order,
for example so that properties with smaller order are placed above (or to the left) of properties with larger order.
Property shapes may link to an SHACL instance of the class sh:PropertyGroup using the property sh:group to indicate that the shape
belongs to a group of related property shapes. Each group may have additional triples that serve application purposes, such as an rdfs:label for form building. Groups may also have an sh:order property
to indicate the relative ordering of groups within the same form.
Property shapes may have a single value for sh:defaultValue. The default value does not have fixed semantics in SHACL, but MAY be used by user interface tools to pre-populate input
widgets. The value type of the sh:defaultValue should align with the specified sh:datatype or sh:class of the same shape.
The following example illustrates the use of these various features together.
ex:PersonFormShape a sh:NodeShape ; sh:property [ sh:path ex:firstName ; sh:name "first name" ; sh:description "The person's given name(s)" ; sh:order 0 ; sh:group ex:NameGroup ; ] ; sh:property [ sh:path ex:lastName ; sh:name "last name" ; sh:description "The person's last name" ; sh:order 1 ; sh:group ex:NameGroup ; ] ; sh:property [ sh:path ex:streetAddress ; sh:name "street address" ; sh:description "The street address including number" ; sh:order 11 ; sh:group ex:AddressGroup ; ] ; sh:property [ sh:path ex:locality ; sh:name "locality" ; sh:description "The suburb, city or town of the address" ; sh:order 12 ; sh:group ex:AddressGroup ; ] ; sh:property [ sh:path ex:postalCode ; sh:name "postal code" ; sh:name "zip code"@en-US ; sh:description "The postal code of the locality" ; sh:order 13 ; sh:group ex:AddressGroup ; ] . ex:NameGroup a sh:PropertyGroup ; sh:order 0 ; rdfs:label "Name" . ex:AddressGroup a sh:PropertyGroup ; sh:order 1 ; rdfs:label "Address" .
A form building application MAY use the information above to display information as follows:
| first name: | John |
| last name: | Doe |
| street address: | 123 Silverado Ave |
| locality: | Cupertino |
| zip code: | 54321 |
Validation takes a data graph and a shapes graph as input and produces a validation report containing the results of the validation. Conformance checking is a simplified version of validation, producing a boolean result. A system that is capable of performing validation is called a processor, and the verb processing is sometimes used to refer to the validation process.
SHACL defines an RDF Validation Report Vocabulary that can be used by processors that produce validation reports as RDF results graphs. This specification uses the SHACL results vocabulary for the normative definitions of the validators associated with the constraint components. Only SHACL implementations that can produce all of the mandatory properties of the Validation Report Vocabulary are standards-compliant.
A shapes graph is an RDF graph containing zero or more shapes that is passed into a SHACL validation process so that a data graph can be validated against the shapes.
The remainder of this section is informative.
Shapes graphs can be reusable validation modules that can be cross-referenced with the predicate owl:imports. As a pre-validation step, SHACL processors SHOULD extend the originally provided shapes graph by transitively following and importing all referenced shapes graphs through the owl:imports predicate. The resulting graph forms the input shapes graph for validation and MUST NOT be further modified during the validation process.
In addition to shape declarations, the shapes graph may contain additional information for the SHACL processor such as sh:entailment statements.
Any RDF graph can be a data graph.
The remainder of this section is informative.
A data graph is one of the inputs to the SHACL processor for validation. SHACL processors treat it as a general RDF graph and makes no assumption about its nature. For example, it can be an in-memory graph or a named graph from an RDF dataset or a SPARQL endpoint.
SHACL can be used with RDF graphs that are obtained by any means, e.g. from the file system, HTTP requests, or RDF datasets. SHACL makes no assumptions about whether a graph contains triples that are entailed from the graph under any RDF entailment regime.
The data graph is expected to include all the ontology axioms related to the data and especially all the
rdfs:subClassOf triples in order for SHACL to correctly identify class targets and validate Core SHACL constraints.
A data graph can include triples used to suggest one or more graphs to a SHACL processor with the predicate sh:shapesGraph.
Every value of sh:shapesGraph is an IRI representing a graph that SHOULD be included into the shapes graph used to validate the data graph.
In the following example, a SHACL processor SHOULD use the union of ex:graph-shapes1 and ex:graph-shapes2 graphs (and their owl:imports) as the shapes graph when validating the given graph.
<http://example.com/myDataGraph> sh:shapesGraph ex:graph-shapes1 ; sh:shapesGraph ex:graph-shapes2 .
Validation is a mapping from some input to validation results, as defined in the following paragraphs.
Validation of a data graph against a shapes graph: Given a data graph and a shapes graph, the validation results are the union of results of the validation of the data graph against all shapes in the shapes graph.
Validation of a data graph against a shape: Given a data graph and a shape in the shapes graph, the validation results are the union of the results of the validation of all focus nodes that are in the target of the shape in the data graph.
Validation of a focus node against a shape: Given a focus node in the data graph and a shape in the shapes graph, the validation results are the union of the results of the validation of the focus node against all constraints declared by the shape, unless the shape has been deactivated, in which case the validation results are empty.
Validation of a focus node against a constraint: Given a focus node in the
data graph and a constraint of kind C in the shapes graph, the validation results are defined by the validators of the constraint component C. These validators typically take as input the focus node, the specific values of the parameters of C of the constraint in the shapes graph,
and the value nodes of the shape that declares the constraint.
During validation, the data graph and the shapes graph MUST remain immutable, i.e. both graphs at the end of the validation MUST be identical to the graph at the beginning of validation. SHACL processors MUST NOT change the graphs that they use to construct the shapes graph or the data graph, even if these graphs are part of an RDF store that allows changes to its stored graphs. SHACL processors MAY store the graphs that they create, such as a graph containing validation results, and this operation MAY change existing graphs in an RDF store, but not any of the graphs that were used to construct the shapes graph or the data graph. SHACL processing is thus idempotent.
Validation and conformance checking can result in a failure. For example, a particular SHACL processor might allow recursive shapes but report a failure if it detects a loop within the data. Failures can also be reported due to resource exhaustion. Failures are signalled through implementation-specific channels.
If the shapes graph contains ill-formed nodes, then the result of the validation process is undefined. A SHACL processor SHOULD produce a failure in this case. See also 3.6.1.3 Syntax Checking of Shapes Graph (sh:shapesGraphWellFormed).
The following properties are the so-called shape-expecting constraint parameters in SHACL Core:
The following properties are the so-called list-taking constraint parameters in SHACL Core:
A shape s1 in an RDF graph G refers to shape s2 in G if it has s2 as value for some non-list-taking, shape-expecting parameter of some constraint component or s2 as a member of the value for some list-taking, shape-expecting parameter of some constraint component. A shape in an RDF graph G is a recursive shape in G if it is related to
itself by the transitive closure of the refers relationship in G.
The validation with recursive shapes is not defined in SHACL and is left to SHACL processor implementations. For example, SHACL processors may support recursion scenarios or produce a failure when they detect recursion.
The remainder of this section is informative.
The recursion policy above has been selected to support a large variety of implementation strategies. By leaving recursion undefined, implementations may chose to not support recursion so that they can issue a static set of SPARQL queries (against SPARQL end points) without having to support cycles. The Working Group is aware that other implementations may support recursion and that some shapes graphs may rely on these specific characteristics. The expectation is that future work, for example in W3C Community Groups, will lead to the definition of specific dialects of SHACL where recursion is well-defined.
A focus node conforms to a shape if and only if the set of result of the validation of the focus node against the shape is empty and no failure has been reported by it.
Conformance checking produces true if and only if a given focus node
conforms to a given shape, and false otherwise.
Note that some constraint components of SHACL Core (e.g., those of sh:not, sh:or and sh:node) rely on conformance checking.
In these cases, the validation results used to determine the outcome of conformance checking are separated from those of the surrounding validation process
and typically do not end up in the same validation report (except perhaps as values of sh:detail).
The validation report is the result of the validation process that reports the conformance and the set of all validation results. The validation report is described with the SHACL Validation Report Vocabulary as defined in this section. This vocabulary defines the RDF properties to represent structural information that may provide guidance on how to identify or fix violations in the data graph.
SHACL-compliant processors MUST be capable of returning a validation report with all required validation results described in this specification. SHACL-compliant processors MAY support optional arguments that make it possible to limit the number of returned results. This flexibility is for example needed in some large-scale dataset validation use cases.
The following graph represents an example of a validation report for the validation of a data graph that conforms to a shapes graph.
[ a sh:ValidationReport ; sh:conforms true ; ] .
The following graph represents an example of a validation report for the validation of a data graph that does not conform to a shapes graph. Note that the specific value of sh:resultMessage is not mandated by SHACL and considered
implementation-specific.
[ a sh:ValidationReport ; sh:conforms false ; sh:result [ a sh:ValidationResult ; sh:resultSeverity sh:Violation ; sh:focusNode ex:Bob ; sh:resultPath ex:age ; sh:value "twenty two" ; sh:resultMessage "ex:age expects a literal of datatype xsd:integer." ; sh:sourceConstraintComponent sh:DatatypeConstraintComponent ; sh:sourceShape ex:PersonShape-age ; ] ] .
The result of a validation process is an RDF graph with exactly one SHACL instance of
sh:ValidationReport. The RDF graph MAY contain additional information such as provenance metadata.
Each SHACL instance of sh:ValidationReport in the results graph has exactly one value for the property sh:conforms and the value is of datatype xsd:boolean. It represents the outcome of the
conformance checking. The value of sh:conforms is true if and only if the validation did not produce any validation results, and false otherwise.
For every validation result that is produced by a validation process (except those mentioned in the context of conformance checking),
the SHACL instance of sh:ValidationReport in the results graph has a value for the property sh:result. Each value of sh:result is a SHACL instance of the class sh:ValidationResult.
SHACL validation engines are not strictly required to check whether the shapes graph is well-formed.
Implementations that do perform such checks (e.g., when the shapes graph is installed in the system, or before or during the validation) SHOULD use the property sh:shapesG[Truncated]