Skip to content

TypeError: Cannot read properties of undefined (reading '_zod') with Zod 3.25.76 #196

@Batsirai

Description

@Batsirai

Bug Description

When using @convex-dev/agent@0.3.2 with zod@3.25.76, any agent with tools fails to run with:

TypeError: Cannot read properties of undefined (reading '_zod')

Environment

  • @convex-dev/agent: 0.3.2
  • zod: 3.25.76
  • ai: 5.0.110
  • @ai-sdk/provider-utils: 3.0.18
  • convex: 1.29.3

Reproduction

  1. Create an agent with any tool using createTool:
import { Agent, createTool } from "@convex-dev/agent";
import { z } from "zod";

const myTool = createTool({
  description: "Test tool",
  args: z.object({
    input: z.string(),
  }),
  handler: async (ctx, args) => {
    return "result";
  },
});

export const myAgent = new Agent(components.agent, {
  name: "Test Agent",
  tools: { myTool },
  // ...
});
  1. Try to run the agent
  2. Error occurs during tool schema validation

Root Cause

The @ai-sdk/provider-utils package checks for Zod 4 schemas using:

function isZod4Schema(zodSchema) {
  return "_zod" in zodSchema;
}

However, the zodSchema parameter is undefined when it reaches this check, causing the error.

Expected Behavior

Agents with tools should work with Zod 3.25.76, which is listed as a supported peer dependency in @ai-sdk/provider-utils.

Workaround Attempted

  • Tried zod@3.22.4 - bundling fails (missing zod/v4 export)
  • Tried zod@3.23.8 - same _zod error
  • Tried @convex-dev/agent@0.5.0-alpha.1 - same error
  • Tried zod/v3 import - Convex bundler doesn't resolve it correctly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions