Skip to main content

Safe House gateway integration

This page explains how Safe House integrates technically with the Mnemom gateway. If you are new to Safe House, start with the concept overview first.
This page predates the 2026-05-08 vocabulary + header clean-break and has not been fully updated. It still refers to the legacy disabled / simulate modes (canonical: off / observe / nudge / enforce — see Vocabulary canonicalization) and to retired X-Safe-House-* headers (canonical: X-Mnemom-Verdict / X-Mnemom-Advisory — see What was retired). Treat Safe House concept, Enforcement Modes, and Response Headers as the canonical references; this page’s phase-by-phase mechanics are directionally correct but its mode names, header names, and status codes need a full pass against those pages before you rely on the specifics below.

Request pipeline

Safe House runs as Phase 0.5 — after agent identification resolves the agent config and policy, but before quota enforcement or message forwarding. This placement is intentional: the gateway already knows which agent is handling the request (so Safe House config can be loaded), but no downstream resources have been consumed yet.

Phase-by-Phase breakdown

Phase 0 — Agent identification

The gateway resolves the Authorization header to an agent record and loads the agent’s alignment card, canonical protection card (including the org’s protected_surface), and policy bundle from KV. If Safe House mode is disabled (the default), Phase 0.5 is skipped entirely with no performance cost.

Phase 0.5 — Safe House screening

Behavior depends on the configured mode:
Safe House runs synchronously. The gateway awaits the full L1→L2→L3 verdict before deciding whether to continue.
  • pass or warn: pipeline continues to Phase 1
  • quarantine: request is stored in the quarantine queue with the full message payload; gateway returns HTTP 400 with body:
  • block: request is dropped; gateway returns HTTP 403 with body:
The X-Safe-House-Verdict header is present on all responses in this mode. For quarantine verdicts, X-Safe-House-Quarantine-Id contains the entry ID.

Phase 1 — Quota enforcement

Standard token and request quota checks run here. In enforce mode, this phase is only reached by messages that passed Safe House screening, so quota is not consumed by quarantined or blocked attempts.

Phase 2 — Policy evaluation

The three-layer policy merge (org → agent → transaction) runs here. Safe House operates independently of the policy engine — a message can pass Safe House and fail policy, or vice versa.

Phase 3 — Forward to AI provider

The message is forwarded to the configured AI provider (Anthropic, OpenAI, Gemini, etc.). In enforce mode, only messages with a Safe House pass or warn verdict reach this stage.

Phase 4 — AIP conscience analysis

The streaming response is teed through the AIP analysis pipeline. If Safe House scored the inbound message with a non-zero threat score (even if the verdict was pass), that score and the specific threat categories detected are injected into the conscience prompt. This gives AIP additional signal to scrutinize the resulting reasoning. What Phase 4 does with the AIP verdict depends on the agent’s integrity mode. In enforce mode the response is gated the same turn — it is evaluated before it is delivered, so a violating response is blocked rather than returned (on streaming this adds latency). In observe and nudge modes the response is returned without being gated this turn; the verdict is recorded (and, for nudge, carried into the agent’s next turn). The enrichment looks like:
Note: Safe House L2 enforcement of the org’s protected_surface (forbidden operations, sealed assets) happens in Phase 0.5, not Phase 4. By the time Phase 4 runs, the org’s hard policy floor has already been evaluated. Phase 4 AIP enrichment adds behavioral context from the alignment card; it does not re-derive the org’s protected_surface.

KV caching

Safe House configuration and session state are cached in the BILLING_CACHE KV binding (the same binding used for quota state). Cache TTLs: The BILLING_CACHE binding must be present in wrangler.toml for Safe House to operate. If the binding is absent and SAFE_HOUSE_ENABLED=true, the gateway logs a warning and skips Safe House analysis for all requests.

Pre-emptive nudge injection

When a message passes Safe House screening but its L2 score is ≥ 0.6, Safe House writes a record to the enforcement_nudges table. On the agent’s next request, the gateway’s standard nudge injection logic picks this up and prepends a notice to the system prompt:
This bridges Safe House and the nudge system — the agent is informed of suspicious context without requiring a full AIP boundary violation to trigger the mechanism.

Attestation

Safe House scores are included in the attestation inputCommitment hash. When proof generation runs for a checkpoint, the hash commits to:
  1. The message content
  2. The Safe House L1 score, L2 score, and verdict
  3. The session risk level at time of message
  4. Whether any canary patterns were matched
This creates a tamper-evident record that the Safe House analysis was performed and what it returned, which is important for compliance use cases where you need to demonstrate that screening happened.

Hardened-default Safe House configuration

For agents operating in high-trust, high-risk environments (financial automation, infrastructure management, regulated data handling), set a hardened protection card via PUT /v1/protection/agent/{agent_id}. A reasonable starting baseline against the canonical UnifiedProtectionCard:
The key differences from default settings: enforce mode is on (instead of observe); thresholds are tighter than defaults; and all four surfaces are screened — incoming (user/principal prompts), outgoing (the agent’s response), tool_calls (arguments going to tools), and tool_responses (values coming back from tools). Trust nothing implicitly: trusted_sources starts empty and is widened only with explicit, audited entries. Canary credentials (sh.canary.triggered) and session-escalation policy are configured separately from the protection card; see Canary credentials and the webhook event catalog for the canonical surfaces.

Environment requirements

Safe House requires the following to be present in the gateway environment: No additional API keys or service bindings are required — L2 analysis runs through the existing Anthropic API key configured for the gateway.

See also