# Importing SHACL for graph validation (namespaces..?)

**URL:** <https://community.neo4j.com/t/importing-shacl-for-graph-validation-namespaces/46389>\
**Category:** Newbie Questions\
**Created:** [October 25, 2021, 7:44am UTC](https://community.neo4j.com/t/importing-shacl-for-graph-validation-namespaces/46389 "2021-10-25T07:44:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![max\_beikirch](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/max_beikirch/32/3913_2.png) [@max\_beikirch](https://community.neo4j.com/u/max_beikirch)\
**Post date:** [October 25, 2021, 7:44am UTC](https://community.neo4j.com/t/importing-shacl-for-graph-validation-namespaces/46389/1 "2021-10-25T07:44:04Z")

</div>

Hello,

I want to use neosemantics to validate a graph in neo4j, but I'm having trouble to get the model constraints loaded on a minimal example:

Suppose I have the following graph:

```auto
CREATE (n:Person {name: 'Andy'})

```

Then, I initialize neosemantics as follows:

```auto
CALL n10s.graphconfig.init();

```

Now I should be good to go and validate the graph. Based on what I found here ([Validating Neo4j graphs against SHACL - Neosemantics](https://neo4j.com/labs/neosemantics/4.0/validation/)), I thought that the following schema should work as a first approach:

```auto
call n10s.validation.shacl.import.inline('

@prefix neo4j: <http://neo4j.com/myvoc#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

neo4j:PersonShape a sh:NodeShape ;
  sh:targetClass neo4j:Person ;
  sh:property [
    sh:path neo4j:name ;
    sh:datatype xsd:string ;
  ];
.','Turtle')

```

However, that gives me:

```auto
Failed to invoke procedure `n10s.validation.shacl.import.inline`: Caused by: n10s.utils.UriUtils$UriNamespaceHasNoAssociatedPrefix: Prefix Undefined: No prefix defined for namespace <http://neo4j.com/myvoc#Person>. Use n10s.nsprefixes.add(...) procedure.

```

It felt weird, but to match that error message, I tried adding the line

```auto
@prefix neo4jPerson: <http://neo4j.com/myvoc#Person> .

```

but that didn't help.

I then tried the following:

```auto
CALL n10s.graphconfig.init({handleVocabUris:"IGNORE"});

```

Then, the validation rule is accepted, but it doesn't really look connected to anything:

```auto
target propertyOrRelationshipPath param value
" __NONE__" " __NONE__" "datatype" "string"

```

I thought that it would be helpful to remove that namespace stuff all along. So I also tried

```auto
call n10s.validation.shacl.import.inline('

@prefix neo4j: <http://neo4j.com/myvoc#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

PersonShape a sh:NodeShape ;
  sh:targetClass Person ;
  sh:property [
    sh:path name ;
    sh:datatype xsd:string ;
  ];
.','Turtle')

```

But that didn't work either as the parser insists on getting that namespace stuff to work:

```auto
Failed to invoke procedure `n10s.validation.shacl.import.inline`: Caused by: org.eclipse.rdf4j.rio.RDFParseException: Expected ':', found ' ' [line 6]

```

I'm a bit at a loss here. The code I've given is more or less taken from the neosemantics user guide ([Neosemantics(n10s) User Guide - Neosemantics](https://neo4j.com/labs/neosemantics/4.0/)) and only adapted slightly.

I should add that I can import the original schema just fine with handleVocabUris: KEEP.

But still something isn't linked correctly. I added a shape that definitely violates the specification (name is missing):

```auto
CREATE (n:Person {violation: 5})

```

Then I ran the validation with

```auto
call n10s.validation.shacl.validate() yield focusNode, nodeType,propertyShape,offendingValue,resultPath,severity

```

but the result remained empty.  
What am I missing?

---

<div class="post-metadata">

**Author:** ![max\_beikirch](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/max_beikirch/32/3913_2.png) [@max\_beikirch](https://community.neo4j.com/u/max_beikirch)\
**Post date:** [November 5, 2021, 9:44am UTC](https://community.neo4j.com/t/importing-shacl-for-graph-validation-namespaces/46389/2 "2021-11-05T09:44:40Z")

</div>

I solved it: [cypher - neo4j neosemantics: loading model constraints - Stack Overflow](https://stackoverflow.com/questions/69689710/neo4j-neosemantics-loading-model-constraints)

---

<div class="post-metadata">

**Author:** ![torodinekle](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/torodinekle/32/29673_2.png) [@torodinekle](https://community.neo4j.com/u/torodinekle)\
**Post date:** [September 18, 2023, 12:43pm UTC](https://community.neo4j.com/t/importing-shacl-for-graph-validation-namespaces/46389/3 "2023-09-18T12:43:23Z")

</div>

I had a similar problem. Does this seems familiar to you?  
[https://community.neo4j.com/t/failed-to-import-shacl-with-neosemantics/64181](https://community.neo4j.com/t/failed-to-import-shacl-with-neosemantics/64181)

---

<div class="post-metadata">

**Author:** ![edenwheeler60](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/edenwheeler60/32/29865_2.png) [@edenwheeler60](https://community.neo4j.com/u/edenwheeler60)\
**Post date:** [October 19, 2023, 11:40am UTC](https://community.neo4j.com/t/importing-shacl-for-graph-validation-namespaces/46389/4 "2023-10-19T11:40:46Z")

</div>

Troubleshooting neosemantics in Neo4j, ensure the namespace prefix is defined using n10s.nsprefixes.add(...). Add this line before your schema definition to resolve the "Prefix Undefined" error. Adjust your schema definition to use the correct prefix, and initialize neosemantics with handleVocabUris: "IGNORE". Confirm that the prefix is consistent throughout. Then, import and validate the SHACL schema. If issues persist, double-check the prefix and rerun the validation. This step-by-step approach ensures proper namespace handling and enhances schema validation in Neo4j using neosemantics.  
[https://stackoverflow.com/questions/69689710/neo4j-neosemantics-loading-model-constraints/](https://community.neo4j.com/t/failed-to-import-shacl-with-neosemantics/64181)[ccsp training](https://www.igmguru.com/cyber-security/ccsp-isc2-certification-training/)
