Skip to content

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.

class StructuredOutputTool(AgentTool)

Defined in: src/strands/tools/structured_output/structured_output_tool.py:26

Tool implementation for structured output validation.

def __init__(structured_output_model: type[BaseModel]) -> None

Defined 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.
@property
def tool_name() -> str

Defined 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).

@property
def tool_spec() -> ToolSpec

Defined 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.

@property
def tool_type() -> str

Defined in: src/strands/tools/structured_output/structured_output_tool.py:78

Identifies this as a structured output tool implementation.

Returns:

“structured_output”.

@property
def 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.

@override
async def stream(tool_use: ToolUse, invocation_state: dict[str, Any],
**kwargs: Any) -> ToolGenerator

Defined 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).