Skip to content

[Platform][Anthropic] Fix TypeError in AssistantMessageNormalizer when toolCalls is null #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Muneer-Shafi
Copy link

@Muneer-Shafi Muneer-Shafi commented Aug 11, 2025

Q A
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #302
License MIT

Summary

Fixes a TypeError in AssistantMessageNormalizer::normalize() that occurs when $data->toolCalls is null in the Anthropic bridge.

Problem

The current implementation calls array_map() on potentially null toolCalls:

'content' => array_map(static function (ToolCall $toolCall) {
    // ...
}, $data->toolCalls ?? []),

@carsonbot carsonbot changed the title Fix TypeError in AssistantMessageNormalizer when toolCalls is null Fix TypeError in AssistantMessageNormalizer when toolCalls is null Aug 11, 2025
@Muneer-Shafi Muneer-Shafi changed the title Fix TypeError in AssistantMessageNormalizer when toolCalls is null [AIBundle] Fix TypeError in AssistantMessageNormalizer when toolCalls is null Aug 11, 2025
- Use hasToolCalls() check before array_map to prevent TypeError
- Return content when no tool calls are present
- Maintains backward compatibility and proper return types
@Muneer-Shafi Muneer-Shafi force-pushed the fix-assistant-message-normalizer-null-toolcalls branch from 969669d to e08c3b1 Compare August 11, 2025 12:28
@Muneer-Shafi Muneer-Shafi changed the title [AIBundle] Fix TypeError in AssistantMessageNormalizer when toolCalls is null [Bridge\Anthropic] Fix TypeError in AssistantMessageNormalizer when toolCalls is null Aug 11, 2025
Copy link
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Muneer-Shafi and welcome to the repository! :)
Thanks for working on that fix - can you please bring in a test case to prove error and fix?

@chr-hertel chr-hertel changed the title [Bridge\Anthropic] Fix TypeError in AssistantMessageNormalizer when toolCalls is null [Platform][Anthropic] Fix TypeError in AssistantMessageNormalizer when toolCalls is null Aug 11, 2025
@chr-hertel chr-hertel added the Platform Issues & PRs about the AI Platform component label Aug 11, 2025
@Muneer-Shafi
Copy link
Author

Hi @Muneer-Shafi and welcome to the repository! :) Thanks for working on that fix - can you please bring in a test case to prove error and fix?

@chr-hertel i have updated test for Claude AssistantMessageNormalizerTest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform Issues & PRs about the AI Platform component Status: Needs Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Platform] AssistantMessageNormalizer throws TypeError when toolCalls is null
3 participants