Overview
Content blocks represent different types of content within messages. They are used in bothUserMessage and AssistantMessage content.
TextBlock
Represents plain text content.str
required
The text content.
Example
ThinkingBlock
Represents Claude’s internal reasoning (extended thinking).str
required
The thinking content showing Claude’s reasoning process.
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.str
required
Unique identifier for this tool use (e.g.,
"toolu_01ABC123").str
required
Name of the tool being invoked (e.g.,
"Bash", "Read", "Write").dict[str, Any]
required
Tool input parameters as a dictionary.
Example
Common Tool Input Schemas
ToolResultBlock
Represents the result of a tool execution.str
required
ID of the tool use this result corresponds to (matches
ToolUseBlock.id).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
Noneif the tool had no output
bool | None
Whether the tool execution resulted in an error.
Example
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:Related Types
- Message Types - Message containers that hold content blocks
- ClaudeAgentOptions - Configuration including tool and thinking settings