pydantic_ai.exceptions
ModelRetry
Bases: Exception
Exception to raise 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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
__get_pydantic_core_schema__
classmethod
Pydantic core schema to allow ModelRetry to be (de)serialized.
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
CallDeferred
Bases: Exception
Exception to raise when a tool call should be deferred.
See tools docs for more information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
dict[str, Any] | None
|
Optional dictionary of metadata to attach to the deferred tool call.
This metadata will be available in |
None
|
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
ApprovalRequired
Bases: Exception
Exception to raise when a tool call requires human-in-the-loop approval.
See tools docs for more information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
dict[str, Any] | None
|
Optional dictionary of metadata to attach to the deferred tool call.
This metadata will be available in |
None
|
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
SkipModelRequest
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.
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
SkipToolValidation
Bases: Exception
Exception to raise in before/wrap tool validate hooks to skip validation.
The provided args will be used as the validated arguments.
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
130 131 132 133 134 135 136 137 138 139 140 | |
SkipToolExecution
Bases: Exception
Exception to raise in before/wrap tool execute hooks to skip execution.
The provided result will be used as the tool result.
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
143 144 145 146 147 148 149 150 151 152 153 | |
UserError
Bases: RuntimeError
Error caused by a usage mistake by the application developer — You!
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
156 157 158 159 160 161 162 163 164 | |
AgentRunError
Bases: RuntimeError
Base class for errors occurring during an agent run.
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
167 168 169 170 171 172 173 174 175 176 177 178 | |
UsageLimitExceeded
Bases: AgentRunError
Error raised when a Model's usage exceeds the specified limits.
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
181 182 | |
ConcurrencyLimitExceeded
Bases: AgentRunError
Error raised when the concurrency queue depth exceeds max_queued.
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
185 186 | |
UnexpectedModelBehavior
Bases: AgentRunError
Error caused by unexpected Model behavior, e.g. an unexpected response code.
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
ContentFilterError
Bases: UnexpectedModelBehavior
Raised when content filtering is triggered by the model provider resulting in an empty response.
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
218 219 | |
ModelAPIError
Bases: AgentRunError
Raised when a model provider API request fails.
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
222 223 224 225 226 227 228 229 230 231 232 233 | |
model_name
instance-attribute
model_name: str = model_name
The name of the model associated with the error.
ModelHTTPError
Bases: ModelAPIError
Raised when an model provider response has a status code of 4xx or 5xx.
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
FallbackExceptionGroup
Bases: ExceptionGroup[Any]
A group of exceptions that can be raised when all fallback models fail.
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
255 256 | |
ToolRetryError
Bases: Exception
Exception used to signal a ToolRetry message should be returned to the LLM.
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
IncompleteToolCall
Bases: UnexpectedModelBehavior
Error raised when a model stops due to token limit while emitting a tool call.
Source code in pydantic_ai_slim/pydantic_ai/exceptions.py
294 295 | |