← Integration guide

Policy Engine Guide

The Policy Engine checks each proxied AI call against the rules in an AI system's active guardrail profile, and rejects the call with HTTP 422 when a rule set to Block matches. Nothing needs to change in your app.

Before rules run

If any of these is missing, the proxy forwards the call without checking it. Each AI system's page in the console shows them as a checklist, with a green check for each step that is done, a red cross for each that is not, and a button to fix it where possible.

  1. The Policy Engine is on for your organisation. It is off by default. Contact Aegis Guardrails support to turn it on.
  2. The AI system's status is Active. New systems start as Draft. Change it on the AI system page. Draft, Paused and Decommissioned systems are ignored.
  3. One guardrail profile is active. On the Guardrails page, the profile in use shows a green Active badge. If the system has exactly one profile, it is used automatically.
  4. The rule is enabled and checks prompts. Rules in Output validation only check the AI's reply (see Categories).
  5. Your app calls the proxy with a key from the system's project. Every AI system is linked to a project when you create it. Calls made with that project's API key are checked automatically. Calls made with your organisation's main API key are checked against your Default project's AI system. If several active systems share a project, the most recently updated one is used; send X-AI-System-Id to choose one.

How a call is checked

  1. PII Shield runs first. If it redacts personal data, the rules see the redacted text.
  2. The circuit breaker is checked. In Pause, Quarantine or Rollback mode, the call is refused with HTTP 503 before any rule runs.
  3. Request rules run. Every enabled rule in a request category is checked, in sort order. All matches are collected.
  4. Any matching Block rule rejects the call with HTTP 422, naming the rule and what it matched. Nothing is sent to the AI provider.
  5. Other matches are recorded. A notification and your webhook fire, and the call goes through.
  6. Output validation rules check the reply after the provider answers. If a Block rule matches, the reply is withheld and your app gets HTTP 422 naming the rule.

If the engine itself errors (for example, a database outage), the call goes through unchecked, unless the organisation has turned on fail-closed mode, which refuses it instead. See the fail-open guarantee.

Categories

The category decides whether a rule checks what you send or what the AI sends back. All request categories behave the same; the name is for organising your rules.

CategoryChecksUse it for
Input checkRequestBanned words, prompt size, allowed models
Prompt integrityRequestPrompt-injection phrases
Retrieval controlRequestLimits on documents or context passed in
Data accessRequestFields or identifiers that must not be sent
Tool permissionRequestTools or functions the model may not call
Human escalationRequestRequests that need a person's review
Audit evidenceRequestRequests you want flagged for audit
Output validationReplyWords or patterns the AI must not return

Condition types

On a chat request, the text checks (Keyword list, Regex and Topic block) read only the newest user message. Earlier turns were already checked when they were sent, so a blocked message doesn't block every later turn, and words in your app's system prompt never trigger a rule. Requests without a message list are read whole. Token limit, Model allowlist and JSON path match always read the whole request. Matching ignores upper and lower case.

TypeMatches whenValue to enterExample
Keyword listAny keyword appears, even inside a longer wordComma-separated keywordsproject falcon, internal only
RegexThe regular expression finds a matchThe pattern only, without slashes\b\d{3}-\d{2}-\d{4}\b
JSON path matchA field in the body passes the comparisonJSON with path, operator, value{"path": "temperature", "operator": "gt", "value": 1}
Topic blockEvery word of a topic appears, in any orderComma-separated topicsmerger acquisition, layoff plan
Token limitEstimated size (characters ÷ 4) is over the limitA number4000
Model allowlistThe body's model doesn't start with a listed nameComma-separated model namesgpt-4o, claude-sonnet

Keyword matching finds parts of words: the keyword ass also matches “class”. Use a regex with \b word boundaries for whole words only.

JSON path operators: equals, not_equals, contains, exists, not_exists, gt, lt. Paths use dots and indexes, such as messages[0].role. If the value isn't valid JSON, the whole text is treated as a path with exists.

Actions and severity

Block and Require approval change what happens to a call. Every other action records the match, sends a notification and calls your webhook, then lets the call through.

