Skip to content

fix(litellm): generate fallback ID for null tool_call IDs#1843

Closed
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
giulio-leone:fix/litellm-null-tool-call-id-1259
Closed

fix(litellm): generate fallback ID for null tool_call IDs#1843
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
giulio-leone:fix/litellm-null-tool-call-id-1259

Conversation

@giulio-leone
Copy link

Bug

When using LiteLLM with certain proxy backends, tool_calls are returned with id: null. This causes downstream failures in the event loop when it tries to match tool results back to their originating tool_call IDs.

Reported in: #1259

Root cause

_process_tool_calls() passes tool_deltas[0] directly to format_chunk(), which reads event["data"].id to set toolUseId. When the proxy returns null for the ID, toolUseId becomes None, breaking tool result matching.

Fix

Before emitting the content_start event, check if the first tool delta's id is None and generate a UUID-based fallback (tooluse_<hex>), matching the ID format used elsewhere in the codebase.

Testing

  • Added test_stream_non_streaming_null_tool_call_id: creates a tool_call with id=None, verifies the emitted event has a non-null toolUseId starting with tooluse_
  • All 42 LiteLLM model tests pass

Fixes #1259

Some LiteLLM proxy backends return tool_calls with id=None, causing
downstream failures when the event loop tries to match tool results
back to tool_call IDs.

Generate a UUID-based fallback ID (tooluse_<hex>) when the tool_call
ID is None, matching the format used elsewhere in the codebase.

Fixes strands-agents#1259

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@giulio-leone
Copy link
Author

Closing to reduce PR volume. Happy to resubmit individually if the team finds this fix useful.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Strands providing null value in id field of tool_calls

1 participant