UltipaDocs
Try Playground
  • Overview
  • Class Definitions
  • Property Definitions
  • Using Ontology Labels
  • Validation & Enforcement
  1. Docs
  2. /
  3. Ontology

Validation & Enforcement

Overview

Control how strictly ontology rules are enforced and validate data against ontology constraints.

Enforcement Modes

Control how strictly ontology rules are enforced with three modes:

ModeBehavior
STRICTViolations cause errors and block operations
WARNINGViolations are logged but operations proceed
OFFNo validation (useful for bulk imports)
CommandDescription
SET ONTOLOGY ENFORCEMENT STRICT | WARNING | OFFSet the enforcement mode
SHOW ONTOLOGY ENFORCEMENTView current enforcement mode

Enable strict enforcement:

GQL
SET ONTOLOGY ENFORCEMENT STRICT

Enable warning mode:

GQL
SET ONTOLOGY ENFORCEMENT WARNING

Disable enforcement:

GQL
SET ONTOLOGY ENFORCEMENT OFF

Check current enforcement mode:

GQL
SHOW ONTOLOGY ENFORCEMENT
enforcement_mode
STRICT

Strict Mode

In STRICT mode, any ontology constraint violation will cause an error and block the operation. Use this in production to ensure data quality.

Setup domain/range constraints:

GQL
CREATE OBJECT PROPERTY @ex:worksFor DOMAIN @ex:Person RANGE @ex:Organization

SET ONTOLOGY ENFORCEMENT STRICT

// This succeeds: Person -> Organization
INSERT (:@ex:Person {name: 'Alice'})-[:@ex:worksFor]->(:@ex:Organization {name: 'Acme'})

Invalid data is rejected:

GQL
// This fails in STRICT mode: Organization -> Organization violates DOMAIN
INSERT (:@ex:Organization {name: 'Org1'})-[:@ex:worksFor]->(:@ex:Organization {name: 'Org2'})
// Error: Domain constraint violation - source must be @ex:Person

Disjoint class violation:

GQL
CREATE CLASS @ex:Cat
CREATE CLASS @ex:Dog DISJOINT WITH @ex:Cat

INSERT (:@ex:Cat&@ex:Dog {name: 'Mystery'})
// Error: Disjoint class violation - cannot be both Cat and Dog

Functional property violation:

GQL
CREATE OBJECT PROPERTY @ex:hasBirthPlace FUNCTIONAL

// First birthPlace assignment succeeds
INSERT (:@ex:Person {name: 'Alice'})-[:@ex:hasBirthPlace]->(:@ex:Location {name: 'Paris'})

// Second birthPlace fails - functional constraint violation
MATCH (a@ex:Person) WHERE a.name = 'Alice'
INSERT (a)-[:@ex:hasBirthPlace]->(:@ex:Location {name: 'London'})
// Error: Functional property violation - Alice already has a birthPlace

Warning Mode

In WARNING mode, constraint violations are logged but operations proceed. Use this during migration or development to identify issues without blocking work.

GQL
SET ONTOLOGY ENFORCEMENT WARNING

// This succeeds but logs a warning
INSERT (:@ex:Organization {name: 'Org1'})-[:@ex:worksFor]->(:@ex:Organization {name: 'Org2'})
// Warning logged: Domain constraint violation - source should be @ex:Person

View warnings after operations:

GQL
SHOW ONTOLOGY WARNINGS
timestamptypemessage
2024-03-15T10:30:00DOMAIN_MISMATCHworksFor: source should be Person, got Organization

Bulk Import Workflow

For large data imports, disable enforcement during import and validate afterward for better performance.

GQL
// Disable enforcement for bulk import
SET ONTOLOGY ENFORCEMENT OFF

// Perform bulk import operations
INSERT (:@ex:Person {name: 'Alice'})
INSERT (:@ex:Person {name: 'Bob'})
INSERT (:@ex:Organization {name: 'Acme'})
// ... thousands more inserts ...

// Re-enable enforcement
SET ONTOLOGY ENFORCEMENT WARNING

// Validate the imported data
VALIDATE ONTOLOGY

VALIDATE Command

Run validation to check existing data against ontology constraints.

GQL
VALIDATE ONTOLOGY

Validation returns any constraint violations found:

typeelementconstraintmessage
DOMAIN_MISMATCHedge:456worksForSource must be Person
RANGE_MISMATCHedge:789worksForTarget must be Organization

Viewing Warnings

When using WARNING mode, violations are stored in a warnings log that you can query.

GQL
SHOW ONTOLOGY WARNINGS
timestamptypeelementmessage
2024-03-15T10:30:00DOMAIN_MISMATCHedge:123worksFor: source should be Person
2024-03-15T10:35:00CLASS_NOT_FOUNDnode:456Unknown class: @ex:Unknown

Validation Types

The ontology validator checks for several types of constraint violations:

TypeDescription
CLASS_NOT_FOUNDNode has ontology label for undefined class
DOMAIN_MISMATCHEdge source doesn't match property domain
RANGE_MISMATCHEdge target doesn't match property range
DISJOINT_VIOLATIONNode has labels from disjoint classes
FUNCTIONAL_VIOLATIONMultiple edges for functional property
TYPE_MISMATCHData property value doesn't match XSD type

Domain violation example:

GQL
CREATE OBJECT PROPERTY @ex:employs DOMAIN @ex:Organization RANGE @ex:Person

// Wrong: Person cannot employ (domain is Organization)
INSERT (:@ex:Person {name: 'Alice'})-[:@ex:employs]->(:@ex:Person {name: 'Bob'})
// DOMAIN_MISMATCH: source must be @ex:Organization

Range violation example:

GQL
// Wrong: Organization cannot be employed (range is Person)
INSERT (:@ex:Organization {name: 'Acme'})-[:@ex:employs]->(:@ex:Organization {name: 'Other'})
// RANGE_MISMATCH: target must be @ex:Person