From 34e05da53e25b28f21095c52f490f05032d67b18 Mon Sep 17 00:00:00 2001 From: Joseph Ivan Obala Date: Thu, 26 Mar 2026 15:54:27 +0300 Subject: [PATCH] fix: ToolCall::arguments() returns null for valid JSON null string When a provider returns a tool call with no arguments, some models send the literal JSON string "null" (valid JSON representing a null value). json_decode('null', true) correctly parses it but returns PHP null, which violates the declared `: array` return type and throws a TypeError at the call site. Fix: guard the json_decode result with is_array() and fall back to [] so callers always receive an array regardless of the model's output. Reproducer: any tool with no required parameters called by a model that emits "arguments": "null" instead of "arguments": "{}". --- src/ValueObjects/ToolCall.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ValueObjects/ToolCall.php b/src/ValueObjects/ToolCall.php index 7329979ed..7e7ed1385 100644 --- a/src/ValueObjects/ToolCall.php +++ b/src/ValueObjects/ToolCall.php @@ -36,11 +36,13 @@ public function arguments(): array $arguments = $this->arguments; - return json_decode( + $decoded = json_decode( $arguments, true, flags: JSON_THROW_ON_ERROR ); + + return is_array($decoded) ? $decoded : []; } /** @var array $arguments */