What Is Policy Engine?

Policy evaluation is the systematic checking of decisions against predefined governance rules and constraints. Unlike application enforcement that automatically blocks non-compliant actions, policy evaluation provides compliance status that can trigger different workflows—approval processes, exception handling, or audit requirements. Key policy concepts: Policy evaluation checks whether decisions meet defined criteria without automatically preventing actions, enabling flexible governance workflows. Governance and compliance workflows use policy evaluation results to route decisions through appropriate approval chains, exception processes, or audit trails. Approval processes can be triggered by policy violations, creating documented exception paths with justification and approver accountability. Difference from enforcement: Policy evaluation returns compliance status (True/False) but does not automatically block actions. Your workflow determines what happens next—immediate approval, escalation, exception handling, or rejection.

Why Use Policy Engine?

Governance and accountability. Create auditable decision workflows where every policy evaluation, exception, and approval is permanently recorded in the knowledge graph with full provenance tracking. Compliance verification. Systematically check decisions against regulatory requirements, internal policies, and risk management rules before they are finalized or acted upon. Approval workflow orchestration. Route non-compliant decisions through structured approval processes with documented justifications and multi-level sign-offs. Regulatory compliance. Meet audit requirements by maintaining complete policy version histories, exception records, and compliance checking trails that regulators can inspect. Risk management. Flag high-risk decisions for additional review while allowing routine compliant decisions to proceed with minimal friction. Policy evolution tracking. Maintain version histories of policy changes with impact analysis, enabling evidence-based policy refinement and regulatory reporting.

When To Use / When Not To Use

Use Policy Engine for:
  • Governance workflows requiring structured approval processes and audit trails
  • Regulatory compliance where policy adherence must be documented and verifiable
  • Multi-level approval workflows for high-stakes decisions (financial approvals, security exceptions, clinical treatments)
  • Regulated environments where policy violations trigger specific escalation procedures
  • Risk management workflows where non-compliant decisions require additional oversight
  • Audit requirements demanding complete policy application and exception tracking
Do NOT use Policy Engine for:
  • Simple form validation or basic input checking—use standard validation libraries instead
  • Basic business rules that don’t require audit trails or governance workflows
  • Low-stakes, high-throughput checks where policy evaluation overhead would impact performance
  • Deterministic rule checking that doesn’t benefit from version tracking and approval processes
  • Real-time operational decisions where policy evaluation latency is unacceptable
Warning: Policy Engine adds governance overhead and requires careful workflow design. Only use when the benefits of structured policy management outweigh the additional complexity. PolicyEngine enforces named policies against recorded decisions, returning True if the decision satisfies all policy rules. Use it to gate AI decisions at runtime — attributions requiring dual-source confirmation, escalations requiring senior approval, or any decision category where compliance must be verified before the outcome is recorded. Policies are versioned graph nodes, so every check, exception, and approval chain is part of the permanent audit trail.
The Policy Engine sits above AgentContext and ContextGraph. Policies are stored as nodes in the same graph as decisions, giving them the same causal tracing, provenance, and temporal validity as any other knowledge graph entity.Key objects: PolicyEngine and Policy import from semantica.context. Decision is a dataclass with fields like decision_id, category, scenario, reasoning, outcome, confidence, timestamp, decision_maker, and metadata. DecisionRecorder imports from semantica.context.decision_recorder for approval workflow tracking.

Supported Rule Types

The PolicyEngine implementation supports specific rule patterns that evaluate decision attributes and metadata: Confidence rules:
  • min_confidence: 0.85decision.confidence >= 0.85
Outcome validation:
  • allowed_outcomes: ["approved", "approved_with_conditions"]decision.outcome must be in the list
Category validation:
  • required_categories: ["credit_risk", "operational_risk"]decision.category must be in the list
Metadata field rules:
  • min_*: value — metadata field must be >= value (e.g., min_credit_score: 680)
  • max_*: value — metadata field must be <= value (e.g., max_ltv: 0.85)
  • required_*: value — metadata field must equal value (string) or contain all items (list)
Field lookup behavior: For rule min_credit_score, the engine checks metadata["credit_score"], then metadata["*_credit_score"] (suffix match), then decision.credit_score attribute. Important: The following rule types are NOT supported and will cause unexpected behavior:
  • disallowed_outcomes (use allowed_outcomes instead)
  • mandatory_fields (use required_* for specific fields)
  • requires_mfa (use metadata field checks like required_mfa_verified)
  • Complex nested conditions or operators

