Skip to content

Tool result format

A tool returns a result that the agent adds to the conversation and sends back to the model. When a custom tool returns a plain value, the SDK wraps it in this structure automatically. Construct the structure yourself when a tool needs to return typed content, mixed content blocks, or an explicit error status. This page documents that structure, the content types it carries, and the conversion rules the SDK applies to return values.

The ToolResult dictionary has three fields:

{
"toolUseId": str, # ID of the tool use request. Matches the incoming request.
"status": str, # Either "success" or "error"
"content": list[dict], # Content items, each in one of the supported formats
}

The toolUseId is optional in a value returned from a decorated function: the @tool decorator fills it in from the originating request.

The content field is a list of content blocks. Each block carries one type of output:

  • text: a string of text output
  • json: any JSON-serializable data structure

Both SDKs also accept image and document blocks; TypeScript additionally accepts video. A single result can mix block types, for example a text summary alongside a JSON payload.

A success response carries a "success" status and one or more content blocks:

{
"toolUseId": "tool-123",
"status": "success",
"content": [
{"text": "Operation completed successfully"},
{"json": {"results": [1, 2, 3], "total": 3}}
]
}

An error response carries an "error" status and describes what failed:

{
"toolUseId": "tool-123",
"status": "error",
"content": [
{"text": "Error: Unable to process request due to invalid parameters"}
]
}

The @tool decorator converts a function’s return value into a ToolResult:

  1. A string or other simple value is wrapped as {"text": str(result)}.
  2. A dictionary that already has the ToolResult structure is used directly.
  3. A raised exception is converted to an error response.