strands.tools.structured_output.structured_output_tool
Structured output tool implementation.
This module provides a real tool implementation for structured output that integrates with the existing tool execution and error handling infrastructure.
StructuredOutputTool
class StructuredOutputTool(AgentTool)Defined in: src/strands/tools/structured_output/structured_output_tool.py:26
Tool implementation for structured output validation.
__init__
def __init__(structured_output_model: type[BaseModel]) -> NoneDefined in: src/strands/tools/structured_output/structured_output_tool.py:29
Initialize a structured output tool.
Arguments:
structured_output_model- The Pydantic model class that defines the expected output structure.
tool_name
@propertydef tool_name() -> strDefined in: src/strands/tools/structured_output/structured_output_tool.py:60
Get the name of the tool.
Returns:
The name of the tool (same as the Pydantic model class name).
tool_spec
@propertydef tool_spec() -> ToolSpecDefined in: src/strands/tools/structured_output/structured_output_tool.py:69
Get the tool specification for this structured output tool.
Returns:
The tool specification generated from the Pydantic model.
tool_type
@propertydef tool_type() -> strDefined in: src/strands/tools/structured_output/structured_output_tool.py:78
Identifies this as a structured output tool implementation.
Returns:
“structured_output”.
structured_output_model
@propertydef structured_output_model() -> type[BaseModel]Defined in: src/strands/tools/structured_output/structured_output_tool.py:87
Get the Pydantic model type for this tool.
Returns:
The Pydantic model class.
stream
@overrideasync def stream(tool_use: ToolUse, invocation_state: dict[str, Any], **kwargs: Any) -> ToolGeneratorDefined in: src/strands/tools/structured_output/structured_output_tool.py:96
Validate the structured output and return appropriate result.
Arguments:
tool_use- The tool use request containing the data to validate.invocation_state- Context for the tool invocation (kept for compatibility).**kwargs- Additional keyword arguments, including structured_output_context.
Yields:
Tool events with the last being the tool result (success or error).