Season 3, Episode 6 of Going Meta returns to SHACL validation in Neo4j with a significantly more advanced treatment than the introductory Session 3 from Season 1. This episode covers the full SHACL constraint authoring workflow using two complementary Python libraries —Documentation Index
Fetch the complete documentation index at: https://mintlify.com/jbarrasa/goingmeta/llms.txt
Use this file to discover all available pages before exploring further.
graphexpectations for constraint authoring and shapes-validation for compilation and execution — and demonstrates how to define node shapes, property shapes, custom sh:targetQuery targets, and how to interpret the violation report.
Watch the Recording
Season 3, Episode 6 — March 2026
Session Code
Colab notebook: GM_S3_6_validations.ipynb
Libraries
graphexpectations— a fluent Python DSL for authoring SHACL constraints without writing Turtle directlyshapes-validation— compiles SHACL shapes to Cypher and runs them against a live Neo4j database
This session extends the foundational SHACL content from Going Meta Season 1, Episode 3. If you are new to SHACL in Neo4j, watch that episode first for the basics of
n10s-based constraint loading.Authoring Constraints with graphexpectations
The graphexpectations library exposes an expectation DSL grouped into ge.Set objects, each targeting a node type or a custom query. Constraints are added as method calls:
Raw SHACL Turtle
You can also write SHACL shapes directly in Turtle. The example below is equivalent to the expectations above and usessh:targetClass, sh:targetQuery, sh:pattern, sh:minCount/sh:maxCount, sh:minInclusive/sh:maxExclusive, and sh:class:
The
sh:targetQuery constraint (used for R007_US_PROD_ID) targets only the subset of Product nodes that are supplied by an American supplier — a custom focus node pattern that goes beyond simple sh:targetClass targeting.Running Validation with shapes-validation
The ValidationClient loads the SHACL shapes (Turtle string or file), compiles them to Cypher internally, and runs them against the database. You can validate the entire graph or a specific set of nodes:
Interpreting the Violation Report
The report can be converted to a Pandas DataFrame for tabular inspection:| Column | Description |
|---|---|
focusNode | The internal Neo4j node ID of the violating node |
nodeType | The label(s) of the focus node |
propertyShape | The SHACL property shape that was violated |
offendingValue | The actual property value that caused the violation |
resultPath | The property path the constraint applies to |
severity | sh:Violation, sh:Warning, or sh:Info |
message | The human-readable message set on the shape (e.g. R001_INVALID_COUNTRY) |
Advanced Patterns Covered in This Session
Inverse Path Constraints
Use
sh:inversePath to constrain nodes based on incoming relationships — for example, requiring that every Product is supplied by at least one Supplier.Custom Target Queries
sh:targetQuery selects an arbitrary subgraph as the focus set, enabling constraints that apply only to contextually relevant nodes rather than all nodes of a given type.Class Constraints on Relationships
sh:class on a property shape verifies that the target node of a relationship has the expected label — catching schema violations where relationships connect incompatible node types.Count Constraints
sh:minCount and sh:maxCount enforce cardinality — for example, that a Product has exactly one unitPrice value and that each Customer has placed at least one order.