Skip to main content

HaltState Sentinel Python SDK - Compliance & Policy Checks for AI Agents

Project description

HaltState Sentinel SDK

PyPI

Compliance & policy checks for AI agents. Perform pre-action checks, approvals, and post-action reporting with minimal code.

Canonical public base URL: https://haltstate.ai

Canonical governance namespace: /api/haltstate/sentinel/*

Current SDKs default to https://haltstate.ai and target /api/haltstate/sentinel/* first. They still fall back to legacy /api/sentinel/* aliases when needed.

Installation

pip install haltstate-sdk

Quickstart (sync)

from haltstate import HaltStateClient

client = HaltStateClient(
    tenant_id="your_tenant_id",
    api_key="hs_xyz",
    base_url="https://haltstate.ai",
    fail_open=False,
)

decision = client.check(
    action="payment.process",
    params={"amount": 5000, "currency": "USD"},
    agent_id="payment-bot-01",
)

if decision.allowed:
    process_payment(...)
    client.report(decision, status="success", result={"transaction_id": "tx_123"}, action="payment.process", agent_id="payment-bot-01")
elif decision.requires_approval:
    print(f"Approval required: {decision.reason}")
else:
    print(f"Action denied: {decision.reason}")

Backward Compatibility

Existing code using janus imports continues to work:

from janus import JanusClient  # Still works!

Guard Pattern

For actions requiring human approval, use the idempotent guard pattern:

from haltstate import AsyncHaltStateClient, ApprovalPending, ActionDenied

async def process_high_value_payment(invoice_id: str, amount: float):
    client = AsyncHaltStateClient(
        tenant_id="acme",
        api_key="hs_xxx",
        base_url="https://haltstate.ai",
    )

    try:
        async with client.guard(
            action="payment.process",
            agent_id="payment-bot",
            params={"invoice_id": invoice_id, "amount": amount},
            idempotency_key=f"payment-{invoice_id}",  # Retry-safe
            timeout_seconds=300
        ) as permit:
            # Only executes after human approval
            result = await execute_payment(amount)
            print(f"Approved by {permit.approver} at {permit.approved_at}")
            return result

    except ApprovalPending:
        print("Awaiting human approval...")
        return {"status": "pending"}

    except ActionDenied as e:
        print(f"Rejected by {e.rejected_by}: {e.reason}")
        raise

Key features:

  • Idempotency keys: Same key = same approval request, safe for retries
  • Process restart safety: Approved actions can be executed after restart
  • Audit trail: Full record of who approved and when

Decorators

from haltstate import HaltStateClient, haltstate_guard

client = HaltStateClient(tenant_id="acme", api_key="hs_xxx", base_url="https://haltstate.ai")

@haltstate_guard(client, action="email.send", agent_id="email-bot")
def send_email(to, subject, body):
    return mailer.send(to, subject, body)

Async

from haltstate import AsyncHaltStateClient

async def main():
    async with AsyncHaltStateClient(tenant_id="acme", api_key="hs_xxx", base_url="https://haltstate.ai") as client:
        res = await client.check("database.drop", params={"table": "users"})
        if res.allowed:
            await client.report(res, status="success", action="database.drop", agent_id="ops-bot")

Exceptions

from haltstate import (
    HaltStateError,           # Base error
    HaltStateAuthError,       # Invalid API key
    HaltStateConnectionError, # Network/timeout
    ApprovalPending,          # Awaiting approval (guard pattern)
    ActionDenied,             # Human rejected (guard pattern)
    ActionExpired,            # Approval expired (guard pattern)
)

Docs

Full documentation at haltstate.ai/docs:

  • Quickstart - 5-minute setup
  • Guard Pattern - HITL approval flow
  • API Reference - All methods
  • Error Handling - Exception handling
  • SB-53 Compliance - Regulatory mapping

Legacy Sentinel-prefixed routes remain supported as compatibility aliases, but new integrations should target the HaltState-branded public contract.

Migration from janus-sdk

If upgrading from janus-sdk:

# Old (still works)
from janus import JanusClient, janus_guard

# New
from haltstate import HaltStateClient, haltstate_guard

Both import styles work - no code changes required for existing users.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

haltstate_sdk-0.7.0.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

haltstate_sdk-0.7.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file haltstate_sdk-0.7.0.tar.gz.

File metadata

  • Download URL: haltstate_sdk-0.7.0.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for haltstate_sdk-0.7.0.tar.gz
Algorithm Hash digest
SHA256 05bce9e39a4d431cda71edada65e11dd8308e9ef47944332e280f20c0d0d0fde
MD5 fc2ea1fc177ab44e5c9548bae22967b0
BLAKE2b-256 469b4d78b879070ffceaadaa4fcfdf861087d511979a676567699dba01bd0a0e

See more details on using hashes here.

File details

Details for the file haltstate_sdk-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: haltstate_sdk-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for haltstate_sdk-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6821e3f95c8c787e710c158eb153a2b6efdd9577bc46bb7c5d2ccaeb48affdd9
MD5 30bbf21eae7d2968975086562a5913cb
BLAKE2b-256 19a4484f0946a7b7a9f219e7a12c3f68b7ab2cd361d7f86bdcfbe7e633bb93c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page