The vocabulary defining the Shapes Constraint Language (SHACL).
Defines arbitrary constraints on the matching resources. Use sh:property for structural property declarations.
Declares that a given property is relevant for matching resources.
Declares that a given incoming reference property is relevant for matching resources.
Links a Shape to other Shapes that the tested nodes need to fulfill before the constraints of the shape are evaluated.
Links a Shape to Scopes that produce the focus nodes that the shape applies to.
Links a Shape to a class, establishing that all instances of that class are expected to have this shape.
The metaclass for classes that are also shapes.
True to indicate that this class is not expected to have direct instances.
True to indicate that this class is only meant to be used inside of the graph that it has been defined in. This is often used to discourage instantiation outside of controlled scenarios. User interfaces may hide private classes from selection widgets.
The class of literal values, eg. textual strings and integers.
The union of xsd:string and rdf:langString, to be used in cases where a property can either be a string or a string with a language tag. This type should never be used directly as the type of literals.
A collection of RDF triples identified by a URI. In a Linked Data scenario, a graph should be accessible from its URI via content negotiation in formats such as Turtle and JSON-LD.
Links a graph with an entailment regime that its shape definitions shall be evaluated with.
Links a graph with other graphs that shall be included into the query graph over which constraints are validated. This is a transitive property, i.e. includes of includes are also added.
Links a graph with other graphs that shall be included into the shapes graph that includes shape and template definitions as well as the SHACL metamodel.
The class of RDF node kinds: literals, blank nodes and IRIs.
Abstract superclass of macro components of a SHACL library, especially Functions and Templates. Macros can take arguments, which are constraints that are different from PropertyConstraints in that they can only have at most one value.
The same predicate can only be used once at all Arguments.
Duplicate Argument for the same predicate {?argPredicate}
SELECT ?this (?this AS ?subject) (?predicate AS ?argPredicate) (?argument1 AS ?object) WHERE { ?this rdfs:subClassOf* ?class1 . ?class1 sh:argument ?argument1 . ?argument1 sh:predicate ?predicate . ?this rdfs:subClassOf* ?class2 . ?class2 sh:argument ?argument2 . FILTER (?argument1 != ?argument2) . ?argument2 sh:predicate ?predicate . }
A macro implementing a SPARQL function, backed by a SPARQL ASK or SELECT query.
True to indicate that this function will always return the same values for the same combination of arguments, regardless of the query graphs. Engines can use this information to cache and reuse previous function calls.
The recommended abstract superclass for all validation functions that take a value as an argument and return a boolean result (true if the value is OK).
A macro that acts as an abstraction of a (reusable) SPARQL query. The query can be parameterized by the supplied arguments.
Outlines how human-readable labels of instances of this template class shall be produced. The values must be strings that can contain {?argName} as placeholders for the actual values of the given argument. There may be multiple values, for different languages.
A profile is a collection of constraint templates and scope templates. Profiles can be used to group together templates with similar complexity. Tools can indicate that they support specific profiles only.
A constraint template supported by the profile.
A scope template supported by the profile.
Points at another profile that forms a sub-set of this profile.
The meta-class of result types that can be instantiated to represent validation results.
Instances of subclasses of this class can be constructed during constraint validation, to represent a single validation result.
Can link a result with other results that provide more details. This is especially useful to describe violations against nested patterns or shapes.
A human-readable message explaining the cause of the result. Multiple values are possible assuming they have different languages.
The subject of triples involved in this result.
The predicate of triples involved in this result.
The object of triples involved in this result.
The focus node evaluated when the result was produced.
A validation result representing a constraint violation.
A non-critical constraint violation indicating a warning.
A constraint violation indicating an error.
An error that cannot be recovered and further evaluation may terminate immediately. Engines may decide to perform the validation of potentially fatal constraints first.
Defines the rules to derive the values of a given annotation property as extra values for a constraint violation.
The annotation property that shall be set.
The name of the SPARQL variable from the SELECT clause that shall be used for the values.
An abstract superclass of scopes. Scopes are either template calls or native scopes with an executable body.
A scope that has a native executable body attached to it.
A template that is used to compute a scope.
A scope that is instantiating a template.
A scope that includes all objects in the graph, except literals.
SELECT DISTINCT ?this WHERE { ?anySubject ?anyPredicate ?this . FILTER (!isLiteral(?this)) . }
A scope that includes all subjects in the graph.
SELECT DISTINCT ?this WHERE { ?this ?anyPredicate ?anyObject . }
A scope that includes all objects that have at least one value for a given predicate.
SELECT DISTINCT ?this WHERE { ?any ?predicate ?this . }
A scope that includes all subjects that have at least one value for a given predicate.
SELECT DISTINCT ?this WHERE { ?this ?predicate ?any . }
An abstract superclass of constraints. Constraints are either template calls or "native" constraints with an executable body.
Links a constraint to Shapes that the tested nodes need to fulfill before the constraint is evaluated.
Specifies the severity to use for any constraint violation produced by this constraint. Defaults to sh:Error for native constraints. For template constraints it uses the severity of the template by default.
A constraint that has a native executable body attached with it.
Specifies the default sh:message(s) to produce for any constraint violation. May have multiple values for different languages.
Specifies the default sh:predicate to produce for any constraint violation.
A human-readable explanation of this constraint. May have multiple values for different languages.
Result annotations provide information about additional properties that the constructed constraint violations shall have.
A template that is used for constraint validation.
Specifies the default rdf:type to produce for any constraint violation.
A constraint template that points to a function that validates one given value at a time.
A boolean function that takes a given value as its first argument. Additional arguments are passed into the function if their predicate matches the template's arguments. If the function returns true then the value is valid.
A value constraint template that validates all objects of triples that have the given focus node as subject and the given predicate.
Inverse property value constraint template
A value constraint template that validates all subjects of triples that have the given focus node as object and the given predicate.
A constraint that is instantiating a template.
Shared superclass for templates that take a predicate as one of their arguments.
A display label for input forms etc. By default, the global rdfs:label of the predicate should be used. Multiple values (for different languages) are supported.
A description of the role of the predicate to users. Multiple values (for different languages) are supported.
Enforces a constraint that the value of an argument must be a literal of a certain datatype. sh:text is recommended if the values shall be either strings or string with language tags.
The datatype that all values of the property must have.
Arguments cannot have more than one value.
SELECT ?this (?this AS ?subject) ?predicate WHERE { FILTER EXISTS { ?this ?predicate ?value1 . ?this ?predicate ?value2 . FILTER (?value1 != ?value2) . } }
Abstract argument value class constraint
Enforces a constraint that the value of an argument must be of a certain type. This will accept instances of subclasses.
The type that all values of the property must have, based on the semantics defined by the function sh:hasValueClass.
Values must be instances of {?valueClass}
Enforces a constraint that a non-optional argument must have a value, similar to minCount = 1, unless it has been declared optional, or a sh:defaultValue exists.
The default value of this argument, to be used if no other value has been specified.
True to indicate that the property does not require a value. By default, the value is required.
True to indicate that the property does not require a value when used by a subclass template. If set to true, then instances of subclasses do not need to fill in all required arguments - incomplete templates will simply not be executed. By default, the value is required.
SELECT ?this (?this AS ?subject) ?predicate WHERE { FILTER (!bound(?defaultValue) && !?optional && !?optionalWhenInherited && NOT EXISTS { ?this ?predicate ?any }) . }
Declares an argument that gets mapped to a variable in the parameterized SPARQL query.
Argument {?predicate} : {?datatype}{?valueClass}
The index of this argument, especially to determine the order of arguments in a function call. Values should be 0, 1, 2 etc. The default index for sh:arg1 is 0 etc.
Arguments cannot have both ?datatype and ?valueClass.
SELECT * WHERE { FILTER EXISTS { ?this sh:datatype ?value1 . ?this sh:valueClass ?value2 . } }
Abstract allowed values property constraint
Specifies the allowed values for a property by pointing to a List of nodes.
The rdf:List containing the allowed values of the property.
Enforces a constraint on the cardinality of the property using minCount and maxCount. By default, a property may have 0 to unlimited number of values.
The minimum number of values that the property must have. Defaults to 0.
The maximum number of values that the property must have. Defaults to unlimited.
Required value count [{?minCount}..{?maxCount}] but found {?count}
SELECT ?this (?this AS ?subject) ?predicate ?count WHERE { BIND (sh:valueCount(?this, ?predicate) AS ?count) . FILTER ((?count < ?minCount) || (bound(?maxCount) && (?count > ?maxCount))) . }
Enforces a constraint that all values of the property must be literals of a certain datatype. This will accept strings with language tags instead of xsd:string.
The datatype that all values of the property must have. sh:text is recommended if the values shall be either strings or string with language tags.
Abstract direct value type property constraint
Enforces a constraint that all values of the property must be of a certain (direct) type. In contrast to sh:valueClass this does not include instances of subclasses.
The type that all values of the property must have, excluding subclasses.
Values must be direct instances of {?directValueType}
Specifies that the given property must have the specified value (it may also have others).
SELECT ?this (?this AS ?subject) ?predicate ?hasValue WHERE { FILTER NOT EXISTS { ?this ?predicate ?hasValue } }
Specifies the valid node kind of a property.
The node kind that all values of the property must be of.
Abstract qualified value shape property constraint
Enforces a constraint that a certain number of values of the property must have a certain shape.
The minimum number of values that must have the shape.
The maximum number of values that must have the shape.
Violation of qualified value shape constraint {?qualifiedValueShape}: expected [{?qualifiedMinCount}..{?qualifiedMaxCount}], found {?count}
SELECT ?this (?this AS ?subject) ?predicate ?qualifiedValueShape ?qualifiedMinCount ?qualifiedMaxCount ?count ?error WHERE { BIND (sh:valuesWithShapeCount(?this, ?predicate, ?qualifiedValueShape, ?shapesGraph) AS ?count) . BIND (!bound(?count) AS ?error) . FILTER IF(?error, true, ((?count < ?qualifiedMinCount) || (bound(?qualifiedMaxCount) && (?count > ?qualifiedMaxCount)))) . }
Abstract value class property constraint
Enforces a constraint that all values of the property must be of a certain type. For resources this will accept instances of subclasses. Untyped blank nodes are allowed if a defaultValueType has been specified.
Abstract value shape property constraint
Enforces a constraint that all values of the property must have a certain shape.
Value does not fulfill the constraints of shape {?valueShape}
SELECT ?this (?this AS ?subject) ?predicate ?object ?valueShape ?error WHERE { ?this ?predicate ?object . BIND (sh:hasShape(?object, ?valueShape, ?shapesGraph) AS ?hasShape) . BIND (!bound(?hasShape) AS ?error) . FILTER (?error || !?hasShape) . }
Specifies the minimum and maximum string length of values.
The minimum string length permitted for values of this property.
The maximum string length permitted for values of this property.
Abstract max exclusive property constraint
Specifies an (exclusive) maximum value for literal values.
The exclusive maximum value permitted for this property: ?value < ?maxExclusive
Values must be less than {?maxExclusive}
Abstract max inclusive property constraint
Specifies an (inclusive) maximum value for literal values.
The inclusive maximum value permitted for this property: ?value <= ?maxInclusive
Values must be less than or equal to {?maxInclusive}
Abstract min exclusive property constraint
Specifies an (exclusive) minimum value for literal values.
The exclusive minimum value permitted for this property: ?value > ?minExclusive
Values must be greater than {?minExclusive}
Abstract min inclusive property constraint
Specifies an (inclusive) minimum value for literal values.
The inclusive minimum value permitted for this property: ?value >= ?minInclusive
Values must be greater than or equal to {?minInclusive}
Specifies a regular expression that all values of the property need to match.
The (regular expression) pattern for values of this property.
Values must match the pattern {?pattern}
Declares the structural constraints for a property at the associated class. The supported arguments are inherited from the superclasses.
Property {?predicate} : {?datatype}{?valueClass} [{?minCount}..{?maxCount}]
A default value that could be used to pre-populate input forms etc. This has no formal meaning otherwise.
Property constraints cannot have both datatype and valueClass or directValueType.
SELECT ?this WHERE { FILTER EXISTS { ?this sh:datatype ?datatype . ?this sh:valueClass|sh:directValueType ?any . } }
Abstract allowed values inverse property constraint
Specifies the allowed values for an inverse property by pointing to a List of nodes.
The rdf:List containing the allowed values of the inverse property.
Abstract count inverse property constraint
Enforces a constraint on the cardinality of an incoming property using minCount and maxCount. By default, an inverse property may have 0 to unlimited number of values.
The minimum number of values that the inverse property must have. Defaults to 0.
The maximum number of values that the inverse property must have. Defaults to unlimited.
Inverse property must have [{?minCount}..{?maxCount}] values, but found {?count}
SELECT ?this (?this AS ?object) ?predicate ?minCount ?maxCount ?count WHERE { BIND (sh:inverseValueCount(?this, ?predicate) AS ?count) . FILTER ((?count < ?minCount) || (bound(?maxCount) && (?count > ?maxCount))) . }
Abstract value class inverse property constraint
Enforces a constraint that all incoming values of the property must be of a certain type. This will accept instances of subclasses..
The type that all values of the inverse property must have, based on the semantics defined by the function sh:hasValueClass.
The values of sh:valueClass cannot be blank nodes.
SELECT ?this (?this AS ?subject) (?valueClass AS ?object) WHERE { ?this sh:valueClass ?valueClass . FILTER isBlank(?valueClass) . }
Inverse values must be instances of {?valueClass}
Abstract value shape inverse property constraint
Enforces a constraint that all inverse values of the property must have a certain shape.
The shape that the inverse values must have.
Inverse value does not fulfill the constraints of shape {?valueShape}
SELECT ?this (?this AS ?object) ?predicate ?subject ?valueShape ?error WHERE { ?subject ?predicate ?this . BIND (sh:hasShape(?subject, ?valueShape, ?shapesGraph) AS ?hasShape) . BIND (!bound(?hasShape) AS ?error) . FILTER (?error || !?hasShape) . }
Declares the structural constraints for an incoming property at the associated class. The supported arguments are inherited from the superclasses.
Inverse property {?predicate} : {?valueClass} [{?minCount}..{?maxCount}]
Triggers an error for each triple of the focus node that has a predicate that is not explicitly enumerated using sh:property in the surrounding shape.
A List of predicates that are permitted regardless of whether they have been declared as sh:property. Could be used to allow sh:nodeShape or rdf:type.
SELECT ?this (?this AS ?subject) ?predicate ?object WHERE { ?this ?predicate ?object . FILTER (NOT EXISTS { GRAPH ?shapesGraph { ?currentShape sh:property/sh:predicate ?predicate . } } && (!bound(?ignoredProperties) || NOT EXISTS { GRAPH ?shapesGraph { ?ignoredProperties rdf:rest*/rdf:first ?predicate . } })) }
A singleton instance of sh:ClosedShapeConstraint that can be shared between multiple shape definitions.
Enforces a constraint that the focus node must not have a given shape, essentially negating the conditions represented by the shape.
SELECT ?this ?error WHERE { BIND (sh:hasShape(?this, ?shape, ?shapesGraph, true) AS ?hasShape) . BIND (!bound(?hasShape) AS ?error) . FILTER (?error || ?hasShape) . }
Enforces a constraint that all of the provided shapes must be valid for the focus resource.
A list of shapes that will be validated.
SELECT ?this ?error WHERE { BIND (sh:walkShapesList(?shapes, false, ?this, ?shapesGraph) AS ?result) . BIND (!bound(?result) AS ?error) . FILTER COALESCE(?result, true) . }
Enforces a constraint that at least one of several provided shapes must be valid for the focus resource.
SELECT ?this ?error WHERE { BIND (sh:walkShapesList(?shapes, true, ?this, ?shapesGraph) AS ?result) . BIND (!bound(?result) AS ?error) . FILTER COALESCE(!?result, true) . }
Enforces a constraint that exactly one of multiple provided shapes must be valid for the focus resource.
SELECT ?this ?error WHERE { BIND (sh:validShapeCount(?this, ?shapes, ?shapesGraph) AS ?count) BIND (!bound(?count) AS ?error) . FILTER IF(?error, true, ?count != 1) . }
Checks whether a given node (?value) is a literal with a given datatype (?datatype). If the datatype is sh:text, then the function will either accept xsd:string or rdf:langString.
ASK { { FILTER isLiteral(?value) . } . BIND (datatype(?value) AS ?realDatatype) . FILTER ((?realDatatype = ?datatype) || (?datatype = sh:text && ?realDatatype IN (rdf:langString, xsd:string))) . }
Checks whether a given node (?value) has a given class (?directValueType) as its rdf:type.
The type that all value must have, excluding subclasses.
ASK { ?value a ?directValueType . }
Checks whether a given string (?value) has a length within a given minimum and maximum string length.
The minimum string length (defaults to 0 if unspecified).
The maximum string length (defaults to unlimited).
ASK { BIND (STRLEN(str(?value)) AS ?valueLength) . FILTER (bound(?valueLength) && (?valueLength >= COALESCE(?minLength, 0)) && (!bound(?maxLength) || ?valueLength <= ?maxLength)) . }
Checks whether a given node (?value) has value less than (<) the provided ?maxExclusive. Returns false if this cannot be determined, e.g. because values do not have comparable types.
Checks whether a given node (?value) has value less than or equal to (<=) the provided ?maxInclusive. Returns false if this cannot be determined, e.g. because values do not have comparable types.
ASK { FILTER (?value <= ?maxInclusive) }
Checks whether a given node (?value) has value greater than (>) the provided ?minExclusive. Returns false if this cannot be determined, e.g. because values do not have comparable types.
Checks whether a given node (?value) has value greater than or equal to (>=) the provided ?minInclusive. Returns false if this cannot be determined, e.g. because values do not have comparable types.
ASK { FILTER (?value >= ?minInclusive) }
Checks whether a given node (?value) has a given sh:NodeKind (?nodeKind). For example, sh:hasNodeKind(42, sh:Literal) = true.
ASK { FILTER ((isIRI(?value) && ?nodeKind = sh:IRI) || (isLiteral(?value) && ?nodeKind = sh:Literal) || (isBlank(?value) && ?nodeKind = sh:BlankNode)) . }
Checks whether the string representation of a given node (?value) matches a given regular expression (?pattern). Returns false if the value is a blank node.
ASK { FILTER (!isBlank(?value) && regex(str(?value), ?pattern)) }
Validates whether a given resource (?arg1) fulfills all error-level constraints defined for a given shape (?arg2). This creates a (possibly recursive) constraint validator equivalent to the validateNodeAgainstShape operation. The function returns an error, i.e. no result, if the validation could not be completed, e.g. due to an unsupported recursion or an unsupported extension language. Therefore the function should not be called inside of FILTER statements directly, but rather with BIND.
The shape containing the constraints that need to be validated.
The graph containing the shape definitions.
If set to true then any recursive occurrence of the same resource against the same shape will fail (result=undefined).
Checks whether a given node (?value) is an instance of a given class (?valueClass) or its subclasses. If ?valueClass is rdf:Property then the function returns true if ?value is an untyped IRI.
ASK { { { FILTER (isIRI(?value) || isBlank(?value)) . } . ?class (rdfs:subClassOf)* ?valueClass . ?value a ?class . } UNION { # Allow untyped resources for rdfs:Resource and rdf:Property FILTER ((isIRI(?value) || isBlank(?value)) && (?valueClass = rdfs:Resource || ?valueClass = rdf:Property) && NOT EXISTS { ?value a ?any }) . } UNION { # Allow untyped blank nodes with rdf:first if expected type is rdf:List FILTER (?valueClass = rdf:List && isBlank(?value) && EXISTS { ?value rdf:first ?any }) . } }
Gets the number of values of a given property (?arg2) at a given object (?arg1). The result is the number of matches of (?subject, ?arg2, ?arg1).
SELECT ((COUNT(?subject)) AS ?result) WHERE { ?subject ?arg2 ?arg1 . }
The rdf:List containing the allowed values.
ASK { FILTER EXISTS { GRAPH ?shapesGraph { ?allowedValues (rdf:rest*)/rdf:first ?value . } } }
Gets the 'first' value of a given property (?arg2) at a given subject (?arg1). The behavior is arbitrary if multiple values are present.
SELECT ?object WHERE { ?arg1 ?arg2 ?object . }
Counts the number of shapes from a given rdf:List (?arg2) defined in a given shapes graph (?arg3) where a given focus node (?arg1) returns no error-level constraint violations. The function produces an error if one of the shapes validated to a fatal error.
# The SUM will fail with an error if one of the operands is not a number # (this mechanism is used to propagate errors from sh:hasShape calls) SELECT (SUM(?s) AS ?result) WHERE { GRAPH ?arg3 { ?arg2 rdf:rest*/rdf:first ?shape . } BIND (sh:hasShape(?arg1, ?shape, ?arg3, true) AS ?hasShape) . BIND (IF(bound(?hasShape), IF(?hasShape, 1, 0), 'error') AS ?s) . }
Gets the number of values of a given property (?arg2) at a given subject (?arg1). The result is the number of matches of (?arg1, ?arg2, ?object).
SELECT ((COUNT(?object)) AS ?result) WHERE { ?arg1 ?arg2 ?object . }
Counts the number of values from a given subject (?arg1) / predicate (?arg2) combination that do not produce any error-level constraint violations for a given shape (?arg3) in a given shapes graph (?arg4). The function produces an error if one of the shapes validated to a fatal error.
# The SUM will fail with an error if one of the operands is not a number # (this mechanism is used to propagate errors from sh:hasShape calls) SELECT (SUM(?s) AS ?result) WHERE { ?arg1 ?arg2 ?value . BIND (sh:hasShape(?value, ?arg3, ?arg4, true) AS ?hasShape) . BIND (IF(bound(?hasShape), IF(?hasShape, 1, 0), 'error') AS ?s) . }
Walks a given rdf:List of shapes (?arg1) recursively until it encounters a shape where sh:hasShape returns a provide boolean value (?arg2) for a given focus node (?arg3) using the given shapes graph (?arg4). Returns true if the list has reached such a node, false if it has reached the end of the list. Returns an error if one of the calls to sh:hasShape has produced a fatal error.
The current rdf:List node in the recursion.
SELECT ?result WHERE { GRAPH ?arg4 { OPTIONAL { ?arg1 rdf:first ?shape . ?arg1 rdf:rest ?rest . } } BIND (IF(bound(?shape), sh:hasShape(?arg3, ?shape, ?arg4, true), !?arg2) AS ?hasShape) . BIND (IF(?hasShape = ?arg2, true, IF(bound(?rest), sh:walkShapesList(?rest, ?arg2, ?arg3, ?arg4), false)) AS ?result) . }
A template encapsulating a query that can be used to construct rdf:type triples for certain untyped blank nodes that are an object in a triple where the predicate has a sh:defaultValueType. This can be used as a pre-processor for shape graphs before they are validated.
CONSTRUCT { ?node a ?defaultValueType . } WHERE { ?predicate sh:defaultValueType ?defaultValueType . ?anySubject ?predicate ?node . FILTER (NOT EXISTS { ?node a ?anyType }) . }
Links a resource with the shapes that it is supposed to have. All values of this property must be IRI nodes.