Skip to content

fix(xai): cast empty tool properties to object in xAI ToolMap#977

Open
Cbrad24 wants to merge 1 commit intoprism-php:mainfrom
Cbrad24:fix/xai-toolmap-empty-properties
Open

fix(xai): cast empty tool properties to object in xAI ToolMap#977
Cbrad24 wants to merge 1 commit intoprism-php:mainfrom
Cbrad24:fix/xai-toolmap-empty-properties

Conversation

@Cbrad24
Copy link
Copy Markdown

@Cbrad24 Cbrad24 commented Mar 24, 2026

Problem

When a tool has no parameters/inputs, the xAI provider sends
"properties": [] (JSON array)
instead of
"properties": {} (JSON object)
in the tool definition.

xAI's API rejects this with a 400 error.

This is the same class of PHP empty-array serialization issue fixed in #896 for MessageMap, but in ToolMap (tool definitions rather than tool call arguments).

Before

{
    "type": "function",
    "function": {
        "name": "list_users",
        "description": "List all users",
        "parameters": {
            "type": "object",
            "properties": [],  // Causes 400 error
            "required": []
        }
    }
}

After

{
    "type": "function",
    "function": {
        "name": "list_users",
        "description": "List all users",
        "parameters": {
            "type": "object",
            "properties": {},  // Works
            "required": []
        }
    }
}

Fix

Cast $tool->parametersAsArray() to (object) so empty arrays serialize as {}.
When tool parameters exist, the cast produces an identical JSON object, no behavioral changes.

@Cbrad24 Cbrad24 changed the title fix(xAI): cast empty tool properties to object in xAI ToolMap fix(xai): cast empty tool properties to object in xAI ToolMap Mar 24, 2026
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.

1 participant