ActionOn a request ruleOn an Output validation rule
BlockCall rejected with HTTP 422; nothing reaches the AI providerReply withheld; your app gets HTTP 422 naming the rule. The call is logged as blocked
FlagMatch recorded; call goes throughMatch recorded
Require approvalCall held with HTTP 403 (code approval_required); nothing reaches the AI provider. The call goes to Approvals; once approved, resend it with X-Aegis-Approval (see Human Oversight → Held AI calls)Recorded like Flag
RedactRecorded like Flag; the text is not changed. Use PII Shield to redact personal dataRecorded like Flag
AllowRecorded like Flag; does not override a Block rule that also matchesRecorded like Flag

Streaming with reply Block rules. When an AI system has an Output validation rule set to Block, streamed replies are checked in full before any of it is sent, so your app receives the reply all at once, or a 422. Other streams are not affected.

Severity (Low, Medium, High, Critical) is a label. It appears in the 422 response, notifications and webhooks so you can sort and route alerts. It does not change what the action does.

A blocked request returns:

HTTP 422
{
  "error": "Policy Engine: prompt blocked by rule \"Block codename\" (Matched keywords: project falcon).",
  "violations": [{
    "rule": "Block codename", "category": "input_check", "severity": "medium",
    "action": "block", "reason": "Matched keywords: project falcon"
  }]
}

A call held for approval returns:

HTTP 403
{
  "error": "Policy Engine: this call needs human approval (rule \"Refunds need finance\"), so it was not sent to the AI provider.",
  "code": "approval_required",
  "requestId": "3f2c…",
  "status": "pending",
  "next": "Check GET /v1/actions/3f2c…. Once it is approved, send exactly the same request again with the header X-Aegis-Approval: 3f2c…",
  "violations": [{ "rule": "Refunds need finance", "action": "require_approval", ... }]
}

Held and blocked calls are both saved in your audit trail, so you can show the control fired.

Agent actions

When you record an agent's tool call with POST /agent/actions, Aegis Guardrails decides whether it needs a human, using the rules of the AI system linked to your project (or the one you name in aiSystemId). Tool permission, Data access and Human escalation rules see { toolName, toolInput }. For example, the JSON path match {"path": "toolInput.amount", "operator": "gt", "value": 500} with the Require approval action marks refunds over $500 as pending.

The agent's own requiresApproval and riskScore can ask for review but can't skip it. If the rules can't be checked, the action is marked pending. The response explains the decision in approvalReason (rule, circuit_breaker, agent_request or policy_unavailable) and lists any matching rules in policyViolations.

Today, actions are recorded after they run. A pending status flags the action for review; it doesn't stop it. Holding an action until someone approves it is on the roadmap.

Circuit breaker

The circuit breaker sets how strictly an AI system is handled. Change the mode by hand, or set triggers that raise it automatically.

ModeEffect on calls
ObserveRules run as normal. The default
MonitorSame as Observe
WarnCalls with any rule match are marked as warned
Require approvalEvery call is held with HTTP 403 (code approval_required). Agent actions are marked pending approval
RestrictProxied calls: same as Observe. Agent actions that match a High or Critical rule are marked pending approval
Pause / Quarantine / RollbackEvery call is refused with HTTP 503. Agent actions are marked pending approval

Triggers raise the mode when a count passes a threshold within a time window: Policy violation rate (logged calls with a rule match), Policy blocked rate (logged calls marked blocked) and Sensitive data exposure (logged calls where PII Shield found personal data). Triggers only raise the mode; set it back by hand. Requests rejected with HTTP 422 are not logged calls, so they don't count toward triggers.

Request headers

None of these are needed for rules to run. Add them for a fuller audit trail.

HeaderUseValue
X-Actor-IdShows who made the call in Events and the session timelineYour user's ID in your app
X-Session-IdGroups calls into a session timelineAny stable ID for the conversation
X-End-User-IPRecords the end user's address for incident tracingThe user's IP address, as your server sees it
X-AI-System-IdChooses a specific AI system instead of the project'sThe AI system's ID from its console page
X-ProjectFiles a call under a project when using the main API keyThe project ID or slug

Quick start: block a keyword

  1. In the console, open Policy and register an AI system. Pick the project whose API key your app uses, then set its Status to Active.
  2. Open its Guardrails page, create a profile, and click Activate.
  3. Add a rule: Category Input check, Condition type Keyword list, value project falcon, Action Block.
  4. Send a request that mentions “Project Falcon”. The proxy answers HTTP 422 naming the rule and what it matched.

If the call goes through instead, check the setup checklist on the AI system's page.