[data-shapes] Usefulness of validation reports (#263)

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

== Usefulness of validation reports ==
One could argue that the contents of the validation report is up to the implementation but I think it's worth discussing if there is anything to help make validation reports more useful to consumers. This is mostly a problem with logical constraints. Here's an example.

### Shapes

```turtle
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix schema: <http://schema.org/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

[] 
  a sh:NodeShape ;
  sh:targetClass schema:Thing ;
  sh:xone ( _:personShape _:orgShape ) ;
.

_:personShape
  sh:property [
    sh:path rdf:type ;
    sh:hasValue schema:Person ;        
  ] , [
    sh:path schema:givenName ;
    sh:minCount 1 ;
  ] ;
.

_:orgShape
  sh:property [
    sh:path rdf:type ;
    sh:hasValue schema:Organization ;
  ] , [
    sh:path schema:name ;
    sh:minCount 1 ;
  ] ;
.
```

### Data

```turtle
@prefix schema: <http://schema.org/> .

[]
 a schema:Thing , schema:Person ;
.
```

### Validation results

Here's what various tools known to me return when these graph are used for validation

**TopQuadrant**

```turtle
@prefix dash:    <http://datashapes.org/dash#> .
@prefix graphql: <http://datashapes.org/graphql#> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema:  <http://schema.org/> .
@prefix sh:      <http://www.w3.org/ns/shacl#> .
@prefix swa:     <http://topbraid.org/swa#> .
@prefix tosh:    <http://topbraid.org/tosh#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .

[ rdf:type     sh:ValidationReport ;
  sh:conforms  false ;
  sh:result    [ rdf:type                      sh:ValidationResult ;
                 sh:focusNode                  _:b0 ;
                 sh:resultMessage              "Value must have exactly one of the following 2 shapes but conforms to 0: _:65799de065e3821b180e3b71a470d5fb, _:064e6e55c78cc9b389f65224e0a92738" ;
                 sh:resultSeverity             sh:Violation ;
                 sh:sourceConstraintComponent  sh:XoneConstraintComponent ;
                 sh:sourceShape                []  ;
                 sh:value                      _:b0
               ]
] .
```

**shacl-js**

```turtle
[
 a sh:ValidationResult ;
 sh:resultSeverity sh:Violation ;
 sh:sourceConstraintComponent sh:XoneConstraintComponent ;
 sh:sourceShape _:n126 ;
 sh:focusNode _:n125 ;
 sh:value _:n125 ;
] .
```

**rdf-validate-shacl**

```turtle
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix schema: <http://schema.org/> .
@prefix earl: <http://www.w3.org/ns/earl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix hydra: <http://www.w3.org/ns/hydra/core#> .

_:report a sh:ValidationReport ;
 sh:result [
  <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> sh:ValidationResult ;
  sh:resultSeverity sh:Violation ;
  sh:sourceConstraintComponent sh:XoneConstraintComponent ;
  sh:sourceShape _:g0 ;
  sh:focusNode _:g0 ;
  sh:value _:g0 ;
 ] ;
 sh:conforms false .

sh:Violation a sh:Severity .

sh:XoneConstraintComponent a sh:ConstraintComponent .

_:g0 a sh:NodeShape ;
 sh:xone (
  [
   sh:property [
    sh:path <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ;
    sh:hasValue schema:Person ;
   ], [
    sh:path schema:givenName ;
    sh:minCount 1 ;
   ] ;
  ]
  [
   sh:property [
    sh:path <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ;
    sh:hasValue schema:Organization ;
   ], [
    sh:path schema:name ;
    sh:minCount 1 ;
   ] ;
  ]
 ) ;
 sh:targetClass schema:Thing .
```

**SHACLex**

```turtle
@prefix sh: <http://www.w3.org/ns/shacl#> .

[ a            sh:ValidationReport ;
  sh:conforms  false ;
  sh:result    [ a                             sh:ValidationResult ;
                 sh:focusNode                  _:b0 ;
                 sh:message                    "_:NodeLine3Col1 does not have nodeShape _:NodeLine7Col1 because some shapes failed." ;
                 sh:resultSeverity             sh:Info ;
                 sh:sourceConstraintComponent  sh:ShapesFailed ;
                 sh:sourceShape                _:b1
               ] ;
  sh:result    [ a                             sh:ValidationResult ;
                 sh:focusNode                  _:b0 ;
                 sh:message                    "Xone violation. Expected _:NodeLine3Col1 to satisfy exactly one of the shapes _:personShape,_:orgShape" ;
                 sh:resultSeverity             sh:Violation ;
                 sh:sourceConstraintComponent  sh:XoneConstraintComponent ;
                 sh:sourceShape                _:b1
               ]
] .
```

**Jena**

```turtle
@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <http://schema.org/> .
@prefix sh:     <http://www.w3.org/ns/shacl#> .
@prefix xsd:    <http://www.w3.org/2001/XMLSchema#> .

[ rdf:type     sh:ValidationReport ;
  sh:conforms  false ;
  sh:result    [ rdf:type                      sh:ValidationResult ;
                 sh:focusNode                  _:b0 ;
                 sh:resultMessage              "Xone has 0 conforming shapes at focusNode _:BNodeLine3Col1" ;
                 sh:resultSeverity             sh:Violation ;
                 sh:sourceConstraintComponent  sh:XoneConstraintComponent ;
                 sh:sourceShape                []  ;
                 sh:value                      _:b0
               ]
] .
```

**rdf-ext (without traces)**

```turtle
@prefix sh: <http://www.w3.org/ns/shacl#>.

[ a sh:ValidationReport;
  sh:conforms false;
  sh:result [ a sh:ValidationResult;
      sh:detail [ a sh:ValidationResult;
          sh:focusNode _:b1;
          sh:resultMessage "Missing expected value <http://schema.org/Person>";
          sh:resultPath <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>;
          sh:resultSeverity sh:Violation;
          sh:sourceConstraintComponent sh:HasValueConstraintComponent;
          sh:sourceShape []
        ], [ a sh:ValidationResult;
          sh:focusNode _:b1;
          sh:resultMessage "Less than 1 values";
          sh:resultPath <http://schema.org/givenName>;
          sh:resultSeverity sh:Violation;
          sh:sourceConstraintComponent sh:MinCountConstraintComponent;
          sh:sourceShape []
        ], [ a sh:ValidationResult;
          sh:focusNode _:b1;
          sh:resultMessage "Missing expected value <http://schema.org/Organization>";
          sh:resultPath <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>;
          sh:resultSeverity sh:Violation;
          sh:sourceConstraintComponent sh:HasValueConstraintComponent;
          sh:sourceShape []
        ], [ a sh:ValidationResult;
          sh:focusNode _:b1;
          sh:resultMessage "Less than 1 values";
          sh:resultPath <http://schema.org/name>;
          sh:resultSeverity sh:Violation;
          sh:sourceConstraintComponent sh:MinCountConstraintComponent;
          sh:sourceShape []
        ];
      sh:focusNode _:b1;
      sh:resultSeverity sh:Violation;
      sh:sourceConstraintComponent sh:XoneConstraintComponent;
      sh:sourceShape [];
      sh:value _:b1
    ]
].

```

SHACLex provides a somewhat informative result but that would still be cryptic if the nested shapes were unlabelled blank nodes.
rdf-ext provides the details of validation issues from nested shapes but it's still hard to process.
The other are no help at all.

We have been facing these kind of issues constantly when building forms. It's often very very hard on the users to understand what are the issues. Usually it's impossible to match a given result with a specific form field. And sometime there is nothing useful to display at all...

To improve the validation feedback in a non-form scenario, in some scenarios we have been splitting shapes, such as by using various target types but it's not a viable solution for forms.

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


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

Received on Friday, 21 February 2025 10:59:43 UTC