Error Handling

May 8, 2026 · View on GitHub

AgentVeil SDK methods raise typed exceptions for API responses and local validation failures. Network failures and some offline verifier failures use their native exception types so applications can handle transport, SDK, and proof errors separately.

Hierarchy

Exception
├── httpx.RequestError
├── agentveil.delegation.DelegationInvalid
├── agentveil.proof.ProofVerificationError
└── AVPError
    ├── AVPAuthError
    ├── AVPNotFoundError
    ├── AVPRateLimitError
    ├── AVPValidationError
    └── AVPServerError

AVPError has these attributes:

AttributeMeaning
messageHuman-readable SDK message. Also available through str(exc).
status_codeHTTP status when the error came from an HTTP response. Defaults to 0 for local SDK errors.
detailBackend detail text when available.

AVPRateLimitError also exposes retry_after, in seconds.

Exception Reference

ExceptionTriggersAttributesCommon causeRecovery pattern
AVPValidationErrorLocal validation failure, 400, or 409message, status_code, detailBad input, invalid outcome/weight, malformed request, conflict stateFix input or state before retrying. Do not blind-retry.
AVPAuthError401 or 403message, status_code, detailMissing/invalid signature, stale timestamp, nonce replay, unverified/suspended/revoked DIDReload the correct key, register/verify the DID, check clock skew, or stop if the DID is revoked.
AVPNotFoundError404message, status_code, detailMissing object, foreign private object, or intentionally hidden resourceVerify the identifier and caller DID. Treat private-resource 404s as non-disclosure.
AVPRateLimitError429message, retry_after, status_codeTrust Gate, registration, or global API rate limitWait at least retry_after seconds and retry with backoff.
AVPServerError5xx or malformed successful responsemessage, status_code, detailBackend dependency unavailable, signing config missing, non-JSON response where JSON was requiredRetry cautiously with backoff. Escalate if persistent.
AVPErrorAny other SDK-mapped responsemessage, status_code, detailUnexpected status code or SDK-level failureLog status/detail and fail safely.
httpx.RequestErrorRequest could not reach the APINative httpx fieldsDNS, TLS, proxy, timeout, connection refusedCheck base_url, network, TLS, and retry only after transport is healthy.
DelegationInvalidOffline DelegationReceipt verification failurereasonExpired receipt, invalid signature, wrong issuer, unsupported scopeObtain a fresh valid DelegationReceipt from the principal.
ProofVerificationErrorOffline proof artifact verification failureReason via str(exc)Invalid signature, untrusted signer DID, malformed packet, or receipt hash mismatchTreat as failed evidence verification and re-export from trusted source artifacts.

HTTP Mapping

SDK HTTP helpers map responses as follows:

HTTP statusSDK exception
400AVPValidationError
401AVPAuthError
403AVPAuthError
404AVPNotFoundError
409AVPValidationError
429AVPRateLimitError
5xxAVPServerError
Other non-successAVPError

integration_preflight() is intentionally different: it returns an IntegrationPreflightReport with ready, status, and next_action instead of raising for common readiness states.

Common Scenarios

ScenarioLikely signalRecovery
Network failure during register(...)httpx.RequestErrorCheck network/TLS/base URL. Retry after transport is stable.
Duplicate DID registrationAVPValidationError with Conflict: ...Load the existing saved agent if it is yours, or create a fresh DID.
Rate limit during attest_batch(...)AVPRateLimitError, retry_afterSleep at least retry_after, then retry with jitter/backoff.
Malformed DelegationReceipt in runtime_evaluate(...)AVPValidationErrorVerify the receipt offline first and correct input before retrying.
Backend unavailable during controlled_action(...)AVPServerErrorDo not execute the action directly. Retry later or fail closed.
Approval not ready or expiredAVPValidationError with a conflict-style messageSurface the state to the principal and follow Approval Routing.
Invalid DelegationReceipt offlineDelegationInvalidAsk the principal for a fresh receipt with the intended scope and validity window.

Recovery Snippets

Rate limit:

try:
    agent.attest_batch(items)
except AVPRateLimitError as exc:
    time.sleep(exc.retry_after)
    # Retry once with jitter/backoff in production.

Validation:

try:
    agent.runtime_evaluate(...)
except AVPValidationError as exc:
    print(exc.message)
    # Fix malformed input or unsafe state before retrying.

Backend unavailable:

try:
    outcome = agent.controlled_action(...)
except AVPServerError as exc:
    print(exc.message)
    # Fail closed: do not run the action outside the control path.

Network:

try:
    agent.register(display_name="worker")
except httpx.RequestError as exc:
    print(exc)
    # Check base_url, TLS, proxy, and retry when connectivity is healthy.

Generic SDK handling:

try:
    result = agent.get_reputation()
except AVPError as exc:
    print(exc.status_code, exc.message)

Known Coverage Notes

Most HTTP-backed SDK calls route non-success API responses through typed SDK exceptions. A few local Python errors can still happen before an HTTP response exists, such as malformed local dictionaries passed into helper methods. Treat those as programming errors and validate inputs before calling the SDK.