A guard is a name plus a before hook (looks at the call), an after hook (looks at the result), or both. define builds one from functions.
guards.define("no-weekend-refunds", (call) => call.tool === "refund_invoice" && [0, 6].includes(new Date().getUTCDay()) ? call.guide("Refunds wait until Monday; offer to schedule one.") : call.proceed());| Language | Signature |
|---|---|
| TypeScript | guards.define(name, before, { mode?, after? }) |
| Python | guards.define(name, before=None, *, after=None, mode=None) |
| Ruby | Scute::Guards.define(name, mode: nil, after: nil) { |call| ... } |
Returning nothing (undefined, None, nil) means proceed. Throwing counts as deny when the guard is enforced.
The call#
| Field | Meaning |
|---|---|
| id | The tool call id (from the framework, or random) |
| tool | The tool name |
| args | The arguments, after any earlier guard's transform. Ruby uses symbol keys. |
| permission, tier, resource | From the tool mapping |
| spec | The full mapping: permission, action, resourceType (resource_type), tier |
| messages | The conversation, when the integration passed it |
| approvedByUser | The person confirmed this exact call in the framework (Python approved_by_user, Ruby approved_by_user?) |
| mode | The mode of the guard looking at the call |
| clear | No enforced guard so far stops the call |
| run | The run, for state such as verifiedAt() or snapshot() |
Answers#
| Helper | Decision |
|---|---|
| call.proceed() | proceed |
| call.transform(args, message?) | transform: run with these arguments (the full set) |
| call.approve(message?) | approve by the person (approve.by is user) |
| call.verify(message?, options?) | verify, options method, methods, permission (default: the call's permission) |
| call.guide(message, reason?) | guide, default reason guided |
| call.redirect(to, message?) | redirect to another tool or route |
| call.deny(message, reason?) | deny, default reason denied |
In Python, call.verify(message, methods=[...]) takes options as keywords; in Ruby, call.verify(message, methods: [...]).
After hooks#
An after hook gets the call and the result and can replace what the model reads. Return a decision with a result to replace it; a guide, redirect or deny without one replaces the result with { "error": "<message>" }.
guards.define("hide-internal-notes", () => undefined, { after: (call, result) => call.tool === "read_ticket" && result && typeof result === "object" ? { kind: "transform", reason: "redacted", result: { ...result, internal_notes: undefined } } : undefined,});A full guard#
For state, options or side effects, write the guard yourself.
import type { Guard } from "@scute/harness";const businessHours: Guard = { name: "business-hours", mode: "monitor", before(call) { const hour = new Date().getUTCHours(); if (call.tier === "high" && (hour < 8 || hour >= 18)) return call.deny("High-risk actions run in business hours only.", "after_hours"); },};- A guard with side effects (sending a push, filing a request) should act only when call.mode is enforce.
- A guard that spends a single-use proof should act only when call.clear is true. TypeScript guards can set runsLast: true to run after the others; in Python set the class attribute runs_last = True; in Ruby define runs_last? to return true.