mastra-ai/mastra · error

Your schema is async, which is not supported. Please use a s

Error message

Your schema is async, which is not supported. Please use a sync schema.

What it means

When `validateInputs` is enabled and a `requestContextSchema` is set, `_validateRequestContext` validates request-context values synchronously. Because Mastra must validate synchronously here, an async schema (one whose `~standard.validate` returns a Promise) is rejected outright with this error.

Source

Thrown at packages/core/src/workflows/workflow.ts:3495

    return this.#validateSchema(this.inputSchema, inputData, 'input data');
  }

  protected async _validateInitialState(initialState?: TState) {
    if (!this.validateInputs || !this.stateSchema) {
      return initialState;
    }

    return this.#validateSchema(this.stateSchema, initialState, 'initial data');
  }

  protected async _validateRequestContext(requestContext?: RequestContext) {
    if (this.validateInputs && this.requestContextSchema) {
      const contextValues = getRequestContextInputValues(requestContext);
      const validation = this.requestContextSchema['~standard'].validate(contextValues);

      if (validation instanceof Promise) {
        throw new Error('Your schema is async, which is not supported. Please use a sync schema.');
      }

      if (!('value' in validation)) {
        const errors = validation.issues;
        throw new Error(
          `Request context validation failed for workflow '${this.workflowId}': \n` +
            errors
              .map(e => {
                const pathStr = e.path?.map(p => (typeof p === 'object' ? p.key : p)).join('.');
                return `- ${pathStr}: ${e.message}`;
              })
              .join('\n'),
        );
      }
    }
  }

  protected async _validateResumeData<TResume>(resumeData: TResume, suspendedStep?: StepWithComponent) {

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Make requestContextSchema fully synchronous: remove async refine/transform and async superRefine.
  2. Perform async lookups outside the schema — validate in your own code and pass already-resolved values via requestContext.
  3. If the async check is required, drop `validateInputs: true` or the requestContextSchema and validate manually before starting the run.
  4. Use sync-only schema features (plain shapes, sync refine) for request contexts.

Example fix

// before
requestContextSchema: z.object({ tenantId: z.string().refine(async id => exists(id)) }),
// after
requestContextSchema: z.object({ tenantId: z.string() }),
// do the async existence check before createRun and pass validated values
Defensive patterns

Strategy: validation

Validate before calling

function assertSyncSchema(schema: { '~standard': { validate: (v: unknown) => unknown } }) {
  const probe = schema['~standard'].validate({});
  if (probe instanceof Promise) throw new Error('requestContextSchema must be synchronous');
}

Try / catch

try {
  await workflow.createRun({ requestContext });
} catch (e) {
  if (e instanceof Error && e.message.includes('Your schema is async')) {
    // rebuild requestContextSchema without async refinements
  } else throw e;
}

Prevention

When it happens

Trigger: Passing an async schema (e.g. a Zod schema with async `.refine()`/`.transform()`, or a custom Standard Schema with async validate) as `requestContextSchema` on a workflow with `validateInputs: true`, then calling createRun/start/execution methods.

Common situations: Adding an async refinement (DB lookup, remote check) to the request-context schema; using async transforms from shared schemas; enabling validateInputs on an existing workflow with an async schema.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/a55a9c2ace495046. Report an issue: GitHub.