Skip to content

AssistantMessageNormalizer throws TypeError when toolCalls is null #302

@Muneer-Shafi

Description

@Muneer-Shafi

The AssistantMessageNormalizer::normalize() method in vendor/symfony/ai-platform/src/Bridge/Anthropic/Contract/AssistantMessageNormalizer.php throws a TypeError when $data->toolCalls is null.

Error message
array_map(): Argument #2 ($array) must be of type array, null given

Root Cause
The current code uses $data->toolCalls ?? [] as a fallback, but this doesn't prevent the issue because array_map() is called regardless of whether toolCalls is null or not. The code assumes toolCalls will always be an array when it may be null.

Current Code (Problematic)
php'content' => array_map(static function (ToolCall $toolCall) {
return [
'type' => 'tool_use',
'id' => $toolCall->id,
'name' => $toolCall->name,
'input' => [] !== $toolCall->arguments ? $toolCall->arguments : new \stdClass(),
];
}, $data->toolCalls ?? []),

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions