Skip to content

Anthropic provider: empty tool_result content crashes with 'content field is empty' API error #15371

Closed as not planned

Description

@isc-tdyar

Bug Description

When a tool call returns an empty string, the Anthropic provider passes content: "" directly into the tool_result content block. The Anthropic API rejects this with:

Error: The content field in the Message object at messages.N is empty. Add a ContentBlock object to the content field and try again.

Location

packages/console/app/src/routes/zen/util/provider/anthropic.ts, in the role === "tool" branch:

if ((m as any).role === "tool") {
  msgsOut.push({
    role: "user",
    content: [
      {
        type: "tool_result",
        tool_use_id: (m as any).tool_call_id,
        content: (m as any).content,  // ← empty string passes through unchecked
        ...cc(),
      },
    ],
  })
}

Reproduction

Any tool that returns an empty string (e.g. a write-only tool, a command with no stdout, or a tool that errors silently) will trigger this. The error identifies the exact message index (e.g. messages.13), making it look like a history corruption issue rather than a missing guard.

Fix

content: (m as any).content || "(no output)",

Or more robustly, filter/normalize before building the block:

const toolContent = (m as any).content
content: (typeof toolContent === "string" && toolContent.length > 0)
  ? toolContent
  : Array.isArray(toolContent) && toolContent.length > 0
  ? toolContent
  : "(no output)",

Environment

  • opencode (console/zen provider path)
  • Anthropic API (claude-sonnet-4-6, claude-opus-4-6)
  • Triggered while running oc-dcp agent loop against a project with tools that produce no stdout

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    zenRelates to Zen
    on Feb 27, 2026
  2. added a commit that references this issue on Feb 27, 2026
    e6544dd
  3. github-actions commented on Apr 29, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)zenRelates to Zen

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions