Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

fix: return empty content array for null/undefined tool results#1097

Open
serhiizghama wants to merge 2 commits into
strands-agents:mainfrom
serhiizghama:fix/void-tool-returns-empty-content
Open

fix: return empty content array for null/undefined tool results#1097
serhiizghama wants to merge 2 commits into
strands-agents:mainfrom
serhiizghama:fix/void-tool-returns-empty-content

Conversation

@serhiizghama

Copy link
Copy Markdown

Problem

When a tool callback returns null or undefined (void/side-effectful tools), _wrapInToolResult was producing a TextBlock with the placeholder text '<null>' or '<undefined>'. These strings:

  • look like internal placeholders to both humans and models
  • are not valid JSON (unlike Python's json.dumps(None)"null")
  • create confusion for side-effectful tools (delete, send, log) that have no meaningful return value

Fixes strands-agents/harness-sdk#2529.

Solution

Replace the separate null and undefined handlers with a single combined check that returns an empty content array:

if (value === null || value === undefined) {
  return new ToolResultBlock({
    toolUseId,
    status: 'success',
    content: [],
  })
}

An empty content array correctly signals success without a misleading placeholder. This matches the common expectation for side-effectful tools.

Testing

  • Updated existing null and undefined test cases to assert content: []
  • Added a new void callback test covering the real-world side-effectful tool pattern (see issue example with greet)
  • All 2834 unit tests pass; no type errors

Void/null-returning tools were producing TextBlock('<undefined>') and
TextBlock('<null>') — strings that look like placeholders and are not
valid JSON. Side-effectful tools that don't return a value should
signal success with an empty content array instead.
Update existing tests to expect empty content arrays instead of
'<null>'/'<undefined>' placeholders. Add a dedicated void-callback test
covering the common side-effectful tool pattern.
lizradway pushed a commit to lizradway/sdk-typescript that referenced this pull request Jun 1, 2026
@strands-agent

Copy link
Copy Markdown
Collaborator

This repository has been merged into the strands-agents/harness-sdk monorepo and will be archived shortly. All new development happens there.

If this PR is still relevant, please recreate it against the monorepo. The code now lives under strands-ts/. Full commit history was preserved, so your base should be findable.

Apologies for the disruption, and thank you for contributing!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Tools returning undefined/null produce invalid text content '<undefined>'/'<null>'

2 participants