SDK API
This is the canonical reference for the Python SDK. For tutorial-style introductions see Quickstart; for framework-specific patterns see the Framework adapters.proofrail.init()
Configure the SDK. Call once at application startup before opening any chains.
Common
Failure handling
Policy thresholds
Privacy
Performance
Returns
AChainConfig instance. Configuration is also stored globally for the process so subsequent proofrail.Chain(...) calls use it.
Sanitization defaults
The SDK uses two separate default lists for redacting sensitive data:sensitive_field_patterns (default — matches against dict keys by case-insensitive substring):
sensitive_value_patterns (default — matches against string values using str.startswith()):
proofrail.Chain
Context manager that opens a chain and records every action within it. Use as an async or sync context manager depending on your code.
Constructor parameters
Lifecycle
On__aenter__ / __enter__: a chain record is created on the backend; the chain ID is available as chain.id after entry.
On __aexit__ / __exit__: the SDK calls POST /v1/chains/{chain_id}/complete, which seals the chain and triggers receipt generation on the backend. If exit was triggered by an exception, the chain is marked accordingly and the receipt reflects the failure mode.
Methods
record_agent_action() (async)
Returns a
PolicyDecision object on allow or allow_with_flag outcomes. Blocks until resolution on require_approval. Raises on deny.
chain.id
The backend-assigned chain UUID. Available after __aenter__ / __enter__. Useful for logging or cross-system references:
proofrail.PolicyDecision
Returned by record_agent_action when the action is allowed (including after a human approval resolves).
Framework adapters
Each adapter exposes agovern() function that wraps an existing framework object. See the framework-specific pages for usage details.
proofrail.langgraph.govern()
proofrail.langchain.govern()
agent_name for recorded events is derived from type(executor).__name__ at wrap time — it isn’t a govern() parameter.
See LangChain adapter.
proofrail.crewai.govern()
proofrail.mcp.ProofRailMcpAdapter
proofrail.client.verify_receipt()
Verify a receipt’s signature and return its contents.
valid field indicates whether the receipt’s HMAC signature checks out. If invalid, the receipt has been tampered with or modified after signing.
This is a thin client over the public verification endpoint at GET /v1/receipts/{receipt_id}/verify. The endpoint requires no authentication — anyone with a receipt ID can verify.
See Audit receipts for the signing and hash-chaining model.
Exceptions
All exceptions live inproofrail.exceptions. The base for policy-driven errors is ProofRailPolicyError.
Version compatibility
The SDK requires Python 3.10 or later (enforced at install time by pip). Supported framework version ranges are pinned insdk/pyproject.toml; install ProofRail with a compatible version of your framework already installed. See Limitations for the current compatibility matrix.
Where to go next
Configuration
Detailed walkthrough of every init() option.
Exceptions
All exception types and how to handle them.
Framework adapters
Per-framework usage and edge cases.
Limitations
What ProofRail does and doesn’t do at current version.