{"record":{"id":"a8484d7fdb247069","repo":"mastra-ai/mastra","slug":"unsupported-schema-type-function-schema-librarie","errorCode":null,"errorMessage":"Unsupported schema type: function (schema libraries should implement StandardSchemaWithJSON)","messagePattern":"Unsupported schema type: function \\(schema libraries should implement StandardSchemaWithJSON\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/schema-compat/src/standard-schema/standard-schema.ts","lineNumber":179,"sourceCode":"  // Zod v4 schemas are also instanceof z3.ZodType due to prototype compatibility\n  if (isZodV3(schema)) {\n    return toStandardSchemaZodV3(schema as ZodType);\n  }\n\n  // Check for AI SDK Schema objects (Vercel's jsonSchema wrapper)\n  if (isVercelSchema(schema)) {\n    return toStandardSchemaAiSdk(schema as Schema<T>);\n  }\n\n  // At this point, assume it's a plain JSON Schema object\n  // JSON Schema objects are plain objects with properties like 'type', 'properties', etc.\n  if (schema === null || (typeof schema !== 'object' && typeof schema !== 'function')) {\n    throw new Error(`Unsupported schema type: ${typeof schema}`);\n  }\n\n  // If it's a function that's not StandardSchemaWithJSON, it's not supported\n  if (typeof schema === 'function') {\n    throw new Error(`Unsupported schema type: function (schema libraries should implement StandardSchemaWithJSON)`);\n  }\n\n  return toStandardSchemaJsonSchema(schema as JSONSchema7);\n}\n\n/**\n * Type guard to check if a value implements the StandardSchemaV1 interface.\n *\n * @param value - The value to check\n * @returns True if the value implements StandardSchemaV1\n *\n * @example\n * ```typescript\n * import { isStandardSchema } from '@mastra/schema-compat';\n *\n * if (isStandardSchema(someValue)) {\n *   const result = someValue['~standard'].validate(input);\n * }","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/schema-compat/src/standard-schema/standard-schema.ts#L161-L197","documentation":"After toStandardSchema() rules out null/primitives, it checks functions: a bare function is not a recognized schema representation. Only StandardSchemaWithJSON functions (which expose a '~standard' and 'jsonSchema' interface) are accepted. A plain function such as a bare zod schema factory, a class constructor, or a schema-producing callback is rejected with this message telling library authors to implement StandardSchemaWithJSON.","triggerScenarios":"Passing a plain function (e.g. () => z.object(...), a class, or a legacy schema-library constructor) to toStandardSchema via wrapped/result/rewrapped, when the function does not implement StandardSchemaWithJSON.","commonSituations":"Passing a Zod v2/legacy schema class; passing a function from an older schema library that never implemented the Standard Schema spec; accidentally passing the schema factory instead of calling it (z.object({...}) vs z.object); custom schema wrappers that are callables.","solutions":["Call the factory function to get the schema instance: () => z.object({...}) becomes z.object({...}).","If using a schema library, upgrade to a version implementing the Standard Schema spec (Zod 3.24+/v4, Valibot, ArkType).","Wrap the function's returned schema in a StandardSchemaWithJSON adapter before passing it.","Convert the schema to plain JSON Schema (JSONSchema7 object) and pass that instead."],"exampleFix":"// before\nagent({ schema: MyZodObjectSchemaFactory }) // function passed\n// after\nagent({ schema: MyZodObjectSchemaFactory() }) // call it to get the zod schema instance","handlingStrategy":"type-guard","validationCode":"if (typeof schema === 'function' && !('~standard' in (schema as any))) {\n  throw new TypeError('Function schemas must implement StandardSchemaWithJSON; call the factory or pass its result.');\n}","typeGuard":"const isStandardSchemaWithJSONFn = (s: unknown): s is { '~standard': unknown; jsonSchema: unknown } =>\n  typeof s === 'function' && '~standard' in s;","tryCatchPattern":"let normalized;\ntry {\n  normalized = toStandardSchema(schema);\n} catch (e) {\n  if (/Unsupported schema type: function/.test(e.message)) {\n    normalized = toStandardSchema((schema as () => unknown)()); // call factory\n  } else throw e;\n}","preventionTips":["Always invoke schema factory functions before passing them.","Use schema libraries implementing the Standard Schema spec (Zod 3.24+/v4, Valibot, ArkType).","Prefer schema instances over classes/functions at API boundaries."],"tags":["schema","standard-schema","invalid-input"],"backgroundTag":"unsupported-schema-type","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}