{"record":{"id":"7f9999d15360f8ed","repo":"ComposioHQ/composio","slug":"experimental-subagent-schema-must-be-a-zod-schem","errorCode":null,"errorMessage":"experimental_subAgent() schema must be a Zod schema or JSON Schema object.","messagePattern":"experimental_subAgent\\(\\) schema must be a Zod schema or JSON Schema object\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ts/packages/cli/src/services/run-helpers-runtime.ts","lineNumber":380,"sourceCode":"    );\n  }\n  const inputSchema = options.schema ?? options.jsonSchema;\n  let structuredSchema: Record<string, unknown> | undefined;\n  let zodSchema: z.ZodType | undefined;\n  if (inputSchema !== undefined) {\n    if (inputSchema instanceof z.ZodType) {\n      if (typeof z.toJSONSchema !== 'function') {\n        throw new Error(\n          'experimental_subAgent() requires Zod 4 with z.toJSONSchema() when using options.schema.'\n        );\n      }\n      zodSchema = inputSchema;\n      const generatedSchema = z.toJSONSchema(inputSchema);\n      structuredSchema = Schema.decodeUnknownSync(JsonObject)(generatedSchema);\n    } else if (Predicate.isRecord(inputSchema)) {\n      structuredSchema = inputSchema;\n    } else {\n      throw new Error('experimental_subAgent() schema must be a Zod schema or JSON Schema object.');\n    }\n  }\n  return {\n    ...(requestedTarget === undefined ? {} : { target: requestedTarget }),\n    ...(typeof options.model === 'string' ? { model: options.model } : {}),\n    ...(options.schema === undefined ? {} : { schema: options.schema }),\n    ...(options.jsonSchema === undefined ? {} : { jsonSchema: options.jsonSchema }),\n    ...(structuredSchema === undefined ? {} : { structuredSchema }),\n    ...(zodSchema === undefined ? {} : { zodSchema }),\n  };\n};\n\nconst normalizeProxyToolkit = (toolkit: string) => {\n  if (typeof toolkit !== 'string' || toolkit.trim().length === 0) {\n    throw new Error('proxy() requires a non-empty toolkit string.');\n  }\n  return toolkit.trim();\n};","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/ComposioHQ/composio/blob/64b1b85502b1beeb2379e6c9e8bf1104504fa637/ts/packages/cli/src/services/run-helpers-runtime.ts#L362-L398","documentation":"The schema option for experimental_subAgent() accepts only two shapes: a Zod schema instance (inputSchema instanceof z.ZodType) or a plain record (JSON Schema object). Anything else — a number, function, class instance, array — triggers this error in normalizeInvokeAgentOptions.","triggerScenarios":"Passing options.schema as a JSON string, an array, a Yup/Valibot/Effect schema, or a Zod schema from a different duplicated zod package instance (instanceof check fails across copies).","commonSituations":"JSON.stringify'd schema stored in a variable, using another validation library, or two copies of zod in node_modules making the instanceof check fail even though the object is a Zod schema.","solutions":["Pass a plain JSON Schema object via options.jsonSchema (or options.schema as a record)","If using Zod, ensure only one zod copy is installed (pnpm dedupe / pnpm why zod) so instanceof works","Do not pass serialized schema strings; parse them to objects first"],"exampleFix":"// before\nawait experimental_subAgent('p', { schema: '{\"type\":\"object\"}' });\n// after\nawait experimental_subAgent('p', { jsonSchema: JSON.parse(schemaString) });","handlingStrategy":"type-guard","validationCode":"const isPlainObject = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);\nif (opts.schema !== undefined && !(opts.schema instanceof z.ZodType) && !isPlainObject(opts.schema)) throw new TypeError('schema must be Zod or JSON Schema object');","typeGuard":"const isZodOrJsonSchema = (v: unknown): v is z.ZodType | Record<string, unknown> => v instanceof z.ZodType || (Predicate.isRecord?.(v) ?? (typeof v === 'object' && v !== null && !Array.isArray(v)));","tryCatchPattern":null,"preventionTips":["Parse JSON strings to objects before passing","Never mix validation libraries into options.schema","Dedupe zod so instanceof checks hold"],"tags":["schema","validation","zod","subagent"],"backgroundTag":"invalid-schema-type","analyzedSha":"64b1b85502b1beeb2379e6c9e8bf1104504fa637","analyzedAt":"2026-08-28T15:39:33.623Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}