Guardrails

Content safety pipeline — providers, config, and testing.

Endpoints

MethodPathAuthDescription
GET/v1/guardrails/providersAPI KeyList available providers
GET/v1/guardrails/templatesAPI KeyList provider templates
POST/v1/guardrails/providersAPI KeyRegister external provider
DELETE/v1/guardrails/providers/:idAPI KeyRemove external provider
GET/v1/guardrails/configAPI KeyGet pipeline config
PUT/v1/guardrails/configAPI KeyUpdate pipeline config
POST/v1/guardrails/testAPI KeyTest with sample text

List providers

curl https://api.brainstormrouter.com/v1/guardrails/providers \
  -H "Authorization: Bearer br_live_..."

Returns built-in scanners (builtin, pii, topic-restriction) plus any registered external providers.

Update config

curl -X PUT https://api.brainstormrouter.com/v1/guardrails/config \
  -H "Authorization: Bearer br_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "enabled": true,
    "mode": "block",
    "confidenceThreshold": 0.7,
    "providers": [
      {"id": "builtin", "enabled": true},
      {"id": "pii", "enabled": true}
    ]
  }'

Config fields

FieldTypeDescription
enabledbooleanMaster switch
modestringblock, warn, or log
confidenceThresholdnumberMinimum confidence to trigger (0-1)
providersarrayOrdered list of scanners to run

Register external provider

curl -X POST https://api.brainstormrouter.com/v1/guardrails/providers \
  -H "Authorization: Bearer br_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "id": "lakera",
    "name": "Lakera Guard",
    "endpoint": "https://api.lakera.ai/v1/guard",
    "api_key": "lk_...",
    "template": "lakera"
  }'

For custom providers without a template, specify result_mapping:

{
  "id": "custom-guard",
  "name": "My Guard",
  "endpoint": "https://guard.example.com/scan",
  "result_mapping": {
    "safe": "$.result.is_safe",
    "confidence": "$.result.score",
    "reason": "$.result.reason"
  }
}

Test pipeline

curl -X POST https://api.brainstormrouter.com/v1/guardrails/test \
  -H "Authorization: Bearer br_live_..." \
  -H "Content-Type: application/json" \
  -d '{"text": "My credit card is 4111-1111-1111-1111"}'
{
  "result": {
    "safe": false,
    "matches": [{ "type": "pii", "subtype": "credit_card" }],
    "scannersRun": 2,
    "durationMs": 3
  },
  "providers": {
    "resolved": ["builtin", "pii"],
    "failed": []
  }
}