pydantic_ai.exceptions
Bases: Exception
Exception to raise to request a model retry.
Can be raised from tool functions, output validators, and capability hooks
(such as after_model_request, after_tool_execute, etc.) to send
a retry prompt back to the model asking it to try again.
The message to return to the model.
Type: str Default: message
@classmethod
def __get_pydantic_core_schema__(cls, _: Any, __: Any) -> core_schema.CoreSchema
Pydantic core schema to allow ModelRetry to be (de)serialized.
core_schema.CoreSchema
Bases: Exception
Exception to raise when a tool call should be deferred.
See tools docs for more information.
Optional dictionary of metadata to attach to the deferred tool call.
This metadata will be available in DeferredToolRequests.metadata keyed by tool_call_id.
Bases: Exception
Exception to raise when a tool call requires human-in-the-loop approval.
See tools docs for more information.
Optional dictionary of metadata to attach to the deferred tool call.
This metadata will be available in DeferredToolRequests.metadata keyed by tool_call_id.
Bases: Exception
Exception to raise in before/wrap model request hooks to skip the model call.
The provided response will be used instead of calling the model.
Note: when raised in before_model_request, any message history modifications
made by earlier capabilities in that hook will not be persisted to the agent’s
message history, since the request preparation is aborted.
Bases: Exception
Exception to raise in before/wrap tool validate hooks to skip validation.
The provided args will be used as the validated arguments.
Bases: Exception
Exception to raise in before/wrap tool execute hooks to skip execution.
The provided result will be used as the tool result.
Bases: RuntimeError
Error caused by a usage mistake by the application developer — You!
Description of the mistake.
Type: str Default: message
Bases: RuntimeError
Base class for errors occurring during an agent run.
The error message.
Type: str Default: message
Bases: AgentRunError
Error raised when a Model’s usage exceeds the specified limits.
Bases: AgentRunError
Error raised when the concurrency queue depth exceeds max_queued.
Bases: AgentRunError
Error caused by unexpected Model behavior, e.g. an unexpected response code.
Description of the unexpected behavior.
Type: str Default: message
The body of the response, if available.
Type: str | None Default: json.dumps(json.loads(body), indent=2)
Bases: UnexpectedModelBehavior
Raised when content filtering is triggered by the model provider resulting in an empty response.
Bases: AgentRunError
Raised when a model provider API request fails.
The name of the model associated with the error.
Type: str Default: model_name
Bases: ModelAPIError
Raised when an model provider response has a status code of 4xx or 5xx.
The HTTP status code returned by the API.
Type: int Default: status_code
The body of the response, if available.
Type: object | None Default: body
Bases: ExceptionGroup[Any]
A group of exceptions that can be raised when all fallback models fail.
Bases: Exception
Exception used to signal a ToolRetry message should be returned to the LLM.
Bases: UnexpectedModelBehavior
Error raised when a model stops due to token limit while emitting a tool call.