Skip to content

fix: ToolCall::arguments() returns null for valid JSON null string#985

Open
obalaweb wants to merge 1 commit intoprism-php:mainfrom
obalaweb:fix/toolcall-null-arguments
Open

fix: ToolCall::arguments() returns null for valid JSON null string#985
obalaweb wants to merge 1 commit intoprism-php:mainfrom
obalaweb:fix/toolcall-null-arguments

Conversation

@obalaweb
Copy link

Fixes #982
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": "{}".

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": "{}".
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.

ToolCall::arguments() throws TypeError when model returns JSON null string

1 participant