{"record":{"id":"fed4e4b187f292b6","repo":"mastra-ai/mastra","slug":"standardschemawithjson-is-not-supported-for-applyc","errorCode":null,"errorMessage":"StandardSchemaWithJSON is not supported for applyCompatLayer and aiSdkSchema mode","messagePattern":"StandardSchemaWithJSON is not supported for applyCompatLayer and aiSdkSchema mode","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/schema-compat/src/utils.ts","lineNumber":212,"sourceCode":"    const standardSchema = toStandardSchema(schema);\n\n    for (const compat of compatLayers) {\n      if (compat.shouldApply()) {\n        const compatSchema = compat.processToCompatSchema(standardSchema);\n\n        return standardSchemaToJSONSchema(compatSchema);\n      }\n    }\n\n    return standardSchemaToJSONSchema(standardSchema);\n  } else {\n    let zodSchema: ZodSchema;\n\n    if (isZodType(schema)) {\n      zodSchema = schema;\n    } else {\n      if (isStandardSchemaWithJSON(schema)) {\n        throw new Error('StandardSchemaWithJSON is not supported for applyCompatLayer and aiSdkSchema mode');\n      }\n\n      // Convert non-zod schema to Zod\n      // After ruling out ZodType and StandardSchemaWithJSON above, remaining PublicSchema\n      // types are Schema (v4/v5/v6) and JSONSchema7, all handled by convertSchemaToZod\n      zodSchema = convertSchemaToZod(schema as Schema | JSONSchema7);\n    }\n\n    for (const compat of compatLayers) {\n      if (compat.shouldApply()) {\n        return compat.processToAISDKSchema(zodSchema);\n      }\n    }\n\n    return convertZodSchemaToAISDKSchema(zodSchema);\n  }\n}\n","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/schema-compat/src/utils.ts#L194-L230","documentation":"applyCompatLayer() with aiSdkSchema mode normalizes a schema into Zod (applying provider compatibility fixes, e.g. for Gemini) and then converts back to an AI SDK Schema. Its conversion path only understands ZodType instances and Schema/JSONSchema7 objects; StandardSchemaWithJSON (Standard Schema objects that carry their own JSON representation) cannot round-trip through the Zod-based compat layer, so it is explicitly rejected with this error.","triggerScenarios":"Calling applyCompatLayer({ schema, mode: 'aiSdkSchema' }) — directly or via applyGeminiSchemaCompatToTools/_applySchemaCompat/jsonSchema/build — with a StandardSchemaWithJSON schema (e.g. a Standard Schema from Zod v4/Valibot/ArkType) instead of a ZodType or JSON Schema object.","commonSituations":"Using Gemini models with tools whose parameters are Standard Schema objects from Zod v4 or another Standard-Schema-compliant library; mixing schema styles across tools where some are zod v3 and some are standard-schema objects.","solutions":["Convert the StandardSchemaWithJSON to a plain JSON Schema (use its jsonSchema/~standard.jsonSchema.output) and pass the JSON Schema instead.","Pass a native Zod (v3 or v4) schema to applyCompatLayer, which it can handle directly.","Use the standard-schema (non-aiSdkSchema) path of toStandardSchema instead, which supports StandardSchemaWithJSON.","Downgrade/recreate the schema with Zod v3 if the Gemini compat path requires it."],"exampleFix":"// before\napplyCompatLayer({ schema: myStandardSchemaWithJSON, mode: 'aiSdkSchema' })\n// after\napplyCompatLayer({ schema: z.object({ query: z.string() }), mode: 'aiSdkSchema' })","handlingStrategy":"type-guard","validationCode":"if (schema && typeof schema === 'object' && '~standard' in schema && !('_def' in schema) && !('_zod' in schema)) {\n  // StandardSchemaWithJSON — convert to JSON Schema first before applyCompatLayer aiSdkSchema mode\n  schema = extractJsonSchema(schema);\n}","typeGuard":"const isZodSchema = (s: unknown): boolean =>\n  typeof s === 'object' && s !== null && ('_def' in s || '_zod' in s);","tryCatchPattern":"let safeSchema = schema;\nif (isStandardSchemaWithJSON(schema)) {\n  safeSchema = schema.jsonSchema ?? toStandardSchemaJsonSchema(schema);\n}\nconst result = applyCompatLayer({ schema: safeSchema, mode: 'aiSdkSchema' });","preventionTips":["Use Zod schemas with the Gemini compat layer path.","Convert StandardSchemaWithJSON objects to plain JSON Schema before aiSdkSchema mode.","Keep tool parameter schema styles uniform across a project."],"tags":["schema","standard-schema","compat","gemini"],"backgroundTag":"unsupported-schema-type","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}