Skip to main content

viewport-hitl

Human approval and policy gates before agent side effects. Declare in YAML what an agent may do alone, what needs a person, and what it may never do. HITL enforces it at the tool boundary, asks the right people through the right channel, survives restarts while it waits, binds every approval to the exact arguments that were approved, and writes a hash-chained receipt for all of it.

Status: beta (v0.1). Python >= 3.11. The TypeScript twin is @viewportai/hitl; both pass the same conformance vectors.

pip install viewport-hitl   # or: uv add viewport-hitl

To build from source, see https://github.com/viewportai/hitl#from-source.

Extra Adds
slack hitl.slack(...) (httpx)
postgres hitl.postgres(dsn) (psycopg 3)
sign Ed25519 verification for hitl.console(...) reviews (cryptography)
otel OpenTelemetry spans (opentelemetry-api)
langgraph, claude-agent-sdk, openai-agents, pydantic-ai the framework adapter of the same name

hitl.sqlite(path), hitl.webhook(...), hitl.web(...) and hitl.terminal() need no extra.

Quickstart

Runs with no API key. Save the program below as quickstart.py and the policy that follows as policies/refunds.yaml, next to it:

from pathlib import Path

from viewportai import hitl

gate = hitl.Gate(Path(__file__).parent / "policies" / "refunds.yaml")


@gate
def issue_refund(order_id: str, amount: float) -> str:
    return f"Refunded ${amount:g} on {order_id}"


print(issue_refund("A-1001", 20))  # policy allows it: runs now

try:
    print(issue_refund("A-1002", 900))  # asks you in the terminal first
except hitl.ActionDenied as denied:
    print(denied.status, denied.message)  # your "no", or no terminal to ask: denied
# policies/refunds.yaml
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 } } }
    reason: Refunds over $50 need a human

Run it with python quickstart.py. With no terminal attached it prints Refunded $20 on A-1001, then denied No approver or channel is available for "default"; on a terminal the $900 refund asks you first.

The package installs a viewport-hitl command (check policies, explain decisions, verify receipts): viewport-hitl --help.

The most restrictive matching rule wins (deny > ask > allow), so a broad allow can never mask a narrow deny. Anything no rule mentions is denied. Sync functions stay sync, async functions stay async; issue_refund.tool is a core Tool for any adapter.

Production shape

A durable store shares approvals, limits, grants and receipts across processes (hitl.postgres(dsn) the same way):

def process_start() -> hitl.Gate:
    """One process: a fresh gate on the shared SQLite file, with receipts in the same file."""
    # redact_key="store" keeps a development redaction key in the store; production sets VIEWPORT_REDACT_KEY.
    return hitl.Gate(POLICY, store=hitl.sqlite(DB), receipts=True, clock=clock, redact_key="store")


invoice = {"tool": "send_invoice", "args": {"invoice_id": "INV-7"}, "call_id": "call_1"}
key = "workflow-42:step-3"  # your runtime's stable step identity

Channels are referenced by name from YAML approvers; their answers arrive through one ASGI app:

clock = FakeClock("2026-11-25T10:00:00Z")
gate = hitl.Gate(
    POLICY,
    mode="suspend",  # a web app: never block a request waiting for a human
    clock=clock,
    channels=[
        hitl.slack(token="xox" + "b-your-bot-token", signing_secret=SLACK_SIGNING_SECRET, transport=slack_api),
        hitl.webhook(
            name="compliance",
            url="https://compliance.example/hitl",
            secret=OUTBOUND_SECRET,
            inbound_secret=INBOUND_SECRET,  # a receiver of the requests cannot sign answers
            transport=compliance,
            now=clock.now,
        ),
    ],
)


@gate
async def send_campaign(campaign: str, audience: str) -> str:
    return f"Sent {campaign} to {audience}"


# Mount this at /hitl in your ASGI app: Slack buttons and webhook replies land here.
webhooks = gate.webhooks(base_path="/hitl")

Suspend instead of waiting, so any process can answer later:

action = {"tool": "send_wire", "args": {"to": "ACME-002", "amount": 9_000}, "call_id": "call_2"}
auth = await gate.authorize(action, wait=False)  # returns "pending" at once
assert auth.approval is not None
approval_id = auth.approval.id

clock.advance(FOUR_HOURS)  # nobody answered
swept = await gate.sweep()  # optional: expiry is also applied lazily on every read

late = await gate.respond(approval_id, hitl.approve(by="pager:kim"))  # too late: "conflict", already expired
retry = await gate.authorize(action, wait=False)  # status "expired", never runs

Testing

with hitl.testing.fake_approvals(answer="approve") as approvals:
    assert issue_refund("A-1002", 900) == "Refunded $900 on A-1002"
    assert approvals.asked("issue_refund", args={"amount": {"gt": 50}})

The pytest plugin gives the same thing as the approvals fixture. tests: blocks in policies/*.yaml and policies/*.test.yaml run as pytest items (pytest policies/) and with viewport-hitl test.

CLI

viewport-hitl check | explain | test | receipts verify | pending | approve | deny | init

Docs: https://docs.getviewport.com/hitl

License

Apache-2.0.

Metadata

Release files for viewport-hitl 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for viewport-hitl 0.1.1
File Size Uploaded Provenance Actions
viewport_hitl-0.1.1.tar.gz 221.2 kB Without provenance Details for viewport_hitl-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for viewport-hitl 0.1.1
File Interpreter ABI Platform Actions
viewport_hitl-0.1.1-py3-none-any.whl Python 3 none any Details for viewport_hitl-0.1.1-py3-none-any.whl

Total release size: 485.8 kB

Release files / viewport_hitl-0.1.1.tar.gz

Download URL viewport_hitl-0.1.1.tar.gz
Size 221.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3d5f6e6c83b0d279f2c869148650bbcfa22a0834ad3b811f1f7c0363f8193dfa
BLAKE2b-256 checksum
How to use checksums
124788748ae35f32168034a17b7891b8fafafef0fbe71ff260fb18b33b19cfdc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / viewport_hitl-0.1.1-py3-none-any.whl

Download URL viewport_hitl-0.1.1-py3-none-any.whl
Size 264.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d62a07fa58ff4c0cfbfc05504c5c7272af38ddba532022b17303e83509cddfc2
BLAKE2b-256 checksum
How to use checksums
eabda9e332fb0a174f6ded89852dbb052faedc372fae390232de94683b5490fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for viewport-hitl 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page