Skip to content

Repository files navigation

owl-sop-enforcement-gate

An enforcing pre-commit / pre-tool-use gate that stops a bad ontology or config edit from landing.

Editing an OWL/RDF ontology or a governed config is easy. Making sure a bad edit can't quietly land — one that violates the SHACL shapes, ships without a human's verbatim authorization, or jumps ahead of an incomplete governance step — is the hard part teams bolt on late, inconsistently, one missing check at a time. This package is that gate, as one small, injectable, degrade-open primitive.

OntologyEditGate evaluates one edit and BLOCKS it on any of four findings, in order:

  1. SHACL non-conformance on an ontology edit — a structurally-invalid graph must not land, regardless of how good the paperwork is.
  2. Missing verbatim / owner sign-off — a governed mutation must carry a human's verbatim rationale (and, for owner-gated mutations, a named responsible owner).
  3. Substanceless verbatim — a present-but-trivial rationale ("ok") satisfies a presence check on paper; the quality floor (≥ 50 non-whitespace chars, not punctuation-only) makes the sign-off real.
  4. Unmet prerequisite phases — a mutation may not land before its prerequisite governance steps are complete.

Three modes:

Mode Behavior
advisory warn (to stderr) and allow — for rollout / observation
enforce BLOCKenforce() raises GateBlocked; the hook main() exits 2 (the default)
override bypass a block, logged loudly — a documented, audited escape hatch

The moat

The valuable, hard-to-fake part is the assembled discipline at one chokepoint: an ontology edit physically cannot land while it is SHACL-nonconformant; a governed change cannot be recorded without a substantive human rationale (not "ok"); a sensitive change additionally names an owner; and a mutation cannot jump an incomplete prerequisite — yet the whole thing degrades open, so the gate never crashes a commit just because a heavy validator isn't installed. Four governance gates, one ordering, one mode switch, zero hard dependencies. That combination — structural validity + human authorization + substance floor + step-ordering, all reserving BLOCK for a real violation a real checker reported — is what reviewers actually want, and it is far cheaper to adopt as a primitive than to reconstruct after an incident. See docs/MOAT.md.

DOMAIN-NEUTRAL. Nothing here is tied to a product or industry. The SHACL shapes graph, the ontology namespace, the mutation-type detection, the owner-gated mutation set, and the substance floor are all caller-supplied or injectable — the neutral default namespace is http://example.org/ontology/core/, and a tiny generic example ontology (+ one SHACL shape, + one SPARQL competency question) ships under examples/ontology/. "ontology", "OWL", "SHACL", "SPARQL", "rdflib", and "tenant" are the only domain language, and they are the point.

Install

pip install -e .            # the gate itself needs ZERO third-party deps (Python 3.9+)
pip install -e ".[shacl]"   # optional: real SHACL conformance (pyshacl + rdflib) + SPARQL CQs

The package imports and runs on a bare Python 3.9 with none of rdflib / owlrl / pyshacl installed — the heavy imports are lazy and the SHACL seam degrades open (returns "skipped" → allow).

Quickstart

from owl_sop_enforcement_gate import OntologyEditGate, GateBlocked

gate = OntologyEditGate(
    mode="enforce",
    shapes_graph_path="ontology/core.shacl.ttl",   # YOUR shapes (optional; degrades open if absent)
    owner_required_mutations={"new_class"},        # YOUR most-sensitive mutation types
    # shacl_check= / phase_check= are injectable seams — wire them to real backends.
)

# A pure verdict (never raises, never exits):
decision = gate.evaluate(
    "ontology/core.ttl",
    verbatim_response="Approved the new class after confirming no collision and a consistent reasoner.",
    responsible_owner="Ontology Lead",
)
print(decision.allowed, decision.reasons)

# Or act on it according to the mode (raises GateBlocked in enforce mode):
try:
    gate.enforce("ontology/core.ttl", verbatim_response="ok")   # too short → blocked
except GateBlocked as exc:
    print("blocked:", exc.decision.reasons)

As a pre-commit / pre-tool-use hook, feed the edit envelope as JSON and read the exit code:

OSEG_GATE_MODE=enforce OSEG_SHAPES_GRAPH=ontology/core.shacl.ttl \
  owl-sop-gate '{"file_path": "ontology/core.ttl", "verbatim_response": "..."}'
# exit 0 = allowed,  exit 2 = blocked

A full runnable demo (every block/allow/override path, no heavy dependency, no network) is in examples/minimal/quickstart.py.

The two heavy checks are seams

SHACL conformance and phase completion are injected callables with degrade-open reference implementations, so the gate is fully exercisable offline and you can wire in real backends without touching the gate:

Seam Signature Reference impl Wire it to
shacl_check (data_path, shapes_path) -> ShaclResult lazy pyshacl; "skipped" if absent a SHACL toolkit / pyshacl
phase_check (change_set_id, mutation_type) -> (ok, missing) reports all complete a governance phase tracker

See docs/FORKING.md. Full reference: docs/API.md. Module map + seams table: ARCHITECTURE.md.

License

MIT — see LICENSE.


About Powerweave Skunkworks

Powerweave Skunkworks is the AI R&D division of Powerweave Software Services — a rapid-innovation lab that turns real-world product feedback into working, reusable, open-source building blocks. Working in parallel to the main engineering backlog, a lean, cross-functional team of product and technology specialists (UX, data, software engineering, and AI) fast-tracks high-priority ideas into validated modules ready for full-scale build-out.

owl-sop-enforcement-gate is one such building block — a de-domained, MIT-licensed, dependency-light component extracted from Powerweave's internal R&D and engineered to be forked into any SaaS or enterprise product.

About Powerweave

Powerweave Software Services Pvt. Ltd. is a digital-transformation company founded in 2001 and headquartered in Mumbai, India. With 25+ years of experience, 1,700+ professionals, and 350+ global customers, Powerweave builds platforms, processes, and teams across enterprise eCommerce, AI-powered procurement, Microsoft Dynamics ERP, business services, and sustainability — with a strong focus on cutting-edge AI automation that streamlines workflows, reduces manual errors, and accelerates decision-making. Powerweave is ISO 27001:2013 certified.

Explore Powerweave

Maintainers — Powerweave Skunkworks


Keywords: ontology · owl · shacl · sparql · governance · pre-commit · gate · signoff · rdflib · Powerweave · Powerweave Skunkworks · AI R&D · open source · MIT · Python · forkable.

About

An enforcing pre-commit / pre-tool-use gate that blocks ontology + config edits on SHACL non-conformance, missing/substanceless sign-off, and unmet phase prerequisites — advisory / enforce / override modes, injectable seams, degrade-open.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages