Bug Report
Summary
ToolCall::arguments() declares : array as its return type but can return
null when the model emits the literal JSON string "null" in the
function.arguments field, causing a TypeError at the call site.
Steps to Reproduce
- Register any tool with no required parameters
- Use a Groq provider with a Llama model (e.g.
llama-3.3-70b-versatile)
- Ask the model something that triggers the no-arg tool call
- Prism attempts to execute the tool and throws
Error
TypeError: Prism\Prism\ValueObjects\ToolCall::arguments(): Return value
must be of type array, null returned
#0 vendor/prism-php/prism/src/Concerns/CallsTools.php:137
#1 vendor/prism-php/prism/src/ValueObjects/ToolCall.php:42
Root Cause
Some models emit "arguments": "null" (valid JSON representing a null value)
instead of "arguments": "{}" for no-arg tool calls.
json_decode('null', true) is valid and returns PHP null, which violates
the : array return type.
Expected Behaviour
arguments() always returns an array. JSON null should be treated as
"no arguments" and return [].
Suggested Fix
$decoded = json_decode($arguments, true, flags: JSON_THROW_ON_ERROR);
return is_array($decoded) ? $decoded : [];
Environment
- Provider: Groq
- Model: llama-3.3-70b-versatile
- Prism: v0.99.22
---
Bug Report
Summary
ToolCall::arguments()declares: arrayas its return type but can returnnullwhen the model emits the literal JSON string"null"in thefunction.argumentsfield, causing aTypeErrorat the call site.Steps to Reproduce
llama-3.3-70b-versatile)Error
Root Cause
Some models emit
"arguments": "null"(valid JSON representing a null value)instead of
"arguments": "{}"for no-arg tool calls.json_decode('null', true)is valid and returns PHPnull, which violatesthe
: arrayreturn type.Expected Behaviour
arguments()always returns an array. JSONnullshould be treated as"no arguments" and return
[].Suggested Fix