Skip to content

fix: skip whitespace-only text blocks in Anthropic message#7343

Merged
angiejones merged 2 commits intoblock:mainfrom
rabi:anthropic_fix
Feb 19, 2026
Merged

fix: skip whitespace-only text blocks in Anthropic message#7343
angiejones merged 2 commits intoblock:mainfrom
rabi:anthropic_fix

Conversation

@rabi
Copy link
Contributor

@rabi rabi commented Feb 19, 2026

Summary

Fixes 400 error from Anthropic "messages: text content blocks must contain non-whitespace text". This occurs when assistant messages have their trailing whitespace trimmed to empty strings but the empty text block remains alongside other content like tool requests.

Type of Change

  • Feature
  • Bug fix
  • Refactor / Code quality
  • Performance improvement
  • Documentation
  • Tests
  • Security fix
  • Build / Release
  • Other (specify below)

Testing

Tested locally

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a 400 error from the Anthropic API by filtering out text content blocks that contain only whitespace. The issue occurred when assistant messages had their trailing whitespace trimmed to empty strings, but the empty text blocks remained alongside other content like tool requests, violating Anthropic's requirement that "text content blocks must contain non-whitespace text".

Changes:

  • Added whitespace check before adding text blocks to Anthropic message format

rabi added 2 commits February 19, 2026 10:58
Fixes 400 error from Anthropic API: "messages: text content blocks must
contain non-whitespace text". This occurs when assistant messages have
their trailing whitespace trimmed to empty strings but the empty text
block remains alongside other content like tool requests.

Change-Id: I65a1283f7dbb3599bdd869ead8b942db019f69df
Signed-off-by: rabi <ramishra@redhat.com>
Change-Id: I1b6a15a3ed0a0c5e2e5462c5bc7888a1535eb137
Signed-off-by: rabi <ramishra@redhat.com>
@angiejones angiejones added this pull request to the merge queue Feb 19, 2026
@angiejones
Copy link
Collaborator

thank you @rabi!

