Errors
Both taxonomies — the wire BrainError hierarchy with its typed server subclasses, and the HTTP tier's BrainHttpError.
Wire tier: the BrainError hierarchy
BrainErrorExceptionrequiredBase class for every wire-client failure. Catch this to catch everything.
ProtocolErrorBrainErroroptionalThe peer broke the protocol sequence. Not retryable; the connection's state is no longer trustworthy.
ConnectionClosedBrainErroroptionalThe peer closed the connection. Retryable — on a new connection. The
transport raises this rather than letting a bare OSError escape.
BrainTimeoutBrainErroroptionalAn operation missed its deadline. Retryable.
VersionMismatchBrainErroroptionalThe server chose a wire version the client did not offer. Never retryable — upgrade one side.
ServerErrorBrainErroroptionalThe server returned a structured ERROR frame. Carries the code, the category, a retry hint and the full response.
Typed server conditions
Three server conditions get their own type, so you catch them by class rather
than testing a predicate. All three SDKs single these three out — Rust as
BrainError::is_act_as_denied() and friends, TypeScript as isActAsDenied
functions — because the category alone does not say which of them you have.
ActAsDeniedServerErroroptionalWire code 0x0033. The principal lacks the act-as grant, or named a
namespace outside its allowlist. Never retryable; the fix is a
differently-scoped credential.
LlmCredentialMissingServerErroroptionalWire code 0x0066, category Conflict, HTTP 409 on the edge. No
provider credential is registered. Terminal: is_retryable returns
False, because retrying cannot create a key — prompt for one instead.
See putLlmCredential.
LlmCredentialUnavailableServerErroroptionalWire code 0x0095, category Unavailable, HTTP 503 on the edge. A
credential exists, but the broker was unreachable, timed out or failed
transiently. Retryable — and deliberately a separate condition:
collapsing the two would either spin forever against a tenant that has no
key, or permanently fail a write for a tenant whose key is fine.
LlmCredentialMissing and LlmCredentialUnavailable live in
brain_db_sdk.errors and, unlike ActAsDenied, are not re-exported from
the package root — import them from the module:
from brain_db_sdk import ServerError, is_retryable
from brain_db_sdk.errors import LlmCredentialMissing, LlmCredentialUnavailable
try:
client.encode(request)
except LlmCredentialMissing:
prompt_for_provider_key()
except ServerError as exc:
if is_retryable(exc):
schedule_retry()
else:
raiseLlmCredentialMissing is a ServerError, which is a BrainError. A broad
except ServerError placed first swallows all three typed conditions.
Categories
The server error's category is the coarse branch:
| Category | Value | Meaning | Retry |
|---|---|---|---|
Protocol | 0 | Malformed or out-of-sequence request. | No |
Authentication | 1 | The credential was rejected. | No |
Authorization | 2 | The identity lacks permission. | No |
Validation | 3 | The request failed input validation. | No |
NotFound | 4 | The referenced thing does not exist. | No |
Conflict | 5 | Idempotency or transaction conflict. | No |
ResourceExhausted | 6 | Rate or quota limit. May carry a retry hint. | Yes |
Internal | 7 | Server-side failure. | No |
Unavailable | 8 | The shard is temporarily unavailable. | Yes |
Codes
The precise verdict is a u16. The families, by prefix:
0x0001–0x000BFramingBad magic, header or payload CRC, opcode, version, frame, oversize payload, reserved field non-zero, bad flag combination, malformed payload or vector.
0x0020–0x0025AuthenticationVersion not supported, no such auth method, unauthenticated, not authenticated, auth backend unavailable, session expired.
0x0030–0x0033AuthorizationPermission denied, admin permission required, wrong shard, act-as denied.
0x0040–0x004CValidationInvalid argument, missing required field, text too large, text empty, bad session id, bad memory kind, bad edge kind, bad strategy hint, top-k out of range, budget too large, bad model fingerprint, predicate not in schema, relation type not in schema.
0x0050–0x0054Not foundMemory, context, subscription, snapshot or transaction not found.
0x0060–0x0066ConflictIdempotency conflict, transaction conflict, transaction timeout, stream id
in use, subscription LSN too old, cardinality violation, LLM credential
missing (0x0066).
0x0070–0x0077Resource exhaustedOut of slots, disk or memory; rate limited; stream, connection or transaction limit exceeded; transaction too large.
0x0080–0x0085InternalInternal, storage, index, embedding or metadata error; cancelled.
0x0090–0x0095UnavailableShard unavailable, overloaded, restarting, maintenance, retriever
degraded, LLM credential unavailable (0x0095).
0x0120–0x0172Graph and extractionSchema invalid or migration required; entity not found, type mismatch, ambiguous, merge conflict; statement not found, object type mismatch, contradicts existing; query timeout or over budget; extractor disabled, budget exceeded, extraction failed.
An unrecognised code decodes to Unknown rather than raising, so a client
built against an older SDK still surfaces a newer server's errors.
is_retryable
is_retryable(exc) is True for ConnectionClosed, BrainTimeout, a bare
OSError from the socket, and a ServerError whose category is
ResourceExhausted or Unavailable. Nothing else — so
LlmCredentialMissing (category Conflict) is False and
LlmCredentialUnavailable (category Unavailable) is True. It is the signal
with_retry consults.
HTTP tier: BrainHttpError
One class, not a hierarchy.
statusintalwaysThe HTTP status. 0 means the request never got an answer — a
transport failure or a client-side timeout.
codestralwaysThe edge's stable string code: unauthorized, llm_credential.missing,
llm_credential.unavailable, and so on. Branch on this, not on the
message.
field_errorslist[FieldError]alwaysPer-field validation detail. Empty unless the edge rejected specific fields.
messagestralwaysHuman-readable. Never parse it.
status == 0 with code == "config" is client-side misconfiguration — an
empty api key, an api key carrying a control character, a base URL that is not
http/https — raised at construction, before any request is attempted. Every
other status == 0 is a transport failure or a timeout, so test code
before treating a 0 as transient.
from brain_db_sdk import BrainHttpError
try:
brain.create_statement(**statement)
except BrainHttpError as exc:
if exc.code == "config":
raise # a bug in the call, not a blip
if exc.status == 0:
return retry_later() # never reached the edge
if exc.code == "llm_credential.missing":
return prompt_for_provider_key() # 409, terminal — register a key
if exc.code == "llm_credential.unavailable":
return retry_later() # 503, the broker blipped
for f in exc.field_errors:
print(f"{f.field}: {f.message}")
raiseThe schema verbs return a populated validation_errors list rather than
raising. A try/except around them catches transport and auth failures
only. See validateSchema.
Was this page helpful?