Skip to content

Documentation navigation

Errors & Exceptions

The SDK error model: the MaivnError base, the validation/execution/transport failure layers, and how to catch and handle each.

#Errors and exceptions

The SDK exposes one exception hierarchy from maivn, plus separate families for private artifacts and skill parsing. Programming mistakes may also raise standard Python or Pydantic exceptions before a request is sent.

#Public SDK exceptions

Python
from maivn import (
    AsyncContextError,
    ConcurrentJobsLimitError,
    ConfigurationError,
    DurableBoundaryRefusedError,
    HostedJobLocalToolsError,
    MaivnHTTPError,
    MaivnSDKError,
    PlanLimitExceededError,
    ResourceRegistrationError,
    ToolBlockedError,
    VaultSetupError,
)
ExceptionParentMeaning
MaivnSDKErrorExceptionBase class for SDK-owned failures.
ConfigurationErrorMaivnSDKErrorRequired SDK configuration is missing or invalid.
VaultSetupErrorConfigurationErrorAutomatic encrypted local storage could not open securely.
AsyncContextErrorMaivnSDKErrorA synchronous facade was called from an active event loop. Use its async sibling.
ResourceRegistrationErrorMaivnSDKErrorA declared resource could not be registered or bound before invocation.
DurableBoundaryRefusedErrorMaivnSDKErrorThe platform ended the run because a payload bound for the durable log still carried a private value.
MaivnHTTPErrorMaivnSDKErrorThe mAIvn API returned a typed non-2xx response.
PlanLimitExceededErrorMaivnHTTPErrorThe platform refused a run because a plan limit is reached.
ConcurrentJobsLimitErrorMaivnHTTPErrorYour team already had as many runs in progress as its plan allows, and the SDK's wait budget ran out.
HostedJobLocalToolsErrorMaivnHTTPErrorThe platform refused a hosted job (HTTP 422 hosted_job_local_tools_unsupported) because it needs SDK-local Python tools. tool_names lists the tools it named. See Hosted jobs.
ToolBlockedErrorMaivnSDKErrorYou raise this from a before_execute hook to refuse one tool call; the SDK does not raise it to you. See Blocking a tool call.

Catching MaivnSDKError catches every row above. Catch the narrower class first when you handle a case differently.

#Attributes on MaivnSDKError

A failure that ends a run carries identifiers you can use to look up the session. Failures before a session exists leave them unset.

AttributeMeaning
session_id, root_event_idIdentifiers of the failed run, or None.
error_codeA stable machine code for the failure, or None.
correlationA small dictionary of value-free identifiers, or None.

#MaivnHTTPError

MaivnHTTPError provides status_code, reason, optional code, fields, retry_after, and detail attributes. error_code aliases code. It does not provide to_dict() or an automatic retry classifier.

#DurableBoundaryRefusedError

This error has the code durable_event_refused. It is terminal, so retrying the same input fails the same way. refused_path names where the refusal happened, as a projection name and field path. It never contains the value. Check your private-data declarations and the field it names before you submit more work.

Python
from maivn import DurableBoundaryRefusedError

try:
    response = agent.invoke('Summarize this ticket.')
except DurableBoundaryRefusedError as exc:
    print(exc.refused_path, exc.session_id)
    raise

#PlanLimitExceededError

A plan limit is not congestion. The same request fails until the period resets or the plan changes, so do not retry it on a timer. Its typed attributes come from the error's context, and each is a string or None:

AttributeMeaning
meterWhich allowance ran out.
planThe plan name.
limit, used, remainingThe allowance and how much of it is spent.
period_resets_atWhen the allowance renews.
upgradeThe plan that would raise the limit.

describe() returns one plain sentence built from those fields. You can show it to a user as is.

#ConcurrentJobsLimitError

The platform refuses a new run start with HTTP 429 and the code concurrent_jobs_limit_reached when your team already has as many runs in progress as its plan allows. It refuses an answer to a paused run (an approval, an interrupt or a follow-up question) the same way, because answering resumes the run. See Concurrent jobs. A refused start did not begin a run, and a refused answer was not recorded, so the SDK waits and sends the same request again. Each wait is the time the platform asks for, between 1 and 30 seconds, and each one is logged on the maivn logger. When the next wait would go past the client's concurrent_jobs_wait_seconds (default 60), the SDK raises this error. Unlike PlanLimitExceededError, it clears as soon as one of your runs finishes.

AttributeMeaning
in_progressHow many runs were in progress, or None.
limitYour plan's limit, or None.
planThe plan name, or None.
retry_afterThe seconds the platform last asked the SDK to wait, or None.
Python
from maivn import Agent, Client, ConcurrentJobsLimitError

