Skip to content

Conversation

@lukasdotcom
Copy link
Member

@lukasdotcom lukasdotcom commented Jul 25, 2025

Gemini complains about a list being passed as the arguments instead of an object. It has an unintended side effect that every single empty object/array will be turned into an empty object when json encoded as a function argument.

'function' => $toolCall,
];
$formattedToolCall['function']['arguments'] = json_encode($toolCall['args']);
$formattedToolCall['function']['arguments'] = json_encode($toolCall['args'], JSON_FORCE_OBJECT);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about inspecting the output of json_encode and then converting it to an object?
It's only an issue when it's empty, right?

$out = json_encode($toolCall['args']) ?: '[]';
if ($out === '[]') {
    $out = '{}';
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a much better and simple idea. Technically it might still be an issue if one of the parameters in an argument needs to be an empty object, but I don't think that is common and might not even be possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A full blown inspection can be done as well looping over all the properties and converting every empty key-val array [] to an empty object (object) [] but if that case is not possible, this is good enough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That also isn't always wanted because I think it is possible to pass an empty array as an argument like below.

{"features":[]}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right

@lukasdotcom lukasdotcom force-pushed the fix/empty-args branch 2 times, most recently from 0324fc6 to 499aca1 Compare August 4, 2025 11:34
@lukasdotcom lukasdotcom marked this pull request as ready for review August 4, 2025 11:34
@lukasdotcom lukasdotcom merged commit f0dcbe2 into main Aug 4, 2025
29 checks passed
@lukasdotcom lukasdotcom deleted the fix/empty-args branch August 4, 2025 14:15
@kyteinsky kyteinsky mentioned this pull request Oct 6, 2025
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.

3 participants