HITLConcepts

Actions and policies

What the gate reviews (an Action) and how a YAML policy decides allow, ask or deny.

Code blocks on this page are excerpts of tested programs; each block's title names its file in examples/, where the complete program runs.

Action

An Action is one proposed side effect. The gate builds it from a tool call: the gated function, an adapter (LangGraph, Claude Agent SDK, OpenAI Agents SDK, Vercel AI SDK) or your own gate.authorize(action) call.

tool: issue_refund
args: { order_id: A-1002, amount: 900 }   # the tool's arguments, never transformed
call_id: call_1                           # the framework's tool call id, when there is one
actor: { id: "user:42", roles: [support] } # who the agent acts for
resource: "order:A-1002"                  # optional
tenant: acme                              # optional; partitions stores, grants, limits and policy overlays
context: { thread_id: t-9, env: production }

The gate freezes args the moment it builds the Action: it serializes them as RFC 8785 canonical JSON (JCS) and works only with that frozen copy from then on. The action digest covers the tool, the args digest, the actor id, the resource, the tenant, the call id (or a per-call nonce) and the context paths any rule reads. Approvals bind to it: a staging approval never matches a production action, while context keys no rule reads (trace ids, timestamps) do not break a resume.

Policy

A policy is one or more YAML documents (hitl/policy/v1). With no argument the gate loads policies/*.yaml; you can also pass a path, a folder, a list, or the same document inline.

policies/campaigns.yaml
# Internal test sends go out on their own. A send to customers needs marketing (in Slack) and compliance (a
# webhook to the compliance service). Both must approve.
approvers:
  marketing:
    channel: slack
    to: "#campaign-approvals"
    members: ["slack:UMAYA"]
    timeout: 24h
  compliance:
    channel: compliance # the webhook channel named "compliance"
    members: ["webhook:compliance:bot"] # webhook reviewers are webhook:<channel>:<by>
    timeout: 24h

rules:
  test-sends:
    allow: send_campaign
    when: { args: { audience: internal } }
  customer-sends:
    ask: send_campaign
    unless: { args: { audience: internal } }
    approver: [marketing, compliance]
    reason: Customer sends need marketing and compliance

tests:
  - action: { tool: send_campaign, args: { campaign: spring-sale, audience: internal } }
    expect: allow
  - action: { tool: send_campaign, args: { campaign: spring-sale, audience: all-customers } }
    expect: { effect: ask, rules: [customer-sends], approvers: [marketing, compliance] }

Each rule has exactly one of allow, ask or deny, naming a tool, a glob ("delete_*", "*") or a list. when and unless are Viewport Matchers over the action document { args, actor, resource, tenant, context, risk }: gt, gte, lt, contains, regex, any_of, not and the rest. An ask rule names its approver (one name, or a list where every approver must approve). The full schema is in the policy reference.

Inline policies are the same document. This gate from the approval-expires example declares its approver and rule in code:

examples/python/approval-expires/main.py (excerpt)
clock = FakeClock("2026-11-25T10:00:00Z")
gate = hitl.Gate(
    {
        "approvers": {"treasury": {"channel": "pager", "timeout": "4h"}},  # on_timeout defaults to deny
        "rules": {"wires": {"ask": "send_wire", "approver": "treasury", "reason": "Wires need treasury"}},
    },
    channels=[pager],
    clock=clock,
)


@gate
async def send_wire(to: str, amount: float) -> str:
    return f"Sent ${amount:g} to {to}"
examples/ts/approval-expires/main.ts (excerpt)
const clock = new FakeClock("2026-11-25T10:00:00Z");
const gate = new Gate(
  {
    approvers: { treasury: { channel: "pager", timeout: "4h" } }, // on_timeout defaults to deny
    rules: { wires: { ask: "send_wire", approver: "treasury", reason: "Wires need treasury" } },
  },
  { channels: [pager], clock },
);

const sendWire = gate.tool({
  name: "send_wire",
  input_schema: {
    type: "object",
    properties: { to: { type: "string" }, amount: { type: "number" } },
    required: ["to", "amount"],
  },
  execute: async ({ to, amount }) => `Sent $${amount} to ${to}`,
});

A mapping whose values are all bare effects is shorthand for one rule per entry: {"lookup_*": "allow", "issue_refund": "ask"}.

Fail closed

SituationResult
No rule matchesdefault (deny when unset)
Invalid policy, unknown approver, duplicate rule idPolicyError when the gate is built or reloaded; a failed reload keeps the old policy
A condition cannot be evaluated (gt on a string)Applies in deny and ask rules, not in allow rules
A key the condition reads is missingNot a match. Use exists: true to require it
Arguments fail the tool's input schemaDenied (hitl.invalid_args or core's core.tool_args_invalid) before any rule runs
A risk scorer throws or times outScores 100
ask with no reachable approverDenied, hitl.no_approver
Store unreachableDenied, hitl.store_unavailable
Timeouton_timeout, default deny
A receipt written before execution failsDenied, hitl.receipt_failed

Risk

Rules can match on risk, an integer 0 to 100 computed before rules run from named scorers you register in code (gate.scorer("pii-in-args", fn) in both languages, or scorers when you build the gate) and list under risk: in the policy. Scores add up and clamp to 0..100. A scorer that throws or times out (1 s by default) scores 100, and a scorer the policy names but nobody registered scores 100 too.

On this page