{"record":{"id":"a50fb6d7f9f599c9","repo":"mastra-ai/mastra","slug":"unsupported-schema-type-typeof-schema","errorCode":null,"errorMessage":"Unsupported schema type: ${typeof schema}","messagePattern":"Unsupported schema type: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/schema-compat/src/standard-schema/standard-schema.ts","lineNumber":174,"sourceCode":"    });\n  }\n\n  // Check for Zod v3 schemas (need wrapping to add JSON Schema support)\n  // Important: Must use isZodV3() not instanceof z3.ZodType because\n  // 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","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/schema-compat/src/standard-schema/standard-schema.ts#L156-L192","documentation":"toStandardSchema() in packages/schema-compat converts any supported schema form (Zod v3/v4, AI SDK Schema, StandardSchemaWithJSON, JSON Schema object) into a Standard Schema. Before treating the input as a plain JSON Schema object it asserts it is a non-null object or function. If the value is null, undefined, a primitive (string/number/boolean), or any other non-object type, it throws this error because there is no conversion path for it.","triggerScenarios":"Calling toStandardSchema (directly or via wrapped/result/rewrapped) with null, undefined, a string like 'zod-schema', a number, or a boolean instead of an actual schema object.","commonSituations":"Schema loaded from a lazily-initialized config that is still undefined at call time; a typo'd import yielding undefined; passing the *name* of a schema instead of the schema object; JSON.parse failure upstream returning a primitive; destructuring a tool/agent definition where the schema field is missing.","solutions":["Ensure the schema variable is actually defined and imported before calling the API (check for undefined/missing imports).","Pass the schema object itself, not a schema name, string, or JSON string.","If the schema is loaded asynchronously/lazily, await or resolve it before registering the tool/agent.","Wrap the call in a check: if (schema == null || typeof schema !== 'object') throw a descriptive app-level error before reaching Mastra."],"exampleFix":"// before\nnew Tool({ parameters: process.env.TOOL_SCHEMA as any }) // undefined or a JSON string\n// after\nimport { z } from 'zod';\nnew Tool({ parameters: z.object({ query: z.string() }) })","handlingStrategy":"type-guard","validationCode":"function assertValidSchemaInput(s: unknown): void {\n  if (s === null || (typeof s !== 'object' && typeof s !== 'function')) {\n    throw new TypeError(`Expected a schema object, got: ${s === null ? 'null' : typeof s}`);\n  }\n}","typeGuard":"const isSchemaObject = (s: unknown): s is Record<string, unknown> =>\n  typeof s === 'object' && s !== null;","tryCatchPattern":"try {\n  return toStandardSchema(schema);\n} catch (e) {\n  if (e.message.startsWith('Unsupported schema type')) {\n    throw new Error(`Schema must be a Zod/JSON Schema/StandardSchema object, got ${typeof schema}`);\n  }\n  throw e;\n}","preventionTips":["Check that schema imports resolve (no undefined) before registering tools/agents.","Never pass schema names or JSON strings where schema objects are expected.","Resolve lazy/async schema loaders before API calls."],"tags":["schema","invalid-input","typeerror"],"backgroundTag":"unsupported-schema-type","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}