HITLReference

Policy schema

Every key of a hitl/policy/v1 document, with types, defaults and what the gate does with it.

The JSON Schema ships in the package (@viewportai/hitl/schemas/policy/v1.json) and is published at https://getviewport.com/schemas/hitl/policy/v1.json. Point your editor at it:

# yaml-language-server: $schema=https://getviewport.com/schemas/hitl/policy/v1.json

Top level

KeyTypeMeaning
version1Optional. The schema version
defaultallow, ask, denyEffect when no rule matches. Default deny. viewport-hitl check warns on allow
approversmap of name to approverNamed routing for ask rules
risklist of scorer namesScorers registered in code; their scores add up, clamped to 0..100
rulesmap of rule id to ruleThe rules. Ids are unique and appear in decisions, receipts and events
invariantslist of invariant/v1Rules over history (Invariants)
testslist of testsRun by viewport-hitl test and the pytest plugin

Several files (policies/*.yaml) merge: rules and approvers are unioned and a duplicate id is a load error; the effective default is the most restrictive. Files under policies/tenants/<tenant>/ add rules only for actions with that tenant, so a tenant can tighten the base policy but never loosen it: the base policy (its rules and its default) is evaluated on its own and the more restrictive outcome wins, overlay rules may only ask or deny, and on_timeout: allow is a load error in an overlay.

Rule

KeyTypeMeaning
allow / ask / denytool name, glob or listExactly one. The effect and the tools it applies to
whenMatcherApplies only when it matches the action document { args, actor, resource, tenant, context, risk }
unlessMatcherDoes not apply when it matches
limitlimitApplies only when this action would go over the limit
reasonstringShown to approvers; returned to the model on refusal
approvername or listask only. Each name is a requirement that must be met. Default default (the terminal, or the only channel)
quorumintegerask only. Approvals needed per requirement
timeoutdurationask only. Overrides the approver's
on_timeoutdeny, allowask only. Default deny. allow is flagged by check as fail-open
editstrue, false, redactedask only. Approvers may approve edited arguments, which the policy re-evaluates. redacted also allows edits when the request was redacted; the edit must replace every redaction marker with a real value

A mapping whose values are all bare effects is shorthand: rules: { "lookup_*": allow, issue_refund: ask } is one rule per entry, with the pattern as its id.

Conditions

when and unless are Viewport matchers. An object whose keys are all operators (gt, regex, any_of...) applies those operators; any other object is a field pattern, matching each key as a field of the value. A key that is a comparison or equality word from another language (greater, less_than, eq, ne, matches, like and similar) with a scalar or list value would compare the field to an object and never decide, so it is a load error (unknown_operator, with the file, line, path and the operator to use). A field really named like that is matched with { fields: { greater: 5 } }, which is not checked. Ordinary field names such as max, min or in are never rejected: they stay indeterminate when misused, and the reason suggests the operator ({ in: [...] } on a string: "did you mean any_of?").

A real field named like an operator. The error says how: use fields: { above: ... } if this is a real field. { fields: { above: 5 } } matches a field literally called above and is never checked.

Unknown never produces an allow. A condition that cannot be decided at run time (a typed operator meets the wrong type, a path that climbs above the root, a field pattern applied to a number) is indeterminate:

Whereallow ruledeny or ask rule
when (or the tool pattern) is indeterminatedoes not applyapplies
unless is indeterminatedoes not apply (the exception may hold)applies (the exception is not established)

not of an indeterminate condition stays indeterminate. A missing field is not indeterminate: it is a plain non-match. So in allow: read_file, unless: { args: { path: { glob: "/home/me/.ssh/**" } } } a call without path is allowed (the exception does not hold), while a path that is a number or an object is indeterminate (not allowed). When the field must be present, require it in when: when: { args: { path: { exists: true } } }.

Path globs. A glob pattern containing / matches the path after lexical normalization, as in Viewport core: // and ./ collapse and .. resolves inside the path, so /tmp/a/../b matches /tmp/** and /tmp/../etc/passwd does not. A .. that would climb above the root, or a NUL byte, makes the condition indeterminate (an allow rule does not apply; a deny or ask rule does), and a pattern that itself contains a .. segment is a load error (glob_invalid). The rules are core's matcher semantics; HITL applies them through its tri-state. Limits to keep in mind:

  • Case-sensitive. On a case-insensitive filesystem (APFS and NTFS by default) /ETC/passwd names the same file as /etc/passwd but does not match /etc/**.
  • No symlink resolution. On macOS /etc is a link to /private/etc; a policy sees only the path the agent passed.
  • Relative paths are matched as written (../secret against /tmp/** simply does not match).
  • /etc/** matches paths under /etc, not /etc itself: write any_of: [{ equals: /etc }, { glob: "/etc/**" }].
  • Deny rules should cover every form that names the protected files (case variants, symlinked aliases such as /private/etc), and a tool that opens files should resolve the real path and check it again.

Approver

KeyTypeMeaning
channelchannel nameWhere requests go (slack, webhook, cli, web, or your channel's name)
tostring or JSONPathDestination on the channel ("#finance-approvals"), or a path into the action ($.context.account_owner)
memberslist, or { permission }Who may answer: channel identities, namespaced by the receiving channel's name (slack:U01ABC, slack_fin:U01ABC for a Slack channel named slack_fin, webhook:<channel>:<by>, console:<user>), or a permission your gate's reviewer checks. An entry from another channel is a check error. Omitted: anyone the channel authenticates (check warns)
quorumintegerApprovals needed. One deny still ends the approval
timeoutdurationHow long the request stays open. Default: the gate's default_timeout (1h)
on_timeoutdeny, allowDefault deny
self_approvalbooleanAllow the actor to approve their own action. Default false
escalateapprover nameReserved: validated, but timed escalation is not in this release

Limit

KeyTypeMeaning
maxnumberThe ceiling
perdurationSliding window: 30s, 15m, 1h, 24h, 7d
sumJSONPathSum this field instead of counting ($.args.amount). Not a number: indeterminate, so the rule applies
byJSONPathPartition key ($.actor.id). Limits are always partitioned by tenant too
unitusd, count, unitsWhat sum measures

The rule applies when usage plus this action would exceed max. Usage is reserved atomically when the action is about to run and committed when it succeeds.

Invariant

KeyMeaning
nameRequired. Decisions name it invariant:<name>
eachSelector for the actions it governs: tool, args, ok, approval, event, where
never, after, not_afterSelectors over earlier events
limit{ max, by?, per?, sum? } over matching events
samePaths that must be equal between the action and the earlier event
scopethread (default), session, actor, tenant
effectdeny (default) or ask
followed_byNot enforceable before the fact: a load error here, an assertion in Viewport Evals

Test

Each test has an action, an expect (an effect, or { effect, rules?, approvers? }), an optional name, and optional facts: store state such as limit usage by rule id (usage: { daily-refund-budget: 450 }) or grants, so tests stay pure. From the quickstart policy:

policies/refunds.yaml
# Refunds up to $50 run on their own. Larger ones wait for someone on the support desk.
approvers:
  support:
    channel: support-desk
    members: ["desk:dana", "desk:omar"]
    timeout: 4h

rules:
  refunds: { allow: issue_refund }
  negative-refunds:
    deny: issue_refund
    when: { args: { amount: { lt: 0 } } }
    reason: A refund amount cannot be negative
  large-refunds:
    ask: issue_refund
    when: { args: { amount: { gt: 50 } } }
    approver: support
    reason: Refunds over $50 need a human

tests:
  - action: { tool: issue_refund, args: { order_id: A-1001, amount: 20 } }
    expect: allow
  - action: { tool: issue_refund, args: { order_id: A-1002, amount: 900 } }
    expect: { effect: ask, rules: [large-refunds] }
  - action: { tool: issue_refund, args: { order_id: A-1003, amount: -900 } }
    expect: { effect: deny, rules: [negative-refunds] }

On this page