Merged via the queue into block:main with commit 3dd197b Feb 19, 2026
20 checks passed
katzdave added a commit that referenced this pull request Feb 19, 2026
* 'main' of github.com:block/goose:
  fix: skip whitespace-only text blocks in Anthropic message (#7343)
  fix(goose-acp): heap allocations (#7322)
jh-block added a commit that referenced this pull request Feb 19, 2026
* origin/main:
  fix(ci): deflake smoke tests for Google models (#7344)
  feat: add Cerebras provider support (#7339)
  fix: skip whitespace-only text blocks in Anthropic message (#7343)
  fix(goose-acp): heap allocations (#7322)
  Remove trailing space from links (#7156)
  fix: detect low balance and prompt for top up (#7166)
  feat(apps): add support for MCP apps to sample (#7039)
  Typescript SDK for ACP extension methods (#7319)
  chore: upgrade to rmcp 0.16.0 (#7274)
  docs: add monitoring subagent activity section (#7323)
  docs: document Desktop UI recipe editing for model/provider and extensions (#7327)
  docs: add CLAUDE_THINKING_BUDGET and CLAUDE_THINKING_ENABLED environm… (#7330)
  fix: display 'Code Mode' instead of 'code_execution' in CLI (#7321)
  docs: add Permission Policy documentation for MCP Apps (#7325)
  update RPI plan prompt (#7326)
  docs: add CLI syntax highlighting theme customization (#7324)
  fix(cli): replace shell-based update with native Rust implementation (#7148)
  docs: rename Code Execution extension to Code Mode extension (#7316)
aharvard added a commit that referenced this pull request Feb 19, 2026
* origin/main: (29 commits)
  fix(ci): deflake smoke tests for Google models (#7344)
  feat: add Cerebras provider support (#7339)
  fix: skip whitespace-only text blocks in Anthropic message (#7343)
  fix(goose-acp): heap allocations (#7322)
  Remove trailing space from links (#7156)
  fix: detect low balance and prompt for top up (#7166)
  feat(apps): add support for MCP apps to sample (#7039)
  Typescript SDK for ACP extension methods (#7319)
  chore: upgrade to rmcp 0.16.0 (#7274)
  docs: add monitoring subagent activity section (#7323)
  docs: document Desktop UI recipe editing for model/provider and extensions (#7327)
  docs: add CLAUDE_THINKING_BUDGET and CLAUDE_THINKING_ENABLED environm… (#7330)
  fix: display 'Code Mode' instead of 'code_execution' in CLI (#7321)
  docs: add Permission Policy documentation for MCP Apps (#7325)
  update RPI plan prompt (#7326)
  docs: add CLI syntax highlighting theme customization (#7324)
  fix(cli): replace shell-based update with native Rust implementation (#7148)
  docs: rename Code Execution extension to Code Mode extension (#7316)
  docs: remove ALPHA_FEATURES flag from documentation (#7315)
  docs: escape variable syntax in recipes (#7314)
  ...

# Conflicts:
#	ui/desktop/src/components/McpApps/McpAppRenderer.tsx
#	ui/desktop/src/components/McpApps/types.ts
katzdave added a commit that referenced this pull request Feb 19, 2026
* 'main' of github.com:block/goose: (24 commits)
  Docs: claude code uses stream-json (#7358)
  Improve link confirmation modal (#7333)
  fix(ci): deflake smoke tests for Google models (#7344)
  feat: add Cerebras provider support (#7339)
  fix: skip whitespace-only text blocks in Anthropic message (#7343)
  fix(goose-acp): heap allocations (#7322)
  Remove trailing space from links (#7156)
  fix: detect low balance and prompt for top up (#7166)
  feat(apps): add support for MCP apps to sample (#7039)
  Typescript SDK for ACP extension methods (#7319)
  chore: upgrade to rmcp 0.16.0 (#7274)
  docs: add monitoring subagent activity section (#7323)
  docs: document Desktop UI recipe editing for model/provider and extensions (#7327)
  docs: add CLAUDE_THINKING_BUDGET and CLAUDE_THINKING_ENABLED environm… (#7330)
  fix: display 'Code Mode' instead of 'code_execution' in CLI (#7321)
  docs: add Permission Policy documentation for MCP Apps (#7325)
  update RPI plan prompt (#7326)
  docs: add CLI syntax highlighting theme customization (#7324)
  fix(cli): replace shell-based update with native Rust implementation (#7148)
  docs: rename Code Execution extension to Code Mode extension (#7316)
  ...
michaelneale added a commit that referenced this pull request Feb 19, 2026
* main: (46 commits)
  chore(deps): bump hono from 4.11.9 to 4.12.0 in /ui/desktop (#7369)
  Include 3rd-party license copy for JavaScript/CSS minified files (#7352)
  docs for reasoning env var (#7367)
  docs: update skills detail page to reference Goose Summon extension (#7350)
  fix(apps): restore MCP app sampling support reverted by #6933 (#7366)
  feat: TUI client of goose-acp (#7362)
  docs: agent variable (#7365)
  docs: pass env vars to shell (#7361)
  docs: update sandbox topic (#7336)
  feat: add local inference provider with llama.cpp backend and HuggingFace model management (#6933)
  Docs: claude code uses stream-json (#7358)
  Improve link confirmation modal (#7333)
  fix(ci): deflake smoke tests for Google models (#7344)
  feat: add Cerebras provider support (#7339)
  fix: skip whitespace-only text blocks in Anthropic message (#7343)
  fix(goose-acp): heap allocations (#7322)
  Remove trailing space from links (#7156)
  fix: detect low balance and prompt for top up (#7166)
  feat(apps): add support for MCP apps to sample (#7039)
  Typescript SDK for ACP extension methods (#7319)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments