Skip to content

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/evaluate

Request ​

json
{
  "guardrail_key": "pii-checker",
  "text": "My email is john@example.com and my phone is 555-0100"
}

Parameters ​

FieldTypeRequiredDescription
guardrail_keystringYesKey of the guardrail to evaluate
textstringYesContent to evaluate

Response ​

json
{
  "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 ​

FieldDescription
passedtrue if no findings triggered, false otherwise
guardrail_keyKey of the evaluated guardrail
guardrail_nameDisplay name
actionConfigured action: block, flag, or redact
findingsArray of detected issues
messageOptional message for blocked content

List guardrails ​

GET /api/client/v1/guardrails

Lists 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.

QueryDescription
enabledtrue or false.
typepreset or custom. Any other value is 400.
searchText filter.
json
{
  "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:

FieldDescription
effectiveModeenforce, monitor or disabled: the guardrail's mode with enabled folded in.
hooksSummary.servableThe hooks /guardrails/hooks/evaluate will actually evaluate for this guardrail. A hook outside this list answers with an allow.
hooksSummary.bindingsPer hook: enabled, timing (sync or async), onFail (block or log), failMode, timeoutMs.
hooksSummary.policiesWhat runs (id, family, enabled, label, hooks, action), never how it is configured.
hooksSummary.authoredfalse 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/evaluate

For 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 ​

json
{
  "hook": "tool.pre",
  "guardrail_keys": ["no-destructive-shell"],
  "tool_name": "bash",
  "tool_args": { "command": "rm -rf /srv/data" },
  "request_id": "7f3c1a9e-run-42"
}
FieldRequiredDescription
hookYesprompt.pre, input.pre, output.pre, output.stream.delta, tool.pre or tool.post.
guardrail_keysYes*Guardrail keys whose verdicts merge. guardrail_key (one string) is accepted too. *One of the two.
textFor prompt.pre, input.pre, output.preThe content to evaluate.
tool_nameFor tool.pre, tool.postThe tool being called.
tool_argsNoAn object with the call arguments.
tool_resultFor tool.postThe tool's result (any JSON).
requested_nameNotool.pre: the name as the model requested it, when it was aliased.
bufferFor output.stream.deltaThe full accumulated output text.
delta, released_to, seq, finalNooutput.stream.delta: the new text, how much of the buffer was already released, a sequence number and whether the stream ended.
onlyNoLimit evaluation to these policy families.
budget_msNoA time budget in milliseconds.
request_idNoYour correlation id. It is reused as the verdict's trace_id.

Response ​

json
{
  "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": []
}
FieldDescription
decisionallow, flag, warn, redact or block. In monitor mode a block is reported as a pass with findings.
would_be_decisionWhat enforcement would have decided; differs from decision in monitor mode.
enforced, modeWhether the decision was enforced, and enforce, monitor or disabled.
passedtrue when there was no blocking finding. It is not "the request was allowed": the two differ in monitor mode.
subjectThe rewritten content. Present only when a redaction was applied; substitute it for what you sent.
blocked_messageThe rendered message for the end user, with its reason class.
degraded, cancelledPolicies 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 ​

FamilyEvaluation Method
Personal data (PII)Regex-based pattern matching (15 categories)
CredentialsPattern + entropy matching
Word FilterDeterministic list/regex matching
ModerationLLM classifier
Prompt ShieldLLM classifier (prompt injection detection)
Tool AccessDeterministic 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:

json
{
  "error": {
    "type": "guardrail_block",
    "guardrail_key": "pii-checker",
    "action": "block",
    "findings": [...]
  }
}

Errors ​

StatusDescription
400Missing guardrail_key or text
401Invalid API token
404Guardrail not found

Studio · Pulse · Console · Agent SDK and more — the Cognipeer documentation hub