I found a crash path in prism-php/prism v0.99.22 when mapping OpenRouter tool calls.
Prism\Prism\Providers\OpenRouter\Maps\ToolCallMap::map() does this:
arguments: json_decode((string) $toolCall['function']['arguments'], true),
If the model returns malformed JSON for function.arguments, json_decode(..., true) returns null. That null is then passed to Prism\Prism\ValueObjects\ToolCall, whose constructor expects array|string for $arguments.
The result is a raw PHP TypeError instead of a handled Prism exception.
Minimal repro
Prism\Prism\Providers\OpenRouter\Maps\ToolCallMap::map([
[
'id' => '1',
'function' => [
'name' => 'demo',
'arguments' => '{',
],
],
]);
This throws:
TypeError: Prism\Prism\ValueObjects\ToolCall::__construct(): Argument #3 ($arguments) must be of type array|string, null given
Expected
Malformed tool-call JSON should be handled gracefully, for example by:
- preserving the raw string, or
- throwing a Prism-level provider/parsing exception with context
Actual
A low-level TypeError escapes the mapping layer.
Because tool arguments are model-generated, malformed JSON is a normal failure mode and should not crash the mapper this way.
I found a crash path in
prism-php/prismv0.99.22when mapping OpenRouter tool calls.Prism\Prism\Providers\OpenRouter\Maps\ToolCallMap::map()does this:If the model returns malformed JSON for
function.arguments,json_decode(..., true)returnsnull. Thatnullis then passed toPrism\Prism\ValueObjects\ToolCall, whose constructor expectsarray|stringfor$arguments.The result is a raw PHP
TypeErrorinstead of a handled Prism exception.Minimal repro
This throws:
Expected
Malformed tool-call JSON should be handled gracefully, for example by:
Actual
A low-level
TypeErrorescapes the mapping layer.Because tool arguments are model-generated, malformed JSON is a normal failure mode and should not crash the mapper this way.