Skip to main content

Overview

Content blocks represent different types of content within messages. They are used in both UserMessage and AssistantMessage content.

TextBlock

Represents plain text content.
text
str
required
The text content.

Example

ThinkingBlock

Represents Claude’s internal reasoning (extended thinking).
thinking
str
required
The thinking content showing Claude’s reasoning process.
signature
str
required
Cryptographic signature verifying the thinking content.

Example

Thinking blocks are only present when extended thinking is enabled via the thinking option in ClaudeAgentOptions.

ToolUseBlock

Represents Claude’s intent to use a tool.
id
str
required
Unique identifier for this tool use (e.g., "toolu_01ABC123").
name
str
required
Name of the tool being invoked (e.g., "Bash", "Read", "Write").
input
dict[str, Any]
required
Tool input parameters as a dictionary.

Example

Common Tool Input Schemas

ToolResultBlock

Represents the result of a tool execution.
tool_use_id
str
required
ID of the tool use this result corresponds to (matches ToolUseBlock.id).
content
str | list[dict[str, Any]] | None
Tool output content. Can be:
  • A string for simple text output
  • A list of content blocks for structured output
  • None if the tool had no output
is_error
bool | None
Whether the tool execution resulted in an error.

Example

Tool result blocks are typically generated internally by the SDK and CLI. You usually don’t need to create them manually unless implementing custom tool execution.

Pattern Matching Example

Python 3.10+ pattern matching makes it easy to handle different content block types:

Type Guards

For older Python versions or more explicit type checking: