Skip to content

Documentation / @agentick/guardrails / toolGuardrail

Function: toolGuardrail() ​

toolGuardrail(config): Middleware

Defined in: guardrails/src/tool.ts:39

Create middleware that gates tool execution with static rules and/or a classifier.

Evaluation order:

  1. Static rules (first-match-wins). If a rule matches:
    • deny → throw GuardrailDenied
    • allow → skip classifier, proceed
  2. Classifier (if no rule matched). If it returns { action: "deny" }:
    • throw GuardrailDenied
  3. Default: allow

Only intercepts procedures with operationName === "tool:run". Other procedures pass through unmodified.

Parameters ​

config ​

ToolGuardrailConfig

Returns ​

Middleware

Example ​

typescript
import { toolGuardrail, deny, allow } from "@agentick/guardrails";

const guardrail = toolGuardrail({
  rules: [
    deny("file_delete", "exec_*"),
    allow("file_read", "file_write"),
  ],
  classify: async (call) => {
    if (call.input?.dangerous) return { action: "deny", reason: "Dangerous input" };
    return null; // allow by default
  },
});

app.use(guardrail);

Released under the ISC License.