Brain Docs

Reference

Python SDKInstallationHTTP clientWire clientSync vs async
ErrorsRetriesPagination
Brain/Docs
✦ ASKBrain on GitHubDashboard
Python SDKErrors

Errors

Both taxonomies — the wire BrainError hierarchy with its typed server subclasses, and the HTTP tier's BrainHttpError.

PURPOSE

The two tiers fail differently and the SDK does not paper over it. The wire client raises a BrainError hierarchy carrying the protocol's own error frames; the HTTP client raises BrainHttpError carrying a status and a string code. This page catalogs both.

Wire tier: the BrainError hierarchy

ParameterTypeRequired
BrainErrorExceptionrequired

Base class for every wire-client failure. Catch this to catch everything.

ProtocolErrorBrainErroroptional

The peer broke the protocol sequence. Not retryable; the connection's state is no longer trustworthy.

ConnectionClosedBrainErroroptional

The peer closed the connection. Retryable — on a new connection. The transport raises this rather than letting a bare OSError escape.

BrainTimeoutBrainErroroptional

An operation missed its deadline. Retryable.

VersionMismatchBrainErroroptional

The server chose a wire version the client did not offer. Never retryable — upgrade one side.

ServerErrorBrainErroroptional

The 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.

ParameterTypeRequired
ActAsDeniedServerErroroptional

Wire 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.

LlmCredentialMissingServerErroroptional

Wire 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.

LlmCredentialUnavailableServerErroroptional

Wire 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:
        raise
Order your except clauses narrowest first

LlmCredentialMissing 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:

CategoryValueMeaningRetry
Protocol0Malformed or out-of-sequence request.No
Authentication1The credential was rejected.No
Authorization2The identity lacks permission.No
Validation3The request failed input validation.No
NotFound4The referenced thing does not exist.No
Conflict5Idempotency or transaction conflict.No
ResourceExhausted6Rate or quota limit. May carry a retry hint.Yes
Internal7Server-side failure.No
Unavailable8The shard is temporarily unavailable.Yes

Codes

The precise verdict is a u16. The families, by prefix:

OptionTypeDefault / Env
0x0001–0x000BFraming

Bad magic, header or payload CRC, opcode, version, frame, oversize payload, reserved field non-zero, bad flag combination, malformed payload or vector.

0x0020–0x0025Authentication

Version not supported, no such auth method, unauthenticated, not authenticated, auth backend unavailable, session expired.

0x0030–0x0033Authorization

Permission denied, admin permission required, wrong shard, act-as denied.

0x0040–0x004CValidation

Invalid 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 found

Memory, context, subscription, snapshot or transaction not found.

0x0060–0x0066Conflict

Idempotency conflict, transaction conflict, transaction timeout, stream id in use, subscription LSN too old, cardinality violation, LLM credential missing (0x0066).

0x0070–0x0077Resource exhausted

Out of slots, disk or memory; rate limited; stream, connection or transaction limit exceeded; transaction too large.

0x0080–0x0085Internal

Internal, storage, index, embedding or metadata error; cancelled.

0x0090–0x0095Unavailable

Shard unavailable, overloaded, restarting, maintenance, retriever degraded, LLM credential unavailable (0x0095).

0x0120–0x0172Graph and extraction

Schema 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.

FieldTypePresence
statusintalways

The HTTP status. 0 means the request never got an answer — a transport failure or a client-side timeout.

codestralways

The 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]always

Per-field validation detail. Empty unless the edge rejected specific fields.

messagestralways

Human-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}")
    raise
Validation failures are not always exceptions

The schema verbs return a populated validation_errors list rather than raising. A try/except around them catches transport and auth failures only. See validateSchema.

See also
RetriesProvider credentialsWire client

Was this page helpful?

ping

A connection-level liveness check that works while streams are in flight.

Retries

Both retry layers — the HTTP client's automatic policy with its idempotent-only verb list, and the wire tier's with_retry combinator.

On this page

Wire tier: the BrainError hierarchyTyped server conditionsCategoriesCodesis_retryableHTTP tier: BrainHttpError
Suggest an editOpen in Playground