[data-shapes] SHACL Profile proposal: disallowing recursive constraints (#875)

scotthenninger has just created a new issue for https://github.com/w3c/data-shapes:

== SHACL Profile proposal: disallowing recursive constraints ==
After some discussion with the profiles working group we'd like to propose a profile that focuses on disallowing recursive constraints. The SHACL spec acknowledges that implementations may handle recursion differently, so it seems a reasonable candidate.  A profile that specifically disallows recursive constraints would eliminate this source of non-determinism, ensuring consistent validation outcomes across implementations. The profile would be for SHACL 1.2, but if SHACL 1.0 is defined as a profile of SHACL 1.2, then it would make sense to have a SHACL 1.0 profile that disallows recursive constraints.

While such a profile would necessarily sacrifice some expressiveness, the trade-off seems worthwhile for use cases that prioritize interoperability and predictability. That said, recursion does serve legitimate modeling needs. Three that come to mind are:

### 1. The recursion occurs directly in the shape:

ex:PersonShape a sh:NodeShape ;
    sh:targetClass ex:Person ;
    sh:property [
        sh:path ex:hasManager ;
        sh:node ex:PersonShape ;
        sh:minCount 1 ;
    ] .

The following data graph produces an infinite validation loop:

ex:Alice a ex:Person ; ex:hasManager ex:Bob .
ex:Bob a ex:Person ; ex:hasManager ex:Alice .

### 2. The recursion occurs when two shapes reference each other:

ex:DepartmentShape a sh:NodeShape ;
    sh:targetClass ex:Department ;
    sh:property [
        sh:path ex:hasMember ;
        sh:node ex:EmployeeShape ;
        sh:minCount 1 ;
    ] .

ex:EmployeeShape a sh:NodeShape ;
    sh:targetClass ex:Employee ;
    sh:property [
        sh:path ex:belongsTo ;
        sh:node ex:DepartmentShape ;
        sh:minCount 1 ;
    ] .

The following data graph produces an infinite validation loop:

ex:Engineering a ex:Department ; ex:hasMember ex:Alice .
ex:Alice a ex:Employee ; ex:belongsTo ex:Engineering .

### 3. Recursive tree validation:

ex:FolderShape a sh:NodeShape ;
    sh:targetClass ex:Folder ;
    sh:property [
        sh:path ex:containsFolder ;
        sh:node ex:FolderShape ;
    ] .

The following data graph produces an infinite validation loop:

ex:FolderA a ex:Folder ; ex:containsFolder ex:FolderB.
ex:FolderB a ex:Folder ; ex:containsFolder ex:FolderA .

This is my first pass at examples. There may be others (please let me know). The bottom line is that the data graphs above all lead to an infinite loop and currently it's up to the SHACL implementations to address the issue.

-- Scott

Please view or discuss this issue at https://github.com/w3c/data-shapes/issues/875 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 30 April 2026 13:33:32 UTC