Skip to content

ToParam() Method Doesn't Handle WebSearchToolResultBlock #242

@katiabazzi

Description

@katiabazzi

When using the web search tool (web_search_20250305), the Go SDK's Message.ToParam() method fails to properly convert WebSearchToolResultBlock and ServerToolUseBlock content, resulting in empty content blocks that cause API errors in multi-turn conversations.

Steps to reproduce:

  1. Enable web search tool in API request
  2. Send a message that triggers web search (e.g., "What's the latest news about AI?")
  3. Store the assistant's response using message.ToParam()
  4. Send a follow-up message in the same conversation
  5. API returns error: "messages.1: all messages must have non-empty content except for the optional final assistant message"

Root Cause
The SDK's ToParam() method (in message.go:664-680) only handles:

  • TextBlock
  • ToolUseBlock
  • ThinkingBlock
  • RedactedThinkingBlock

It does NOT handle:

  • ServerToolUseBlock (used for web search invocation)
  • WebSearchToolResultBlock (contains search results)

When encountering these unhandled types, it returns an empty ContentBlockParamUnion{}.

Impact
Applications cannot use web search in multi-turn conversations without implementing custom message conversion logic to filter out or properly handle these blocks.

Suggested Fix
Update the SDK's ToParam() method to properly handle ServerToolUseBlock and WebSearchToolResultBlock

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions