Staso Docs
Guards

Guards

Your agent is about to refund $4,200. Or drop a database. Or email every customer in your CRM.

Guards evaluate tool calls before they execute and decide what happens next: allow, block, modify the input, or escalate to a human. Every decision is recorded as a span on your dashboard.

from staso import guard

result = guard(tool_name="process_refund", tool_input={"amount": 4200, "customer_id": "cust-99"})

if result.action == "block":
    print(f"Blocked: {result.reason}")
elif result.action == "modify":
    # Guard sanitized the input
    tool_input = result.modified_input

How It Works

  1. Your agent decides to call a tool
  2. guard() sends the tool name and input to Staso for evaluation
  3. Staso runs your configured rules against the action
  4. You get back a GuardResult with the decision

Rules are configured in your Staso dashboard -- no code changes needed to add, edit, or disable them.

Four Actions

ActionWhat HappensWhen to Use
allowTool executes normallyAction passes all rules
blockTool is prevented from runningDangerous or policy-violating action
modifyTool runs with sanitized inputInput needs adjustment (PII redaction, limit capping)
escalatePaused until a human approves or deniesHigh-value or ambiguous decisions

Where Guards Run

Guards work across every Staso integration:

IntegrationHow Guards RunWhat Happens on Block
Your own agentsYou call guard() explicitlyYou decide -- raise an error, skip the tool, return a fallback
Anthropic SDKAuto-evaluated after each responseGuard results recorded on span metadata
OpenAI SDKAuto-evaluated after each responseGuard results recorded on span metadata
Claude CodeAuto-evaluated before each toolTool blocked or input modified in real-time
CodexAuto-evaluated before each toolTool blocked or input modified in real-time

Fail-Open by Default

If the guard service is unreachable or returns an error, the tool executes normally. Your agent never crashes because of a guard timeout. Guard failures are logged as warnings.

Evaluation Context Scope

Rules can evaluate at two levels:

ScopeWhat It EvaluatesBest For
Tool-levelIndividual tool call — name, input, outputGranular control: block a specific action, redact PII from one call
Trace-levelFull agent execution — all spans, tool calls, and LLM responsesEnd-to-end validation: detect multi-step policy violations, cost escalation across a session

Configure scope per rule in your dashboard. Tool-level is the default. Trace-level rules run after the full execution completes, giving them access to the entire conversation context.

Audit Mode

Every rule can run in audit mode. Audit rules evaluate and record what would have been blocked, but don't actually block anything. Use this to validate new rules before enforcing them.

On your dashboard, audit violations show up as guard:would-block spans -- so you can see exactly what would have triggered before you flip the switch.

What's Next