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:
- Static rules (first-match-wins). If a rule matches:
deny→ throwGuardrailDeniedallow→ skip classifier, proceed
- Classifier (if no rule matched). If it returns
{ action: "deny" }:- throw
GuardrailDenied
- throw
- Default: allow
Only intercepts procedures with operationName === "tool:run". Other procedures pass through unmodified.
Parameters ​
config ​
Returns ​
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);