pydantic_ai.models.test
Utility model for quickly testing apps built with Pydantic AI.
Here’s a minimal example:
from pydantic_ai import Agent
from pydantic_ai.models.test import TestModel
my_agent = Agent('openai:gpt-5.2', instructions='...')
async def test_my_agent():
"""Unit test for my_agent, to be run by pytest."""
m = TestModel()
with my_agent.override(model=m):
result = await my_agent.run('Testing my agent...')
assert result.output == 'success (no tool calls)'
assert m.last_model_request_parameters.function_tools == []
See Unit testing with TestModel for detailed documentation.
Bases: Model
A model specifically for testing purposes.
This will (by default) call all tools in the agent, then return a tool response if possible, otherwise a plain response.
How useful this model is will vary significantly.
Apart from __init__ derived by the dataclass decorator, all methods are private or match those
of the base class.
List of tools to call. If 'all', all tools will be called.
Type: list[str] | Literal[‘all’] Default: call_tools
If set, this text is returned as the final output.
Type: str | None Default: custom_output_text
If set, these args will be passed to the output tool.
Type: Any | None Default: custom_output_args
Seed for generating random data.
Type: int Default: seed
The last ModelRequestParameters passed to the model in a request.
The ModelRequestParameters contains information about the function and output tools available during request handling.
This is set when a request is made, so will reflect the function tools from the last step of the last run.
Type: ModelRequestParameters | None Default: None
The model name.
Type: str
The model provider.
Type: str
def __init__(
call_tools: list[str] | Literal['all'] = 'all',
custom_output_text: str | None = None,
custom_output_args: Any | None = None,
seed: int = 0,
model_name: str = 'test',
profile: ModelProfileSpec | None = None,
settings: ModelSettings | None = None,
)
Initialize TestModel with optional settings and profile.
@classmethod
def supported_builtin_tools(cls) -> frozenset[type[AbstractBuiltinTool]]
TestModel supports all builtin tools for testing flexibility.
frozenset[type[AbstractBuiltinTool]]
Bases: StreamedResponse
A structured response that streams test data.
Get the model name of the response.
Type: str
Get the provider name.
Type: str
Get the provider base URL.
Get the timestamp of the response.
Type: datetime