Skip to content

Fix IndexError on empty tool_calls list in proxy convert#68

Open
hobostay wants to merge 1 commit into
antoinezambelli:mainfrom
hobostay:fix/empty-toolcalls-indexerror
Open

Fix IndexError on empty tool_calls list in proxy convert#68
hobostay wants to merge 1 commit into
antoinezambelli:mainfrom
hobostay:fix/empty-toolcalls-indexerror

Conversation

@hobostay
Copy link
Copy Markdown

Summary

  • tool_calls_to_openai() and tool_calls_to_sse_events() both access tool_calls[0] without checking if the list is empty
  • If an upstream filtering step ever removes all tool calls, this raises an unhandled IndexError
  • Add early-return guards that fall back to the corresponding text response helpers when the list is empty

Impact

  • Without this fix, an empty tool_calls list would crash the proxy's response serialization with a 500 error instead of gracefully returning an empty response

Test plan

  • Call tool_calls_to_openai([]) and verify it returns a valid response without IndexError
  • Call tool_calls_to_sse_events([]) and verify it returns valid SSE events without IndexError
  • Verify normal tool call conversion still works

🤖 Generated with Claude Code

`tool_calls_to_openai()` and `tool_calls_to_sse_events()` both access
`tool_calls[0]` without checking if the list is empty. If an upstream
filtering step removes all tool calls, this raises an unhandled
IndexError that crashes the proxy's response serialization with a 500
error.

Add early-return guards that fall back to the corresponding text
response helpers when the list is empty.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

1 participant