What is SHACL?

SHACL (Shapes Constraint Language) is a W3C standard for validating the contents of an RDF-style graph database. It also describes what validation results should be returned so that the user gets a meaningful warning.

In SHACL, constraints are described by ‘shapes’. Each shape contains a description of its targets—the nodes which is intends to validate. The targets could be all instances of a particular class, objects with a particular property, or an explicit list of nodes.

There exist two types of SHACL shapes: node shapes (which apply constraints to their target nodes) and property shapes (which apply constraints to their target nodes’ properties).

There are many different types of constraints a shape can contain, for example:

Class or data types

“Check if every person’s date of birth is of type xsd:date”

:shape1 a sh:PropertyShape;
sh:targetClass :Person;
sh:property [sh:path :dateOfBirth;sh:datatype xsd:date] .

Number and range of property values

"Check that each person in the database has only one date of birth and that date is before 01/01/2099"

Length or language of a string, or matching a regular expression

“Check that the name of a person starts with a capital letter”

Comparisons between two different properties of a node

“Check that each employee’s date of birth is before the date when they signed their contract”

“Check that no person’s child is simultaneously their parent”

You can also use logical operators like “AND” and “OR” to combine the constraints.

Down arrow icon.