Skip to content

fix(zen): guard against empty tool_result content in Anthropic provider#15375

Closed
zerone0x wants to merge 1 commit intoanomalyco:devfrom
zerone0x:fix/issue-15371-empty-tool-result-content
Closed

fix(zen): guard against empty tool_result content in Anthropic provider#15375
zerone0x wants to merge 1 commit intoanomalyco:devfrom
zerone0x:fix/issue-15371-empty-tool-result-content

Conversation

@zerone0x
Copy link
Contributor

Summary

Fixes #15371

  • Guard against empty/null/undefined tool content in the toAnthropicRequest function
  • When a tool call returns an empty string (""), null, or undefined, the Anthropic API rejects the request with "content field is empty" error
  • Normalize empty tool content to "(no output)" before building the tool_result content block

Changes

  • packages/console/app/src/routes/zen/util/provider/anthropic.ts: Added content normalization in the role === "tool" branch of toAnthropicRequest — empty strings, null, undefined, and empty arrays now fall back to "(no output)" while non-empty strings and non-empty arrays pass through unchanged

Test plan

  • Configure a tool that returns an empty string (e.g. a write-only tool or command with no stdout)
  • Verify the Anthropic API no longer rejects the request with "content field is empty"
  • Verify tools with normal output still work correctly

🤖 Generated with Claude Code

When a tool call returns an empty string, the Anthropic API rejects the
request with "content field is empty". Normalize empty/null/undefined
tool content to "(no output)" before sending the request.

Fixes anomalyco#15371

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions bot added contributor needs:compliance This means the issue will auto-close after 2 hours. labels Feb 27, 2026
@github-actions
Copy link
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found one potentially related PR:

PR #14586: fix: filter empty content blocks for Bedrock provider
#14586

Why it might be related: This PR addresses a similar issue of filtering empty content blocks, but for the Bedrock provider instead of Anthropic. Both involve handling empty content that causes API errors.

The other PRs found (#8497, #8958, #11572, #11882, #12634, #14637) are related to provider compatibility and message handling but address different issues (thinking blocks, reasoning content, tool_use blocks).

However, if PR #14586 is already merged and handles a similar pattern, it might provide useful context for this Anthropic fix.

@github-actions
Copy link
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Feb 27, 2026
@github-actions github-actions bot closed this Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant