Exception raised when a tool function should be retried.
The agent will return the message to the model and ask it to try calling the function/tool again.
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
222324252627282930313233
classModelRetry(Exception):"""Exception raised when a tool function should be retried. The agent will return the message to the model and ask it to try calling the function/tool again. """message:str"""The message to return to the model."""def__init__(self,message:str):self.message=messagesuper().__init__(message)
Error caused by a usage mistake by the application developer — You!
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
363738394041424344
classUserError(RuntimeError):"""Error caused by a usage mistake by the application developer — You!"""message:str"""Description of the mistake."""def__init__(self,message:str):self.message=messagesuper().__init__(message)
Base class for errors occurring during an agent run.
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
474849505152535455565758
classAgentRunError(RuntimeError):"""Base class for errors occurring during an agent run."""message:str"""The error message."""def__init__(self,message:str):self.message=messagesuper().__init__(message)def__str__(self)->str:returnself.message
Error caused by unexpected Model behavior, e.g. an unexpected response code.
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
656667686970717273747576777879808182838485868788
classUnexpectedModelBehavior(AgentRunError):"""Error caused by unexpected Model behavior, e.g. an unexpected response code."""message:str"""Description of the unexpected behavior."""body:str|None"""The body of the response, if available."""def__init__(self,message:str,body:str|None=None):self.message=messageifbodyisNone:self.body:str|None=Noneelse:try:self.body=json.dumps(json.loads(body),indent=2)exceptValueError:self.body=bodysuper().__init__(message)def__str__(self)->str:ifself.body:returnf'{self.message}, body:\n{self.body}'else:returnself.message
classModelHTTPError(AgentRunError):"""Raised when an model provider response has a status code of 4xx or 5xx."""status_code:int"""The HTTP status code returned by the API."""model_name:str"""The name of the model associated with the error."""body:object|None"""The body of the response, if available."""message:str"""The error message with the status code and response body, if available."""def__init__(self,status_code:int,model_name:str,body:object|None=None):self.status_code=status_codeself.model_name=model_nameself.body=bodymessage=f'status_code: {status_code}, model_name: {model_name}, body: {body}'super().__init__(message)