SHACL Validator: enforcing closed-world data contracts
OWL ontologies operate under the Open-World Assumption: a missing field is treated as merely unstated, not invalid. Operational pipelines need a deterministic boundary gate that rejects incomplete or mistyped records before downstream consumers see them.
The interactive Shinylive app runs rdflib and pyshacl directly in WebAssembly. It preloads three synthetic invoice records against ex:InvoiceShape so you can see one passing record and two distinct constraint violations.
Data graph (Turtle)
invoice-1001 is valid; invoice-1002 omits ex:paymentTerms; invoice-1003 provides a plain string instead of xsd:decimal.
pyshacl.validate(data, shacl_graph=shapes) returns a boolean conformance flag and an RDF report graph. The app queries that report graph with SPARQL to produce an auditable row per violation.
Focus node
Property path
Severity
SHACL message
ex:invoice-1001
—
Conforms
Satisfies both ex:amountDue and ex:paymentTerms constraints.
ex:invoice-1002
ex:paymentTerms
Violation
Every invoice needs payment terms.
ex:invoice-1003
ex:amountDue
Violation
Every invoice needs exactly one decimal amount due.
SPARQL query used to extract sh:ValidationResult rows
PREFIX sh: <http://www.w3.org/ns/shacl#>
SELECT ?focus ?path ?severity ?message WHERE {
?r a sh:ValidationResult ; sh:focusNode ?focus ; sh:resultSeverity ?severity .
OPTIONAL { ?r sh:resultPath ?path }
OPTIONAL { ?r sh:resultMessage ?message }
} ORDER BY STR(?focus)
Keep your OWL ontology reusable across teams and place workflow-specific required fields, datatypes, and cardinality bounds in SHACL shapes at ingestion, API, and LLM structured-output boundaries.