{"record":{"id":"c9be66b2b569319b","repo":"mastra-ai/mastra","slug":"async-validation-is-not-supported","errorCode":null,"errorMessage":"Async validation is not supported","messagePattern":"Async validation is not supported","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/schema-compat/src/provider-compats/anthropic.ts","lineNumber":125,"sourceCode":"        .any()\n        .refine(v => v === null, { message: 'must be null' })\n        .describe(value.description || 'must be null');\n    } else if (isIntersection(z)(value)) {\n      return this.defaultZodIntersectionHandler(value);\n    }\n\n    return this.defaultUnsupportedZodTypeHandler(value);\n  }\n\n  processToAISDKSchema(zodSchema: ZodTypeV3 | ZodTypeV4) {\n    const compat = this.processToCompatSchema(zodSchema);\n    const transformedJsonSchema = standardSchemaToJSONSchema(compat);\n\n    return jsonSchema(transformedJsonSchema, {\n      validate: (value: unknown) => {\n        const result = compat['~standard'].validate(value);\n        if (result instanceof Promise) {\n          throw new Error('Async validation is not supported');\n        }\n        return 'issues' in result && result.issues\n          ? { success: false as const, error: new Error(result.issues.map(i => i.message).join(', ')) }\n          : { success: true as const, value: (result as { value: unknown }).value };\n      },\n    });\n  }\n\n  public processToCompatSchema<T>(schema: PublicSchema<T>): StandardSchemaWithJSON<T> {\n    const originalStandardSchema = toStandardSchema(schema);\n    const validationStandardSchema = this.#getCompatValidationStandardSchema(schema, originalStandardSchema);\n\n    return {\n      '~standard': {\n        version: 1,\n        vendor: 'mastra',\n        validate: (value: unknown) => {\n          const transformedJsonSchema = this.processToJSONSchema(schema, 'input') as Record<string, unknown>;","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/schema-compat/src/provider-compats/anthropic.ts#L107-L143","documentation":"When converting a Standard Schema-compatible schema to an AI SDK schema, processToAISDKSchema installs a synchronous `validate` callback. Standard Schema validation may be async (returns a Promise); the AI SDK's jsonSchema() validate hook is synchronous, so the library throws rather than silently dropping validation.","triggerScenarios":"Using a schema whose `~standard.validate` returns a Promise — e.g. a Zod schema wrapped through an async-transforming adapter, a custom Standard Schema implementation with async refinements/transformations, or schemas using `z.string().refine(async ...)`.","commonSituations":"Migrating to the AI SDK path while keeping schemas with async refinements; third-party schema libraries that only implement async validation; combining structured output with schema transforms that are inherently async.","solutions":["Remove async refinements/transforms from the schema so validation is synchronous.","Pre-validate the value yourself before calling the AI SDK, using the schema's async validate, and pass an already-valid value.","Use a synchronous-only schema library or version for the structured-output path.","Wrap a sync subset schema for the model and enforce async rules in application code after the response."],"exampleFix":"// before\nconst schema = z.object({ id: z.string().refine(async id => checkExists(id)) });\n// after\nconst schema = z.object({ id: z.string() });\n// check existence asynchronously in your own code before/after the model call","handlingStrategy":"validation","validationCode":"const probe = schema['~standard'].validate({});\nif (probe instanceof Promise) {\n  throw new TypeError('Schema uses async validation; provide a synchronous schema for AI SDK structured output');\n}","typeGuard":"function isSyncStandardSchema(s: { '~standard': { validate: (v: unknown) => unknown } }): boolean {\n  return !(s['~standard'].validate({}) instanceof Promise);\n}","tryCatchPattern":"try {\n  converted = processToAISDKSchema(schema);\n} catch (e) {\n  if ((e as Error).message === 'Async validation is not supported') {\n    converted = processToAISDKSchema(stripAsyncRefinements(schema));\n  } else throw e;\n}","preventionTips":["Avoid .refine(async)/.transform(async) in schemas bound to model structured output.","Enforce async invariants in application code before/after model calls.","Add a sync-check on schemas in a startup unit test."],"tags":["schema","async","ai-sdk"],"backgroundTag":"async-validation-unsupported","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}