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.jsonTop level
| Key | Type | Meaning |
|---|---|---|
version | 1 | Optional. The schema version |
default | allow, ask, deny | Effect when no rule matches. Default deny. viewport-hitl check warns on allow |
approvers | map of name to approver | Named routing for ask rules |
risk | list of scorer names | Scorers registered in code; their scores add up, clamped to 0..100 |
rules | map of rule id to rule | The rules. Ids are unique and appear in decisions, receipts and events |
invariants | list of invariant/v1 | Rules over history (Invariants) |
tests | list of tests | Run 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
| Key | Type | Meaning |
|---|---|---|
allow / ask / deny | tool name, glob or list | Exactly one. The effect and the tools it applies to |
when | Matcher | Applies only when it matches the action document { args, actor, resource, tenant, context, risk } |
unless | Matcher | Does not apply when it matches |
limit | limit | Applies only when this action would go over the limit |
reason | string | Shown to approvers; returned to the model on refusal |
approver | name or list | ask only. Each name is a requirement that must be met. Default default (the terminal, or the only channel) |
quorum | integer | ask only. Approvals needed per requirement |
timeout | duration | ask only. Overrides the approver's |
on_timeout | deny, allow | ask only. Default deny. allow is flagged by check as fail-open |
edits | true, false, redacted | ask 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:
| Where | allow rule | deny or ask rule |
|---|---|---|
when (or the tool pattern) is indeterminate | does not apply | applies |
unless is indeterminate | does 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/passwdnames the same file as/etc/passwdbut does not match/etc/**. - No symlink resolution. On macOS
/etcis a link to/private/etc; a policy sees only the path the agent passed. - Relative paths are matched as written (
../secretagainst/tmp/**simply does not match). /etc/**matches paths under/etc, not/etcitself: writeany_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
| Key | Type | Meaning |
|---|---|---|
channel | channel name | Where requests go (slack, webhook, cli, web, or your channel's name) |
to | string or JSONPath | Destination on the channel ("#finance-approvals"), or a path into the action ($.context.account_owner) |
members | list, 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) |
quorum | integer | Approvals needed. One deny still ends the approval |
timeout | duration | How long the request stays open. Default: the gate's default_timeout (1h) |
on_timeout | deny, allow | Default deny |
self_approval | boolean | Allow the actor to approve their own action. Default false |
escalate | approver name | Reserved: validated, but timed escalation is not in this release |
Limit
| Key | Type | Meaning |
|---|---|---|
max | number | The ceiling |
per | duration | Sliding window: 30s, 15m, 1h, 24h, 7d |
sum | JSONPath | Sum this field instead of counting ($.args.amount). Not a number: indeterminate, so the rule applies |
by | JSONPath | Partition key ($.actor.id). Limits are always partitioned by tenant too |
unit | usd, count, units | What 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
| Key | Meaning |
|---|---|
name | Required. Decisions name it invariant:<name> |
each | Selector for the actions it governs: tool, args, ok, approval, event, where |
never, after, not_after | Selectors over earlier events |
limit | { max, by?, per?, sum? } over matching events |
same | Paths that must be equal between the action and the earlier event |
scope | thread (default), session, actor, tenant |
effect | deny (default) or ask |
followed_by | Not 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:
# 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] }