Skip to content

addAdditionalPropertiesToJsonSchema breaks xAI/Grok tool calling: xAI rejects additionalProperties: false #14678

Closed

Description

@dotCipher

Description

The addAdditionalPropertiesToJsonSchema function in @ai-sdk/provider-utils forcibly adds additionalProperties: false to all object schemas during tool serialization. This breaks tool calling for xAI/Grok models because xAI's validator explicitly rejects additionalProperties: false in tool schemas.

xAI's structured output docs state:

  • additionalProperties defaults to false already
  • schemas with boolean property schemas like false are rejected

So the AI SDK is adding something that xAI explicitly rejects, even though xAI's default behavior is already what the AI SDK is trying to enforce.

Root Cause

In @ai-sdk/provider-utils, the addAdditionalPropertiesToJsonSchema function unconditionally sets additionalProperties: false on all object-type schemas:

function addAdditionalPropertiesToJsonSchema(jsonSchema2) {
  if (jsonSchema2.type === "object" || ...) {
    jsonSchema2.additionalProperties = false;  // <-- This breaks xAI
    ...
  }
}

This function is called during tool schema serialization for all providers, with no provider-specific opt-out.

Impact

Any application using the AI SDK with xAI/Grok models and tool calling will fail with:

[xAI] Invalid request content: Schema validation failed: [standard_violation] /properties/properties/additionalProperties: property schema 'false' is not supported

This affects:

  • Direct xAI provider usage (@ai-sdk/xai)
  • OpenRouter xAI models (@openrouter/ai-sdk-provider)
  • Any other OpenAI-compatible provider routing to xAI

Investigation

We spent significant time debugging this in OpenCode and confirmed:

  1. The AI SDK re-adds additionalProperties: false AFTER any application-level sanitization
  2. The binary bundles all dependencies at build time, so runtime interceptors don't work
  3. The conflict exists at the AI SDK level, not the application level

Full investigation: anomalyco/opencode#23704

Suggested Fix

Add provider-specific schema serialization options to the AI SDK, such as:

  1. Provider-level opt-out: Allow providers to disable addAdditionalPropertiesToJsonSchema for specific models
  2. xAI-specific handling: Skip adding additionalProperties: false when targeting xAI models
  3. Configuration option: Add a strictToolSchemas or similar option to provider constructors

Since xAI defaults to additionalProperties: false anyway, skipping it for xAI targets preserves intended strictness while avoiding the validator rejection.

Workaround (for now)

Applications can disable tool calling for xAI models via config:

{
  "provider": {
    "openrouter": {
      "models": {
        "x-ai/grok-4.1-fast": {
          "tool_call": false
        }
      }
    }
  }
}

But this is not a real solution — it just disables tools entirely for xAI models.

Related

Activity

  1. added
    ai/providerrelated to a provider package. Must be assigned together with at least one `provider/*` label
    bugSomething isn't working as documented
    provider/xaiIssues related to the @ai-sdk/xai provider
    on Apr 21, 2026
  2. added a commit that references this issue on Apr 30, 2026
    de9cd4e
  3. aayush-kapoor commented on May 7, 2026

    @aayush-kapoor
    Collaborator

    do you have a reproduction example for this? would be easy to verify fix

  4. aayush-kapoor commented on May 14, 2026

    @aayush-kapoor
    Collaborator

    attached a repro script in the attached PR

  5. github-actions commented on May 14, 2026

    @github-actions
    Contributor

    🚀 Published in:

    Package Version
    ai 7.0.0-canary.138
    @ai-sdk/angular 3.0.0-canary.138
    @ai-sdk/cohere 4.0.0-canary.44
    @ai-sdk/devtools 1.0.0-canary.24
    @ai-sdk/gateway 4.0.0-canary.81
    @ai-sdk/langchain 3.0.0-canary.138
    @ai-sdk/llamaindex 3.0.0-canary.138
    @ai-sdk/otel 1.0.0-canary.84
    @ai-sdk/react 4.0.0-canary.139
    @ai-sdk/rsc 3.0.0-canary.139
    @ai-sdk/svelte 5.0.0-canary.138
    @ai-sdk/vue 4.0.0-canary.138
    @ai-sdk/workflow 1.0.0-canary.55
    @ai-sdk/xai 4.0.0-canary.62
  6. lgrammel commented on Jul 22, 2026

    @lgrammel
    Collaborator

    Identify issue type

    Identified as Bug
    Confidence: High

    Rationale

    This is a concrete interoperability failure in existing xAI/Grok tool-calling behavior, not merely a request for a new option. The suggested configuration and provider-specific handling are proposed fixes for that failure.

    Evidence

    • Tool serialization forcibly adds additionalProperties: false to object schemas.
    • xAI/Grok rejects the generated schema, causing tool-calling requests to fail with a schema validation error.
    • A maintainer requested a reproduction and later attached one to the associated fix PR; a canary release was subsequently published.
  7. added theissue type on Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions