Include Tool Return Schemas
IncludeToolReturnSchemas is a capability that includes return type schemas in tool definitions sent to the model. For models that natively support return schemas (e.g. Google Gemini), the schema is passed as a structured field in the API request. For other models, it is injected into the tool description as JSON text.
from pydantic_ai import Agent
from pydantic_ai.capabilities import IncludeToolReturnSchemas
from pydantic_ai.models.test import TestModel
test_model = TestModel()
agent = Agent(test_model, capabilities=[IncludeToolReturnSchemas()])
@agent.tool_plain
def get_temperature(city: str) -> float:
"""Get the temperature for a city."""
return 21.0
result = agent.run_sync('What is the temperature in Paris?')
params = test_model.last_model_request_parameters
assert params is not None
td = params.function_tools[0]
assert td.include_return_schema is True
(This example is complete, it can be run “as is”)
Use the tools parameter to select which tools should include return schemas. It accepts a list of tool names, a metadata dict for matching, or a callable predicate:
from pydantic_ai import Agent
from pydantic_ai.capabilities import IncludeToolReturnSchemas
from pydantic_ai.models.test import TestModel
test_model = TestModel()
agent = Agent(
test_model,
capabilities=[IncludeToolReturnSchemas(tools=['get_temperature'])],
)
@agent.tool_plain
def get_temperature(city: str) -> float:
"""Get the temperature for a city."""
return 21.0
@agent.tool_plain
def get_greeting(name: str) -> str:
"""Get a greeting."""
return f'Hello, {name}!'
result = agent.run_sync('Hello')
params = test_model.last_model_request_parameters
assert params is not None
temp_tool = next(t for t in params.function_tools if t.name == 'get_temperature')
greet_tool = next(t for t in params.function_tools if t.name == 'get_greeting')
assert temp_tool.include_return_schema is True
assert greet_tool.include_return_schema is None
(This example is complete, it can be run “as is”)
The same effect can be achieved at the toolset level using .include_return_schemas() — see toolset composition.