# Wait up to two minutes in total before raising. 0 raises at once; at most 600.
client = Client(concurrent_jobs_wait_seconds=120)
agent = Agent(name='assistant', client=client)

try:
    response = agent.invoke('Summarize the latest release notes')
except ConcurrentJobsLimitError as error:
    print(f'{error.in_progress} of {error.limit} runs are in progress; try again later.')

No other 429, and no other error, is retried this way.

#Private artifact errors

Private artifact calls raise their own family, not MaivnSDKError. They carry fixed messages and a code attribute, and never include file content.

ExceptionMeaning
PrivateArtifactErrorBase class, and the error for any rejected or malformed request.
PrivateArtifactAuthorizationDeniedErrorThe operation was admitted and then denied.
PrivateArtifactGrantExpiredErrorThe grant expired before the operation finished.
PrivateArtifactEffectFailedErrorThe operation reached a terminal failure.
PrivateArtifactTimeoutErrorThe bounded wait for the final status expired.

See Artifacts for the code of each.

#Skill parsing errors

parse_skill_markdown raises subclasses of SkillMarkdownError, which is itself a ValueError.

ExceptionMeaning
SkillMarkdownErrorBase class for malformed skill markdown.
SkillFrontmatterErrorA skill file has invalid frontmatter.
SkillChildNotFoundErrorA skill-set child path cannot be resolved.
SkillCycleErrorSkill-set child references form a cycle.

#Error responses

Every non-2xx API response has one JSON shape:

JSON
{
  "detail": "Request validation failed.",
  "code": "validation_failed",
  "fields": [{"field": "messages.0.content", "message": "Field required"}]
}
MemberAlways presentMeaning
detailYesA message for a person. MaivnHTTPError.reason holds it.
codeYesA stable machine code in lower snake case, such as not_found, validation_failed or plan_limit_exceeded. Branch on this, not on detail.
fieldsNoThe request fields that failed validation, each with a message. MaivnHTTPError.fields holds them.
retry_afterNoSeconds to wait before retrying. The Retry-After header carries the same value.
contextNoData specific to the code, such as the meter and reset time of a plan limit. MaivnHTTPError.detail holds it.
request_idNoAn identifier for the request, when one exists. The SDK does not copy it onto the exception.

A plan_limit_exceeded response raises PlanLimitExceededError, and hosted_job_local_tools_unsupported raises HostedJobLocalToolsError. Every other code raises MaivnHTTPError.

#Memory write refusals

A team's memory policy can refuse an explicit memory write. Both codes raise MaivnHTTPError.

StatuscodeMeaning
403memory_persistence_disabledThe team's memory switch is off or its persistence ceiling is No storage. Nothing was stored. Change the policy in the Portal before you retry.
503memory_policy_unavailableThe platform could not read the policy. A write was not stored, and a skill or insight list was not served. Retry.

The refused calls are creating a skill or insight, promoting an insight and uploading a resource. See Portal Memory Management.

Python
from maivn import Agent, MaivnHTTPError, MaivnSDKError, PlanLimitExceededError
from maivn.messages import HumanMessage

agent = Agent(name='assistant', api_key='your-api-key')

try:
    response = agent.invoke([HumanMessage(content='Summarize this ticket.')])
except PlanLimitExceededError as exc:
    print(exc.describe())
    raise
except MaivnHTTPError as exc:
    print(exc.status_code, exc.code, exc.reason)
    raise
except MaivnSDKError as exc:
    print(str(exc), exc.error_code)
    raise

#Validation and transport failures

Invalid input to a constructor, decorator or option can raise ValueError, TypeError, or pydantic.ValidationError. These are deterministic input problems. Correct the call rather than retrying it.

The SDK uses httpx for transport. Connection and timeout exceptions can therefore surface as httpx.HTTPError subclasses. Decide retry policy in your application from the concrete exception and operation. The SDK does not expose an is_retryable() helper.

Python
import httpx
from pydantic import ValidationError

try:
    response = agent.invoke('Summarize this ticket.')
except (TypeError, ValueError, ValidationError):
    raise  # fix input or configuration
except httpx.TimeoutException:
    raise  # apply application-specific backoff if this operation is safe to retry

#Invocation results

Successful invoke() and ainvoke() calls return maivn.InvokeResponse. The current model has no status or error field. It contains the final message, response, optional structured result, session and thread identifiers, event positions, usage metadata, stop reason, and a tool-call summary. Interrupt and follow-up builders resolve checkpoints while consuming the stream. Failures use exceptions or terminal stream events.

See Shared Data Models, Sessions and Streaming, and Interrupts.