Defining the policy

A Policy is a dataclass with a free-form rules dict — encode whatever your domain requires using supported rule patterns.
The policy is now a node in the graph. It has a version string, a creation timestamp, and a rules dict that the compliance checker will read when evaluating decisions against it.

Checking a decision for compliance

check_compliance takes a Decision object and the policy ID and returns a boolean.
The engine returns False. The decision has not been rejected — it has been flagged. What happens next depends on your workflow. In some organisations, a non-compliant result simply blocks the write to the authoritative graph. In others, it triggers an exception process where a human approver reviews the evidence and signs off.

Recording a policy exception

record_exception permanently links a decision, the policy it violated, the approver identity, and the justification.

Building a multi-level approval chain

For the highest-stakes decisions — formal attribution reports that will be shared with government partners — a single approver is not enough. Three people need to sign off: the team lead, the department head, and the CISO. DecisionRecorder.record_approval_chain captures all three in a single call, linking each approver to the communication method and context of their sign-off.

What-if impact analysis before changing a policy

Six months on, your threat intelligence lead wants to tighten the policy: raise the minimum confidence threshold from 0.85 to 0.92 to reduce false-positive attributions. Before she updates the policy, she wants to know how many past decisions would have been blocked under the stricter rule. analyze_policy_impact runs a what-if simulation over the historical decision record — no permanent changes are made.
The impact dict contains per-decision detail, not just the count. You can inspect which specific attribution decisions would have been affected, review their reasoning, and decide whether tightening the threshold is worth it.

Updating the policy and finding affected decisions

The lead decides to proceed with the threshold increase. She updates the policy to version 1.1.0, recording her reason. The old version is preserved in the history.
This is the re-audit workflow: every decision made under the old policy is surfaced, reviewed against the new standard, and either re-confirmed or flagged for correction. The graph preserves the full history of which policy version governed each decision.

Reviewing the full audit trail

At any point — for an Inspector General review, a board report, or an incident investigation — you can retrieve the complete version history of a policy.

Common Pitfalls

Assuming failed compliance automatically blocks actions. PolicyEngine returns compliance status but does NOT automatically prevent actions. Your workflow must check the returned boolean and decide what happens next—approval, rejection, exception handling, or escalation. Using unsupported rule keys. The implementation only supports specific patterns: min_*, max_*, required_*, min_confidence, allowed_outcomes, and required_categories. Any other rule key falls back to a key-presence check: it passes only if that exact key exists in decision.metadata, regardless of its value. This means keys like disallowed_outcomes will silently fail compliance whenever that literal key is absent from metadata (the common case), and will silently pass — regardless of the actual outcome — if a disallowed_outcomes key happens to exist in metadata with any value. Neither behavior matches the intended “outcome must not be in this list” semantics — use allowed_outcomes instead. Treating exceptions as approvals. Recording a policy exception with record_exception() does NOT automatically make a non-compliant decision compliant. Exceptions are audit trail entries—your workflow must still decide whether to proceed with the non-compliant decision. Assuming PolicyEngine modifies graph state automatically. PolicyEngine only evaluates compliance and records policy applications, exceptions, and approval chains. It does not modify decision outcomes, metadata, or prevent actions—that is your workflow’s responsibility. Using complex nested rule structures. The implementation does not support complex conditional logic, nested operators, or arbitrary expressions. Keep rules simple: single field comparisons, list membership checks, and threshold validations only. Missing metadata for rule evaluation. Rules like min_credit_score require the corresponding metadata field (credit_score) to be present in decision.metadata. Missing metadata fields cause rule evaluation to fail, making the decision non-compliant. Forgetting to check rule evaluation results. Always handle both compliant and non-compliant cases explicitly. Non-compliant decisions that proceed without proper exception handling create audit gaps and governance risks.

Domain Examples

TLP:RED intelligence must never be shared outside the originating organisation without commander-level approval. The policy is enforced on every information-sharing decision that touches classified threat reporting. Violations are routed to the J2 officer for exception review rather than silently logged.

  • Decision Intelligencerecord_decision(), causal chains, and precedent search — the decisions that check_compliance() evaluates
  • Reasoning & Rules — complement policy rules with formal inference for logical conflict detection
  • SHACL Validation — enforce structural constraints on policy nodes themselves
  • Change Management — version-snapshot the policy graph alongside the knowledge graph
  • Provenance — W3C PROV-O lineage for every policy decision and exception
  • MCP Server — expose record_decision and find_precedents as MCP tools for AI agents