
# Invalid schema for function: schema must be a JSON Schema of 'type: "object"'

## Issue

When using tools, `generateObject`, or `streamObject` with Zod schemas, you encounter this error:

```
Error [AI_APICallError]: Invalid schema for function 'json': schema must be a JSON Schema of 'type: "object"', got 'type: "string"'.
```

or similar variants like:

- `got 'type: "Null"`
- `Invalid schema for function 'calculator'`
- `Invalid schema for function '[your-function-name]'`

This error occurs when using:

- Tool definitions with `tool()` function
- Structured object generation with `generateObject()` or `streamObject()`
- Any AI SDK feature that converts Zod schemas to JSON schemas

## Cause

The AI SDK v4 is not compatible with Zod v4. The schema conversion process that transforms Zod schemas into JSON schemas breaks with Zod v4's internal structure changes.

## Solution

### Option 1: Downgrade to Zod v3 (Recommended)

```bash
npm install zod@3.25.76
```

or with pnpm:

```bash
pnpm add zod@3.25.76
```

### Option 2: Upgrade to AI SDK v5 (Beta)

If you need Zod v4, you can upgrade to the beta version of AI SDK v5:

```bash
# replace openai and react with your provider and framework of choice
npm install ai@beta @ai-sdk/openai@beta @ai-sdk/react@beta
```

Note: v5 is currently in beta and may have breaking changes. See the [v5 migration guide](https://v5.ai-sdk.dev/docs/migration-guides/migration-guide-5-0).

## Additional Resources

- [GitHub Issue #7325](https://github.com/vercel/ai/issues/7325)
- [Structured Object Generation Documentation](/docs/ai-sdk-core/generating-structured-data)
- [Tool Calling Documentation](/docs/ai-sdk-core/tools-and-tool-calling)


## Navigation

- [Azure OpenAI Slow to Stream](/v4/docs/troubleshooting/azure-stream-slow)
- [Client-Side Function Calls Not Invoked](/v4/docs/troubleshooting/client-side-function-calls-not-invoked)
- [Server Actions in Client Components](/v4/docs/troubleshooting/server-actions-in-client-components)
- [useChat/useCompletion stream output contains 0:... instead of text](/v4/docs/troubleshooting/strange-stream-output)
- [Streamable UI Errors](/v4/docs/troubleshooting/streamable-ui-errors)
- [Tool Invocation Missing Result Error](/v4/docs/troubleshooting/tool-invocation-missing-result)
- [Streaming Not Working When Deployed](/v4/docs/troubleshooting/streaming-not-working-when-deployed)
- [Streaming Not Working When Proxied](/v4/docs/troubleshooting/streaming-not-working-when-proxied)
- [Getting Timeouts When Deploying on Vercel](/v4/docs/troubleshooting/timeout-on-vercel)
- [Unclosed Streams](/v4/docs/troubleshooting/unclosed-streams)
- [useChat Failed to Parse Stream](/v4/docs/troubleshooting/use-chat-failed-to-parse-stream)
- [Server Action Plain Objects Error](/v4/docs/troubleshooting/client-stream-error)
- [useChat No Response with maxSteps](/v4/docs/troubleshooting/use-chat-tools-no-response)
- [useChat "An error occurred"](/v4/docs/troubleshooting/use-chat-an-error-occurred)
- [streamText fails silently](/v4/docs/troubleshooting/stream-text-not-working)
- [NaN token counts when using streamText with OpenAI models](/v4/docs/troubleshooting/nan-token-counts-openai-streaming)
- [Model is not assignable to type "LanguageModelV1"](/v4/docs/troubleshooting/model-is-not-assignable-to-type)
- [TypeScript error "Cannot find namespace 'JSX'"](/v4/docs/troubleshooting/typescript-cannot-find-namespace-jsx)
- [React error "Maximum update depth exceeded"](/v4/docs/troubleshooting/react-maximum-update-depth-exceeded)
- [Jest: cannot find module 'ai/rsc'](/v4/docs/troubleshooting/jest-cannot-find-module-ai-rsc)
- [Schema must be JSON Schema of type object error](/v4/docs/troubleshooting/zod-v4-json-schema-type-error)


[Full Sitemap](/sitemap.md)
