Skip to content

fix(ai): treat whitespace-only tool text as empty - #462

Merged
shuv1337 merged 4 commits into
integration-v2from
cursor/blank-tool-text-24cd
Oct 29, 2026
Merged

shuv1337 merged 4 commits into
integration-v2from
cursor/blank-tool-text-24cd

Conversation

@shuv1337

@shuv1337 shuv1337 commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Issue for this PR

No tracked issue.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Whitespace-only tool text was kept, while an empty string was replaced with (no tool output). normalizeToolResult treats .trim() === "" as empty for text results and error values. Non-blank text, including surrounding spaces, is unchanged.

For content arrays, exact "" items are removed because they cannot separate joined text. The (no tool output) fallback applies only when every remaining item is blank and there is no media. Whitespace such as "\n" stays, so Mistral's empty-string join of ["foo", "\n", "bar"] stays "foo\nbar".

Anthropic and Bedrock drop remaining blank text, including " ", while lowering a tool result. A Bedrock result of [{text:" "}, image] sends only the image.

Head 60ac11e8c2.

How did you verify your code works?

env -u RECORD CI=true bun test --timeout 30000 in packages/ai on 60ac11e8c2: 1963 pass, 28 skip, 0 fail. The skips are recorded cases whose cassettes are not on disk. Recorded fixtures that have cassettes passed.

Visual

No UI change.

Screenshots / recordings

None.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR
Open in Web Open in Cursor 

Blank tool text, error values, and content items now match an empty
string. Anthropic success tool results drop that text and keep non-blank
text unchanged.
PR 461 landed on the base while this branch was open. Keep that error-result
filter and the whitespace-only success path from this branch.

# Conflicts:
#	packages/ai/src/protocols/anthropic-messages.ts
@shuv1337
shuv1337 merged commit 9805d87 into integration-v2 Oct 29, 2026
5 checks passed
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