Runtime Security

BrainstormRouter's 4-stage runtime security model — pre-model, pre-tool, post-tool, post-model enforcement

Runtime Security

BrainstormRouter's security subsystems are organized into four logical stages, each containing independent enforcement components. These components are production-grade and individually active — this page maps where each subsystem operates in the request lifecycle.

The 4-Stage Model

Request → [Pre-Model] → Model → [Pre-Tool] → Tool → [Post-Tool] → [Post-Model] → Response

Stage 1: Pre-Model

Inspects inbound requests before they reach the model router.

ComponentWhat It DoesConfiguration
Guardrails ChainPII scanning, jailbreak detection, topic restrictionPUT /v1/guardrails/config
Guardian IntelligenceCost estimation, velocity anomaly detection, budget seatbeltsX-BR-Max-Estimated-Cost header
PII ScannerEmail, phone, SSN, credit card detection with redactionBuilt-in + pluggable backends (Presidio, Google DLP)

Enforcement actions: Block (403), Redact (rewrite), Warn (headers only), Off.

Stage 2: Pre-Tool

Inspects tool calls in LLM responses before tool execution.

ComponentWhat It DoesConfiguration
Tool Call FirewallDeny list, argument validation, RBAC scope checks, secret redactionPer-tenant firewall config
Tool Governance EngineDeep intent classification, role hierarchy evaluation, approval workflowsPUT /v1/security/policies
Intent ClassifierPattern-based threat detection (SQL injection, code execution, privilege escalation)Deterministic — no configuration needed
MCP GovernorTool allowlist, parameter validation, session rate limiting, approval queuePUT /v1/mcp/governance/policy

Enforcement actions: Block, Warn, Log, Quarantine, Require Approval (202 Accepted).

Stage 3: Post-Tool

Inspects tool execution results before they reach the model for the next turn.

ComponentWhat It DoesConfiguration
Output SanitizerStrips secrets, internal IDs, and file paths from tool resultsAutomatic
Result Size LimiterTruncates oversized tool outputs to prevent context exhaustionPer-tenant tool config

Enforcement actions: Redact, Truncate, Log.

Stage 4: Post-Model

Inspects model output before it reaches the client. Includes both batch and streaming enforcement.

ComponentWhat It DoesConfiguration
Outbound GuardrailsPII detection, content filtering, governance validation on completionsPUT /v1/guardrails/config
Streaming GuardrailsToken-by-token PII detection, content safety, governance rule validationBuffered window evaluation
Governance ValidatorValidates output against tenant governance rules (e.g., "never mention competitors")Memory-embedded governance rules

Enforcement actions: Block, Redact, Truncate, Replace, Warn.

Cross-Cutting Systems

These systems operate across all stages:

SystemPurposeAPI
RBAC5 roles (admin, developer, auditor, operator, agent), 30+ permissionsRole assignment via API keys
Policy EngineDeclarative rules with priority, exemptions, and conditionsGET/PUT /v1/security/policies
Anomaly DetectionAdaptive 3σ thresholds per sender/service with rolling windowsGET /v1/security/anomalies
SSRF GuardBlocks provider endpoints targeting internal services or cloud metadataAutomatic — deployment-mode aware
Egress AllowlistPer-service domain allowlists for outbound requestsPer-service configuration
Kill SwitchEmergency routing suspension per tenantPOST /v1/killswitch/activate

API Endpoint Mapping

EndpointStagePurpose
GET /v1/security/statusCross-cuttingPolicy version + anomaly count
GET /v1/security/policiesCross-cuttingCurrent ruleset
PUT /v1/security/policiesCross-cuttingUpdate ruleset
POST /v1/security/policies/testCross-cuttingTest context against rules
GET /v1/security/anomaliesCross-cuttingRecent anomaly alerts
GET /v1/guardrails/providersPre-model, Post-modelAvailable providers
PUT /v1/guardrails/configPre-model, Post-modelTenant guardrail config
POST /v1/guardrails/testPre-modelTest content against pipeline
PUT /v1/mcp/governance/policyPre-toolMCP tool policies

SDK Examples

import BrainstormRouter from "brainstormrouter";

const br = new BrainstormRouter({ apiKey: "br_live_..." });

// Check security status (policy + anomaly)
const status = await br.security.status();

// Get and update policy rules
const policies = await br.security.getPolicies();
await br.security.updatePolicies({
  version: "1",
  rules: [
    {
      id: "block-competitor-mentions",
      action: "deny",
      description: "Prevent competitor name leakage",
      conditions: [{ field: "output.text", op: "matches", value: "competitor" }],
    },
  ],
});

// Test a context against policies
const policyResult = await br.security.testPolicy({
  "tool.name": "web_search",
  action: "tool_call",
});

// Get guardrail config
const guardrailConfig = await br.guardrails.getConfig();

// Update guardrail config
await br.guardrails.updateConfig({
  enabled: true,
  mode: "block",
  providers: [{ id: "builtin" }, { id: "pii" }],
});

// Test guardrails
const result = await br.guardrails.test("User SSN is 123-45-6789");
from brainstormrouter import BrainstormRouter

br = BrainstormRouter(api_key="br_live_...")

# Check security status (policy + anomaly)
status = br.security.status()

# Get and update policy rules
policies = br.security.get_policies()
br.security.update_policies({
    "version": "1",
    "rules": [
        {
            "id": "block-competitor-mentions",
            "action": "deny",
            "description": "Prevent competitor name leakage",
            "conditions": [{"field": "output.text", "op": "matches", "value": "competitor"}],
        }
    ],
})

# Test a context against policies
policy_result = br.security.test_policy({
    "tool.name": "web_search",
    "action": "tool_call",
})

# Get guardrail config
guardrail_config = br.guardrails.get_config()

# Update guardrail config
br.guardrails.update_config({
    "enabled": True,
    "mode": "block",
    "providers": [{"id": "builtin"}, {"id": "pii"}],
})

# Test guardrails
result = br.guardrails.test("User SSN is 123-45-6789")

MCP Tools

Agents can manage security via MCP tools:

ToolPermissionPurpose
br_get_security_statussecurity.readSecurity status overview
br_get_policiessecurity.readCurrent policy ruleset
br_test_policysecurity.readTest context against policies
br_get_guardrail_configconfig.readCurrent guardrail configuration
br_update_guardrail_configconfig.writeUpdate guardrail settings
br_test_guardrailsconfig.writeTest content against guardrails
br_activate_killswitchsecurity.writeEmergency routing suspension
br_deactivate_killswitchsecurity.writeResume routing
br_get_killswitch_statussecurity.readKill switch state