check, evaluate, and guard you pass a single identifier (one string per call). It can be:
- Policy key — a single policy key, e.g.
'amount-minimum-usd' - Tag — the tag name with a
#prefix, e.g.'#payments'. All policies with that tag are evaluated; their results are combined into one outcome.
check(policyKeyOrTag, input) — conditions
Evaluates a conditions policy. input must be an object (e.g. request/response data).
Signature
| Parameter | Type | Required | Description |
|---|---|---|---|
policyKeyOrTag | string | Yes | Policy key (e.g. 'amount-minimum-usd') or tag (e.g. '#payments'). |
input | Record<string, unknown> | Yes | Request/response data object. |
Promise<PolicyEvaluationResult>. See Result shape below.
Throws: InvalidPolicyKeyError, InvalidInputError, APIRequestError, NetworkError, TimeoutError.
evaluate(policyKeyOrTag, prompt, response) — instructions
Evaluates an instructions policy (prompt + LLM response). Typically used in middleware to validate LLM outputs before returning them.
Signature
| Parameter | Type | Required | Description |
|---|---|---|---|
policyKeyOrTag | string | Yes | Policy key or tag (e.g. '#refunds'). |
prompt | string | Yes | User prompt. |
response | string | Yes | LLM response to validate. |
Promise<PolicyEvaluationResult>.
guard(policyKeyOrTag, input) — guardrails
Evaluates a guardrails policy on text. input must be a string. Typically used in middleware to check model output (e.g. safety, PII) before sending to the user.
Signature
| Parameter | Type | Required | Description |
|---|---|---|---|
policyKeyOrTag | string | Yes | Policy key or tag (e.g. '#safety'). |
input | string | Yes | Text to check (e.g. model output). |
Promise<PolicyEvaluationResult>.
Result shape
The API returns a response withmeta and result; the SDK normalizes this to the PolicyEvaluationResult shape below. All three methods return a PolicyEvaluationResult:
| Field | Type | Description |
|---|---|---|
data | object | Always present. |
data.action | 'ALLOW' | 'BLOCK' | 'ESCALATE' | Decision. |
data.reason | string | Human-readable reason. |
isAllowed | boolean | data.action === 'ALLOW'. |
isBlocked | boolean | data.action === 'BLOCK'. |
isEscalated | boolean | data.action === 'ESCALATE'. |
errors | string[] | undefined | Validation errors from the API when present. |
Error handling
| Error class | When it is thrown |
|---|---|
InvalidAPIKeyError | Key missing or doesn’t start with sk_. |
InvalidPolicyKeyError | Policy key/tag empty or invalid. |
InvalidInputError | Empty input where required. |
APIRequestError | API returned 4xx/5xx (error.statusCode, error.response). |
NetworkError / TimeoutError | Request failed or timed out. |