Guardrails API
Endpoints for evaluating content against guardrail rules, evaluating a single lifecycle hook from your own enforcement point, and listing the guardrails a token can use.
Hook plane (September 2026)
Guardrails now attach at six lifecycle hooks (prompt.pre, input.pre, output.pre, output.stream.delta, tool.pre, tool.post) across nine policy families, each with its own enforce/monitor mode. The /evaluate contract below is unchanged; /hooks/evaluate evaluates one hook; see the Guardrails guide for the hook model and the full family list.
Evaluate
POST /api/client/v1/guardrails/evaluateRequest
{
"guardrail_key": "pii-checker",
"text": "My email is john@example.com and my phone is 555-0100"
}Parameters
| Field | Type | Required | Description |
|---|---|---|---|
guardrail_key | string | Yes | Key of the guardrail to evaluate |
text | string | Yes | Content to evaluate |
Response
{
"passed": false,
"guardrail_key": "pii-checker",
"guardrail_name": "PII Checker",
"action": "flag",
"findings": [
{ "category": "email", "message": "Email address detected", "block": false },
{ "category": "phone", "message": "Phone number detected", "block": false }
],
"message": null
}Response Fields
| Field | Description |
|---|---|
passed | true if no findings triggered, false otherwise |
guardrail_key | Key of the evaluated guardrail |
guardrail_name | Display name |
action | Configured action: block, flag, or redact |
findings | Array of detected issues |
message | Optional message for blocked content |
List guardrails
GET /api/client/v1/guardrailsLists the guardrail definitions the token can address: its own project plus workspace-level guardrails (the same set /guardrails/hooks/evaluate accepts). The tenant and project come from the token. Needs read on the guardrails service.
| Query | Description |
|---|---|
enabled | true or false. |
type | preset or custom. Any other value is 400. |
search | Text filter. |
{
"guardrails": [
{
"key": "no-destructive-shell",
"name": "No destructive shell",
"type": "preset",
"enabled": true,
"effectiveMode": "enforce",
"hooksSummary": {
"contractVersion": 2,
"authored": true,
"servable": ["tool.pre"],
"bindings": { "tool.pre": { "enabled": true, "timing": "sync", "onFail": "block" } },
"policies": [
{ "id": "p1", "family": "tool_access", "enabled": true, "hooks": ["tool.pre"], "action": "block" }
],
"stream": null
}
}
]
}Each item is the stored guardrail record without its hooks configuration (which can hold webhook credentials), plus:
| Field | Description |
|---|---|
effectiveMode | enforce, monitor or disabled: the guardrail's mode with enabled folded in. |
hooksSummary.servable | The hooks /guardrails/hooks/evaluate will actually evaluate for this guardrail. A hook outside this list answers with an allow. |
hooksSummary.bindings | Per hook: enabled, timing (sync or async), onFail (block or log), failMode, timeoutMs. |
hooksSummary.policies | What runs (id, family, enabled, label, hooks, action), never how it is configured. |
hooksSummary.authored | false when the hook configuration was derived from an older guardrail on read. |
There is no route to read one guardrail by key; filter the list with search. Guardrails are created with POST /guardrails and changed with PATCH and DELETE /guardrails/{key}; those need write access and are described in the OpenAPI Specification.
Evaluate a hook
POST /api/client/v1/guardrails/hooks/evaluateFor an enforcement point that runs outside Cognipeer (a coding agent, a proxy, your own application). It evaluates one lifecycle hook against one or more guardrails and returns the merged verdict. Needs write on the guardrails service.
The tenant, project and actor come from the API token. There is no field for them in the body, so a caller cannot evaluate as someone else.
Request
{
"hook": "tool.pre",
"guardrail_keys": ["no-destructive-shell"],
"tool_name": "bash",
"tool_args": { "command": "rm -rf /srv/data" },
"request_id": "7f3c1a9e-run-42"
}| Field | Required | Description |
|---|---|---|
hook | Yes | prompt.pre, input.pre, output.pre, output.stream.delta, tool.pre or tool.post. |
guardrail_keys | Yes* | Guardrail keys whose verdicts merge. guardrail_key (one string) is accepted too. *One of the two. |
text | For prompt.pre, input.pre, output.pre | The content to evaluate. |
tool_name | For tool.pre, tool.post | The tool being called. |
tool_args | No | An object with the call arguments. |
tool_result | For tool.post | The tool's result (any JSON). |
requested_name | No | tool.pre: the name as the model requested it, when it was aliased. |
buffer | For output.stream.delta | The full accumulated output text. |
delta, released_to, seq, final | No | output.stream.delta: the new text, how much of the buffer was already released, a sequence number and whether the stream ended. |
only | No | Limit evaluation to these policy families. |
budget_ms | No | A time budget in milliseconds. |
request_id | No | Your correlation id. It is reused as the verdict's trace_id. |
Response
{
"hook": "tool.pre",
"decision": "block",
"would_be_decision": "block",
"enforced": true,
"mode": "enforce",
"passed": false,
"findings": [{ "category": "destructive_command", "message": "Blocked by tool policy", "block": true }],
"mutations": [],
"subject": null,
"redacted_text": null,
"risk_score": 0.9,
"codes": ["tool_denied"],
"blocked_message": { "…": "…" },
"message": "…",
"guardrail_key": "no-destructive-shell",
"guardrail_keys": ["no-destructive-shell"],
"trace_id": "7f3c1a9e-run-42",
"latency_ms": 12,
"degraded": [],
"cancelled": []
}| Field | Description |
|---|---|
decision | allow, flag, warn, redact or block. In monitor mode a block is reported as a pass with findings. |
would_be_decision | What enforcement would have decided; differs from decision in monitor mode. |
enforced, mode | Whether the decision was enforced, and enforce, monitor or disabled. |
passed | true when there was no blocking finding. It is not "the request was allowed": the two differ in monitor mode. |
subject | The rewritten content. Present only when a redaction was applied; substitute it for what you sent. |
blocked_message | The rendered message for the end user, with its reason class. |
degraded, cancelled | Policies that could not run, or that were stopped before they finished. Their absence from findings is explained here. |
The verdict is repeated in x-cognipeer-guardrail-* response headers (x-cognipeer-guardrail, -key, -hook, -mode, -enforced, -trace-id, and -risk and -codes when detailed headers are on). The x-aegis-* headers are deprecated aliases.
The status is 200. If any named guardrail opts into verdict status codes, it is 246 (passed with findings) or 446 (blocked) instead.
A key that does not exist in the token's scope is 404; an unknown hook or a missing subject field is 400.
Policy Families
| Family | Evaluation Method |
|---|---|
| Personal data (PII) | Regex-based pattern matching (15 categories) |
| Credentials | Pattern + entropy matching |
| Word Filter | Deterministic list/regex matching |
| Moderation | LLM classifier |
| Prompt Shield | LLM classifier (prompt injection detection) |
| Tool Access | Deterministic tool allow/deny policy |
A guardrail's type (preset vs custom) is separate from its policy families — custom runs an LLM judged against your own rule text instead of the bundled families above.
Inference Integration
Guardrails can be attached to models and evaluated automatically during chat completions. When a guardrail blocks a request, the chat API returns:
{
"error": {
"type": "guardrail_block",
"guardrail_key": "pii-checker",
"action": "block",
"findings": [...]
}
}Errors
| Status | Description |
|---|---|
| 400 | Missing guardrail_key or text |
| 401 | Invalid API token |
| 404 | Guardrail not found |

