{"record":{"id":"da987c94f8b5fe09","repo":"mastra-ai/mastra","slug":"request-context-validation-failed-for-workflow","errorCode":null,"errorMessage":"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')}","messagePattern":"Request context validation failed for workflow '(.+?)': \\\\n(.+?): (.+?)`; \\}\\)\\.join\\('\\\\n'\\)\\}","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/workflows/workflow.ts","lineNumber":3500,"sourceCode":"    if (!this.validateInputs || !this.stateSchema) {\n      return initialState;\n    }\n\n    return this.#validateSchema(this.stateSchema, initialState, 'initial data');\n  }\n\n  protected async _validateRequestContext(requestContext?: RequestContext) {\n    if (this.validateInputs && this.requestContextSchema) {\n      const contextValues = getRequestContextInputValues(requestContext);\n      const validation = this.requestContextSchema['~standard'].validate(contextValues);\n\n      if (validation instanceof Promise) {\n        throw new Error('Your schema is async, which is not supported. Please use a sync schema.');\n      }\n\n      if (!('value' in validation)) {\n        const errors = validation.issues;\n        throw new Error(\n          `Request context validation failed for workflow '${this.workflowId}': \\n` +\n            errors\n              .map(e => {\n                const pathStr = e.path?.map(p => (typeof p === 'object' ? p.key : p)).join('.');\n                return `- ${pathStr}: ${e.message}`;\n              })\n              .join('\\n'),\n        );\n      }\n    }\n  }\n\n  protected async _validateResumeData<TResume>(resumeData: TResume, suspendedStep?: StepWithComponent) {\n    if (!this.validateInputs || !suspendedStep?.resumeSchema) {\n      return resumeData;\n    }\n\n    return this.#validateSchema(suspendedStep.resumeSchema, resumeData, 'resume data');","sourceCodeStart":3482,"sourceCodeEnd":3518,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/workflows/workflow.ts#L3482-L3518","documentation":"This is the sync validation-failure branch of `_validateRequestContext`: when request-context values fail the (sync) `requestContextSchema`, Mastra throws an Error enumerating each issue's dotted path and message, prefixed with the workflow id.","triggerScenarios":"Calling `workflow.createRun()` / `start()` / `execute()` with a `requestContext` whose values violate `requestContextSchema` while `validateInputs: true` — wrong types, missing required keys, failed sync refinements.","commonSituations":"Request context built dynamically from env/HTTP headers with missing or mistyped values; schema updated to require new fields while call sites weren't; tenant/role values passing null where strings are required.","solutions":["Read the `- path: message` lines and correct the requestContext values to match requestContextSchema.","Parse request context with the schema (`requestContextSchema.parse(values)`) at the entry point before createRun.","Give optional fields defaults in the schema (`z.string().default(...)`) where appropriate.","Ensure all call sites (API routes, cron jobs) supply the newly required context keys."],"exampleFix":"// before\nawait workflow.createRun({ requestContext: { tenantId: undefined } });\n// after\nconst rc = workflow.requestContextSchema.parse({ tenantId: req.headers['x-tenant-id'] });\nawait workflow.createRun({ requestContext: rc });","handlingStrategy":"validation","validationCode":"const rc = workflow.requestContextSchema.safeParse(requestContext);\nif (!rc.success) {\n  throw new Error(rc.error.issues.map(i => `${i.path.join('.')}: ${i.message}`).join('\\n'));\n}\nawait workflow.createRun({ requestContext: rc.data });","typeGuard":"function isValidRequestContext<S extends z.ZodTypeAny>(schema: S, data: unknown): data is z.infer<S> {\n  return schema.safeParse(data).success;\n}","tryCatchPattern":"try {\n  await workflow.createRun({ requestContext });\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Request context validation failed')) {\n    console.error('fix requestContext per:', e.message);\n  } else throw e;\n}","preventionTips":["Parse request context at every entry point (HTTP, cron, queue) before createRun.","Type requestContext with z.infer of the workflow's requestContextSchema.","Add defaults for optional context fields and keep call sites updated when the schema changes."],"tags":["workflow","request-context","validation","schema"],"backgroundTag":"request-context-validation-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}