Error Handling & Retries
Error hierarchy (BlockedError, AuthenticationError, RateLimitError, APIError, APIConnectionError), automatic retry policy, and timeout configuration for the Highflame SDK.
Error Hierarchy
HighflameError
├── BlockedError — Shield decision was "deny"
└── APIError — HTTP error from the service
├── AuthenticationError — 401 Unauthorized
└── RateLimitError — 429 Too Many Requests
APIConnectionError — Network failure or timeout (extends HighflameError)Python
from highflame import (
Highflame,
GuardRequest,
HighflameError,
APIError,
AuthenticationError,
RateLimitError,
APIConnectionError,
BlockedError,
)
client = Highflame(api_key="hf_sk_...")
try:
resp = client.guard.evaluate(GuardRequest(
content=user_input,
content_type="prompt",
action="process_prompt",
))
except BlockedError as e:
# Raised only by Shield decorators (@shield.prompt, @shield.tool, etc.)
# Direct client.guard.evaluate() calls return GuardResponse and never raise on deny.
print(f"Blocked: {e.response.policy_reason}")
print(f"Signals: {[s.name for s in e.response.signals]}")
except AuthenticationError as e:
# 401 — invalid or expired API key
print(f"Auth failed: {e.status} {e.title} — {e.detail}")
except RateLimitError as e:
# 429 — request quota exceeded
print(f"Rate limited: {e.status} {e.title} — {e.detail}")
except APIError as e:
# Any other non-2xx HTTP response
print(f"API error {e.status}: {e.title} — {e.detail}")
except APIConnectionError as e:
# Network failure, timeout, DNS error
print(f"Connection error: {e}")
except HighflameError as e:
# Catch-all for any other SDK error
print(f"SDK error: {e}")APIError Attributes
Attribute
Type
Description
BlockedError Attributes
Attribute
Type
Description
TypeScript
Catching BlockedError from Shield wrappers
Automatic Retries
Timeouts
Handling Rate Limits Manually
Self-Hosted Deployments
Last updated