Skip to content

fix(anthropic): handle empty response.content safely to prevent IndexError - #181

Closed
abhi-0203 wants to merge 1 commit into
alexzhang13:mainfrom
abhi-0203:fix/anthropic-empty-content-indexerror
Closed

abhi-0203 wants to merge 1 commit into
alexzhang13:mainfrom
abhi-0203:fix/anthropic-empty-content-indexerror

Conversation

@abhi-0203

Copy link
Copy Markdown

Summary

  • Fixes IndexError in AnthropicClient.completion() and acompletion() when the Anthropic API returns a response with an empty content list (e.g., immediate end_turn under load).
  • Filters response content blocks for type "text" and safely returns the first text block or an empty string "" if none exist.
  • Added unit tests covering empty response content and normal text content.

Closes #178

@abhi-0203 abhi-0203 closed this by deleting the head repository Aug 30, 2026
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.

AnthropicClient: IndexError on empty response.content in completion()/acompletion()

1 participant