Skip to content

Not able to use Zod object as outputType w/ Deno + Supabase Edge Functions #408

@mulder3010

Description

@mulder3010

Describe the bug

I am triggering a supabase edge function using Agent SDK version "@openai/agents": "^0.0.17".
But, I am not able to use Zod object as outputType.
I receive the following error when creating an agent with a Zod object as outputtype:
Error] Unexpected error: 400 Missing required parameter: 'text.format.type'.

Debug information

I am not able to create and run an agent using outputtype object.
Even from: examples/docs/agents/agentWithAodOutputType.ts

I checked the underlying function verifying the object, it retrieves a false value for isZodObject().

For debugging I looked at
https://github.com/openai/openai-agents-js/blob/main/packages/agents-core/src/agent.ts

and at:
packages/agents-core/src/utils/typeGuards.ts

const CalendarEvent = z.object({
      name: z.string(),
      date: z.string(),
      participants: z.array(z.string()),
    });

function isZodObject(input: unknown): input is ZodObject<any> {
  return (
    typeof input === 'object' &&
    input !== null &&
    '_def' in input &&
    typeof input._def === 'object' &&
    input._def !== null &&
    'typeName' in input._def &&
    input._def.typeName === 'ZodObject'
  );
}

  if (isZodObject(CalendarEvent)) {
      console.log("Expected output schema:", CalendarEvent);
    } else {
      console.log("Invalid output schema for CalendarEvent");
    }

This gave me a true value:

function isZodObject(input: unknown): input is ZodObject<any> {
      return (
        // check #1: instanceof
        input instanceof ZodObject ||
        // check #2: structural fallback
        (typeof input === "object" &&
          input !== null &&
          "_def" in input &&
          typeof (input as any)._def === "object" &&
          (input as any)._def !== null &&
          (input as any)._def.typeName === ZodFirstPartyTypeKind.ZodObject)
      );
    }

Repro steps

Original code:

const extractor = new Agent({
  name: "Calendar extractor",
  instructions: "Extract calendar events from the supplied text.",
  outputType: z.object({
    name: z.string(),
    date: z.string(),
    participants: z.array(z.string()),
  }),
});

  const result = await run(extractor, [
      {
        type: "message",
        role: "user",
        content: "Tomorrow at 3 pm 30/08/2025, meeting with John and Jane",
      },
    ]);

Expected behavior

I would expect a result from the run that equals the inputted output type as a JSON.

What would be your suggestion to get a correct zod output structure?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions