Skip to main content

Guardrails

Policy rules plus the evaluation log. Evaluating a proposed action checks it against every enabled rule — the strictest matching rule wins (block beats approve beats allow) — and records the verdict.

All endpoints require a Bearer JWT in the Authorization header plus an X-Workspace-Id header selecting the workspace.

Rules

GET/api/guardrails/rulesAuth required

List policy rules ordered by name.

Query Parameters

FieldTypeRequiredNote
enabledbooleanNo—

Response

[
  {
    "id": 1,
    "workspace_id": 1,
    "name": "AE spend cap",
    "rule_kind": "spend_cap",
    "action_kind": "spend",
    "threshold_cents": 500000,
    "verdict": "approve",
    "required_approvals": 1,
    "enabled": true
  }
]
POST/api/guardrails/rulesAuth required

Create a policy rule. Returns 422 for an unknown verdict.

Request Body

FieldTypeRequiredNote
namestringYesRequired
rule_kindstringYesspend_cap | approval_threshold | flagged_account | first_of_kind
action_kindstringNoRestricts the rule to one action kind
threshold_centsnumberNoUsed by spend_cap / approval_threshold
windowstringNo—
max_countnumberNo—
account_refstringNoUsed by flagged_account
verdictstringNoallow | approve | block. Default 'approve'
required_approvalsnumberNoDefault 1
enabledbooleanNoDefault true

Response

{
  "id": 2,
  "name": "Block flagged vendor",
  "rule_kind": "flagged_account",
  "account_ref": "sketchy-vendor",
  "verdict": "block",
  "enabled": true
}
GET/api/guardrails/rules/{rule_id}Auth required

Get a single policy rule.

Response

{
  "id": 1,
  "name": "AE spend cap",
  "rule_kind": "spend_cap",
  "action_kind": "spend",
  "threshold_cents": 500000,
  "verdict": "approve",
  "required_approvals": 1,
  "enabled": true
}
PATCH/api/guardrails/rules/{rule_id}Auth required

Update a rule. All fields optional; returns 400 when no fields are provided.

Request Body

FieldTypeRequiredNote
namestringNo—
rule_kindstringNo—
action_kindstringNo—
threshold_centsnumberNo—
windowstringNo—
max_countnumberNo—
account_refstringNo—
verdictstringNo—
required_approvalsnumberNo—
enabledbooleanNo—

Response

{ "id": 1, "name": "AE spend cap", "threshold_cents": 1000000, "enabled": true }
DELETE/api/guardrails/rules/{rule_id}Auth required

Delete a policy rule.

Response

{ "deleted": 1 }

Evaluation

POST/api/guardrails/evaluateAuth required

Check a proposed action against the enabled rules and record the verdict. Strictest matching rule wins.

Request Body

FieldTypeRequiredNote
action_kindstringYesRequired, e.g. 'spend'
amount_centsnumberNoDefault 0
account_refstringNo—
actorstringNo—

Response

{
  "verdict": "approve",
  "reason": "AE spend cap: $6,000 is over the $5,000 cap",
  "policy_id": 1,
  "required_approvals": 1,
  "suggested_rule": null
}
GET/api/guardrails/evalsAuth required

List recorded evaluation verdicts, newest first.

Query Parameters

FieldTypeRequiredNote
verdictstringNoallow | approve | block
limitnumberNoDefault 50, max 200

Response

[
  {
    "id": 7,
    "workspace_id": 1,
    "rule_id": 1,
    "rule_name": "AE spend cap",
    "action_kind": "spend",
    "amount_cents": 600000,
    "account_ref": null,
    "actor": "jane",
    "verdict": "approve",
    "reason": "AE spend cap: $6,000 is over the $5,000 cap"
  }
]