·Docs

Rakshak

Error handling

Handle blocked content, invalid keys, rate limits, and network failures without exposing guard internals to users.

SDK exceptions

RakshakBlockedErrorguard verdictRaised only when raise_on_block=True and the verdict is block.
RakshakAuthError401API key is missing, invalid, or revoked.
RakshakRateLimitError429Request rate exceeded for the key.
RakshakAPIError4xx/5xxOther non-success response from the API.
RakshakConnectionErrornetworkTimeout, DNS, or transport failure reaching the Rakshak server.

Recommended pattern

try:
    result = client.guard(user_message, raise_on_block=True)
except rakshak.RakshakBlockedError as exc:
    log_security_event(exc.result.threats, exc.result.request_id)
    return "I can't help with that."
except rakshak.RakshakRateLimitError:
    return "Security checks are busy. Try again in a moment."
except rakshak.RakshakAuthError:
    raise RuntimeError("Rakshak API key is not configured correctly")
except rakshak.RakshakConnectionError:
    return "Security checks are temporarily unavailable."

return call_your_llm(user_message)

REST error shape

{
  "error": {
    "code": "INVALID_API_KEY",
    "message": "Invalid API key",
    "request_id": "req_..."
  }
}