Skip to content

ToolResultBlock dataclass

A tool result block that contains the results for a tool request that the model previously made. For more information, see Call a tool with the Converse API in the Amazon Bedrock User Guide.

Source code in src/aws_sdk_bedrock_runtime/models.py
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
@dataclass(kw_only=True)
class ToolResultBlock:
    """A tool result block that contains the results for a tool request that
    the model previously made. For more information, see [Call a tool with
    the Converse
    API](https://docs.aws.amazon.com/bedrock/latest/userguide/tool-use.html)
    in the Amazon Bedrock User Guide.
    """

    tool_use_id: str
    """The ID of the tool request that this is the result for."""

    content: list[ToolResultContentBlock]
    """The content for tool result content block."""

    status: str | None = None
    """The status for the tool result content block.

    Note:
        This field is only supported by Amazon Nova and Anthropic Claude 3 and 4
        models.
    """

    type: str | None = None
    """The type for the tool result content block."""

    def serialize(self, serializer: ShapeSerializer):
        serializer.write_struct(_SCHEMA_TOOL_RESULT_BLOCK, self)

    def serialize_members(self, serializer: ShapeSerializer):
        serializer.write_string(
            _SCHEMA_TOOL_RESULT_BLOCK.members["toolUseId"], self.tool_use_id
        )
        _serialize_tool_result_content_blocks(
            serializer, _SCHEMA_TOOL_RESULT_BLOCK.members["content"], self.content
        )
        if self.status is not None:
            serializer.write_string(
                _SCHEMA_TOOL_RESULT_BLOCK.members["status"], self.status
            )

        if self.type is not None:
            serializer.write_string(
                _SCHEMA_TOOL_RESULT_BLOCK.members["type"], self.type
            )

    @classmethod
    def deserialize(cls, deserializer: ShapeDeserializer) -> Self:
        return cls(**cls.deserialize_kwargs(deserializer))

    @classmethod
    def deserialize_kwargs(cls, deserializer: ShapeDeserializer) -> dict[str, Any]:
        kwargs: dict[str, Any] = {}

        def _consumer(schema: Schema, de: ShapeDeserializer) -> None:
            match schema.expect_member_index():
                case 0:
                    kwargs["tool_use_id"] = de.read_string(
                        _SCHEMA_TOOL_RESULT_BLOCK.members["toolUseId"]
                    )

                case 1:
                    kwargs["content"] = _deserialize_tool_result_content_blocks(
                        de, _SCHEMA_TOOL_RESULT_BLOCK.members["content"]
                    )

                case 2:
                    kwargs["status"] = de.read_string(
                        _SCHEMA_TOOL_RESULT_BLOCK.members["status"]
                    )

                case 3:
                    kwargs["type"] = de.read_string(
                        _SCHEMA_TOOL_RESULT_BLOCK.members["type"]
                    )

                case _:
                    logger.debug("Unexpected member schema: %s", schema)

        deserializer.read_struct(_SCHEMA_TOOL_RESULT_BLOCK, consumer=_consumer)
        return kwargs

Attributes

content instance-attribute

content: list[ToolResultContentBlock]

The content for tool result content block.

status class-attribute instance-attribute

status: str | None = None

The status for the tool result content block.

Note

This field is only supported by Amazon Nova and Anthropic Claude 3 and 4 models.

tool_use_id instance-attribute

tool_use_id: str

The ID of the tool request that this is the result for.

type class-attribute instance-attribute

type: str | None = None

The type for the tool result content block.