Skip to main content

Policy Engine

The Policy Engine is a deterministic rule evaluator. It takes the operation type, risk assessment, scope, context, and content flags as input, and evaluates a list of YAML-defined rules in priority order. The first matching rule wins, producing a PolicyDecision with an action and reason codes.
Deterministic means the same input combined with the same policy version always produces the same decision. There is no randomness, no ML model, and no external calls.

Policy File Structure

Policies are defined in a YAML file with four top-level sections:

Rule Anatomy

Each rule has these fields:
Rules are evaluated in ascending priority order. A rule with priority: 10 is evaluated before a rule with priority: 20. Use gaps (10, 20, 30) so you can insert rules later without renumbering.

Match Modes

Available Fields

These fields are available in rule conditions:

Condition Operators

The engine supports 10 operators:

Actions

Each rule produces one of four actions:

allow

The operation proceeds to the adapter and is committed to the memory backend.

deny

The operation is blocked immediately. A PolicyDeniedError is raised with the matched rule ID.

require_approval

The operation is paused and sent to the Approval Broker. It proceeds only if approved.

quarantine

The operation payload is stored in the quarantine store for later review. A QuarantinedError is raised.

The on_policy_miss Fallback

When no rule matches an operation, the defaults.on_policy_miss action is used. The decision will have reason_codes: ["DEFAULT_POLICY"] and an empty matched_rule_ids list.
In production, consider setting on_policy_miss: deny to enforce a deny-by-default posture. Any operation not explicitly covered by a rule will be blocked.

Policy Schema Validation

Policies are validated against a JSON Schema at load time. If a memproof-policy.schema.json file is found in the schemas/ directory, it is used automatically:

Example: Multi-Rule Policy

In this example, a delete operation containing a secret would match block-secrets (priority 10) before reaching approve-deletes (priority 30), because rules are evaluated in ascending priority order.