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 aPolicyDecision 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:| Field | Purpose |
|---|---|
version | Semver string tracked in every PolicyDecision |
mode | Deployment mode (monitor, enforce, strict) |
defaults.on_policy_miss | Fallback action when no rule matches |
rules | Ordered list of policy rules |
Rule Anatomy
Each rule has these fields:Match Modes
| Mode | Behavior |
|---|---|
all | All conditions must be true (logical AND). This is the default. |
any | At least one condition must be true (logical OR). |
Available Fields
These fields are available in rule conditions:| Field | Type | Source |
|---|---|---|
operation_type | string | remember, update, forget, search, get |
risk_level | string | low, medium, high, critical |
risk_score | float | 0.0 to 1.0 |
scope.tenant_id | string | From MemoryScope |
scope.project_id | string | From MemoryScope |
scope.agent_id | string | From MemoryScope |
scope.subject_id | string | From MemoryScope |
context.source | string | langgraph, openai_sessions, mcp, or custom |
content.contains_pii | boolean | PII detected in content |
content.contains_secret | boolean | Secret/credential detected in content |
content.length | integer | Character length of the content |
Condition Operators
The engine supports 10 operators:| Operator | Description | Example |
|---|---|---|
eq | Equals | risk_level eq "critical" |
neq | Not equals | operation_type neq "search" |
in | Value in list | operation_type in ["forget", "update"] |
nin | Value not in list | context.source nin ["langgraph", "mcp"] |
gt | Greater than | risk_score gt 0.8 |
gte | Greater than or equal | content.length gte 10000 |
lt | Less than | risk_score lt 0.3 |
lte | Less than or equal | risk_score lte 0.5 |
contains | String contains | scope.tenant_id contains "prod" |
regex | Regex match | scope.project_id regex "^proj-[a-z]+" |
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.
Policy Schema Validation
Policies are validated against a JSON Schema at load time. If amemproof-policy.schema.json file is found in the schemas/ directory, it is used automatically:
Example: Multi-Rule Policy
block-secrets (priority 10) before reaching approve-deletes (priority 30), because rules are evaluated in ascending priority order.