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
from maivn import (
AsyncContextError,
ConcurrentJobsLimitError,
ConfigurationError,
DurableBoundaryRefusedError,
HostedJobLocalToolsError,
MaivnHTTPError,
MaivnSDKError,
PlanLimitExceededError,
ResourceRegistrationError,
ToolBlockedError,
VaultSetupError,
)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.
#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.
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:
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.
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.
See Artifacts for the code of each.
#Skill parsing errors
parse_skill_markdown raises subclasses of SkillMarkdownError, which is itself a ValueError.
#Error responses
Every non-2xx API response has one JSON shape:
{
"detail": "Request validation failed.",
"code": "validation_failed",
"fields": [{"field": "messages.0.content", "message": "Field required"}]
}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.
The refused calls are creating a skill or insight, promoting an insight and uploading a resource. See Portal Memory Management.
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.
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.