Skip to documentation
Documentation navigation

Documentation navigation

Documentation / guides

ToolResultBlock

Nest tool output blocks and preserve tool success or failure.

developer

ToolResultBlock carries the result of one tool call as nested content. Nesting lets a tool return text, documents, images, or another provider-neutral block without inventing a second message format.

API surface

type ToolResultBlock struct {
	ToolUseID string
	Content   []Block
	IsError   bool
}
FieldMeaning
ToolUseIDThe ToolUseBlock.ID being answered
ContentOrdered nested blocks; may include text or multimodal values
IsErrorWhether the tool result is an error result

The block implements custom JSON handling because Content is another sealed block slice. MarshalBlocks and UnmarshalBlocks recurse through this field and enforce the per-slice safety cap.

Example

package main

import (
	"fmt"
	"github.com/looprig/core/content"
)

func main() {
	result := &content.ToolResultBlock{
		ToolUseID: "call_42",
		Content: []content.Block{
			&content.TextBlock{Text: "72 degrees"},
		},
	}
	wire, err := content.MarshalBlock(result)
	if err != nil {
		panic(err)
	}
	decoded, err := content.UnmarshalBlock(wire)
	if err != nil {
		panic(err)
	}
	fmt.Println(decoded.(*content.ToolResultBlock).ToolUseID)
}

At the message level, ToolResultMessage repeats ToolUseID and IsError while carrying top-level blocks. Use one or the other according to the provider codec’s message model; do not silently discard the correlation ID.

Proof

Related: ToolUseBlock, ToolResultMessage.

← back to documentation