Skip to content

[Bug]: outputSchema cannot describe infinite nested structures using z.lazy() #169

Description

@FireTable

Describe the bug

example code

  const BaseNodeSchema = z.object({
    id: z.string().describe('node id'),
    title: z.string().describe('node title'),
    description: z.string().describe('node description'),
    templateId: z.string().optional().describe('node template id'),
  });

  const NodeSchemaWithNodes: z.ZodType<any> = z.lazy(() =>
    BaseNodeSchema.extend({
      nodes: z.array(NodeSchemaWithNodes).describe('child nodes').optional().nullable(),
    })
  );

  console.warn(
    'validate result zod schema',
    NodeSchemaWithNodes.parse({
      id: '1',
      title: '1',
      description: '1',
      templateId: '1',
      nodes: [
        {
          id: '2',
          title: '2',
          description: '2',
          templateId: '2',
          nodes: [
            {
              id: '3',
              title: '3',
              description: '3',
            },
          ],
        },
      ],
    })
  );

run result

// success validate
validate result zod schema {
  id: "1",
  title: "1",
  description: "1",
  templateId: "1",
  nodes: [
    {
      id: "2",
      title: "2",
      description: "2",
      templateId: "2",
      nodes: [
        {
          id: "3",
          title: "3",
          description: "3",
        }
      ],
    }
  ],
}

// error in aigne core
  aigne:core:error Invoke agent site-map-generator failed with error: BadRequestError: 400 status code (no body)
  aigne:core:error     at new OpenAIError (unknown:1:28)
  aigne:core:error     at new APIError (/Users/FireTable/Code/ArcBlock/pages-kit/node_modules/openai/error.mjs:7:9)
  aigne:core:error     at new BadRequestError (unknown:1:28)
  aigne:core:error     at generate (/Users/FireTable/Code/ArcBlock/pages-kit/node_modules/openai/error.mjs:41:24)
  aigne:core:error     at makeRequest (/Users/FireTable/Code/ArcBlock/pages-kit/node_modules/openai/core.mjs:339:30)
  aigne:core:error     at processTicksAndRejections (native:7:39) {
  aigne:core:error   status: 400,
  aigne:core:error   headers: {
  aigne:core:error     'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000',
  aigne:core:error     'content-encoding': 'gzip',
  aigne:core:error     'content-type': 'application/json; charset=UTF-8',
  aigne:core:error     date: 'Mon, 23 Jun 2025 05:46:16 GMT',
  aigne:core:error     server: 'scaffolding on HTTPServer2',
  aigne:core:error     'server-timing': 'gfet4t7; dur=1197',
  aigne:core:error     'transfer-encoding': 'chunked',
  aigne:core:error     vary: 'Origin, X-Origin, Referer',
  aigne:core:error     'x-content-type-options': 'nosniff',
  aigne:core:error     'x-frame-options': 'SAMEORIGIN',
  aigne:core:error     'x-xss-protection': '0'
  aigne:core:error   },
  aigne:core:error   request_id: undefined,
  aigne:core:error   error: undefined,
  aigne:core:error   code: undefined,
  aigne:core:error   param: undefined,
  aigne:core:error   type: undefined
  aigne:core:error } +2ms

Reproduction Steps

  1. copy example code
  2. run in AIGNE

Observed Behavior

Need to check whether it is supported. If not, please describe it in the document

Expected Behavior

Need to check whether it is supported. If not, please describe it in the document

Possible Solution

No response

Additional Information/Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions