Skip to content

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

Open
Cbrad24 wants to merge 1 commit into
prism-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 into
prism-php:mainfrom
Cbrad24:fix/xai-toolmap-empty-properties

Conversation

@Cbrad24

@Cbrad24 Cbrad24 commented Mar 24, 2026

Copy link
Copy Markdown

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
wishborn added a commit to Particle-Academy/prism that referenced this pull request Jul 6, 2026
wishborn added a commit to Particle-Academy/prism that referenced this pull request Jul 6, 2026
Corrects prism-php#977 (xAI) to the established convention used by the
Anthropic and OpenRouter maps ($properties === [] ? new \stdClass : $properties)
so non-empty parameters stay arrays, and applies the same fix to Groq and Z,
which had the identical latent bug (empty properties serialized as [] instead
of {}). DeepSeek and OpenAI already omit the parameters block when a tool has
none. Adds regression tests for all three maps. Refs prism-php#1007.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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