Reference
Exceptions Reference
SDK exception hierarchy and when each is raised.
Exceptions Reference
Overview
Exception types raised by the AgentTrust Python SDK.
Why It Matters
Proper exception handling prevents silent governance bypass and enables correct user-facing error messages.
Step-by-Step Guide
Exception hierarchy
from agentrust_sdk import (
BlockedError,
TierGateError,
GatewayUnavailableError,
GatewayVersionError,
)| Exception | When raised | Recovery |
|---|---|---|
BlockedError | Decision outcome is block, or escalate with block_on_escalate=True, or failure_mode=closed on gateway error | Review decision.reasons; fix agent or policy |
GatewayUnavailableError | Gateway unreachable and failure_mode=closed | Fix gateway or switch to open/queue |
GatewayVersionError | SDK version incompatible with gateway | Upgrade SDK or gateway |
TierGateError | Tier-gated adapter/capability without sufficient tier | Upgrade subscription |
Handling pattern
from agentrust_sdk import harness, BlockedError, GatewayUnavailableError
@harness(block_on_block=True)
def agent(user, input):
return run_llm(input)
try:
agent("alice", "query")
except BlockedError as e:
return {"error": "governance_blocked", "detail": str(e)}
except GatewayUnavailableError:
return {"error": "governance_unavailable"}TypeScript equivalents
import { BlockedError, GatewayError } from 'agentrust-sdk';Best Practices
- Catch
BlockedErrorat user-facing boundaries - Alert on
GatewayUnavailableErrorin production - Never catch and ignore
TierGateErrorsilently - Log full
decision.reasonswith every block
Common Mistakes
- Catching
Exceptionbroadly and continuing - Confusing
BlockedError(governance decision) withGatewayUnavailableError(infra)