Guides
Tool-call enforcement
Intercept agent tool calls before execution with a trusted wrapper, and know where bypass risk remains.
Most agent frameworks let the model choose a tool and arguments, then run a function you wrote. That function is your enforcement point.
A trusted tool wrapper
Wrap each tool so the authorization check runs inside the function the framework calls, after arguments are validated and before any side effect.
TypeScript
import { Reqlo, ReqloDeniedError } from "@reqlo/sdk";
import { z } from "zod";
const reqlo = new Reqlo({ apiKey: process.env.REQLO_API_KEY! });
export function protectedTool<A>(opts: {
action: string;
schema: z.ZodType<A>;
resource: (args: A, ctx: RunContext) => Promise<{ type: string; id: string; attributes?: Record<string, unknown> }>;
context?: (args: A, ctx: RunContext) => Record<string, unknown>;
run: (args: A, ctx: RunContext) => Promise<unknown>;
}) {
return async (rawArgs: unknown, ctx: RunContext) => {
const args = opts.schema.parse(rawArgs); // 1. validate model output
const resource = await opts.resource(args, ctx); // 2. authoritative lookup
try {
await reqlo.enforce({ // 3. check
agent: { id: ctx.agentId },
subject: ctx.user ? { id: ctx.user.id, kind: "user" } : undefined,
action: opts.action,
resource,
context: opts.context?.(args, ctx),
});
} catch (e) {
if (e instanceof ReqloDeniedError) return { error: "This action isn't allowed." };
throw e; // errors: never run
}
return opts.run(args, ctx); // 4. execute the checked action
};
}ctx is built by your server from the verified session; the model never supplies it.
Where bypass risk remains
- Tools that aren't wrapped. Audit your tool registry; a lint rule or registry helper that only accepts
protectedToolkeeps new tools covered. - Tools with broad credentials. A "run SQL" or "call any URL" tool can't be authorized meaningfully. Prefer narrow tools with specific actions.
- Indirect execution. If a tool enqueues a job, check in the worker too, or bind the decision ID to the job and verify it hasn't expired. See Queues and jobs.
- Concurrency. Two parallel calls can each pass a per-request rule. Enforce cumulative limits atomically in your own system.
Framework guides
Something wrong or unclear? Report an issue with this page.