ai icon indicating copy to clipboard operation
ai copied to clipboard

Using grok with tools raises errors

Open defless opened this issue 1 year ago • 6 comments

Description

Using grok with tools causes generic error:

Image

Using grok (grok-3) without tools works well, so as using other provider (openai in my case) works perfectly well with tools.

Am I the only one facing this issue ?

AI SDK Version

"@ai-sdk/openai": "1.3.23",
"@ai-sdk/provider": "1.1.2",
"@ai-sdk/xai": "1.2.18",
"ai": "4.3.16",
"zod": "3.24.2"

defless avatar Jul 22 '25 09:07 defless

could you let me know if you face this issue in v5 beta?

dancer avatar Jul 24 '25 08:07 dancer

i'm trying to migrate to give you an answer.

Did you remove the zodSchema helper on v5 ? I need this for circular dependencies

defless avatar Jul 29 '25 08:07 defless

import { zodSchema } from '@ai-sdk/provider-utils';

dancer avatar Jul 29 '25 09:07 dancer

will update docs thank you for letting me know

dancer avatar Jul 29 '25 09:07 dancer

I have successfully migrated on v5 it works well.

It seems that the problem comes from the use of z.union and .or() from zod in tools schemas. when removing this methods from my schemas it works well with grok.

I have tried using zod 4 but it doesn't work.

defless avatar Jul 29 '25 14:07 defless

Identify issue type

Identified as Bug
Confidence: High

Rationale

The issue reports a reproducible failure in existing xAI/Grok tool handling, specifically with union-based Zod schemas. The incidental v5 documentation question does not supersede the primary runtime bug report.

Evidence

  • grok-3 throws a generic error when tools are enabled, while the same model works without tools and OpenAI works with those tools.
  • The reporter narrowed the failure to tool schemas using Zod z.union or .or(); removing those constructs makes Grok work.
  • Migrating to v5 reportedly resolved the original issue, indicating version-specific broken behavior.

lgrammel avatar Jul 22 '26 14:07 lgrammel