{"record":{"id":"229c2b2a91151a44","repo":"mastra-ai/mastra","slug":"processor-workflow-invalid-output","errorCode":"PROCESSOR_WORKFLOW_INVALID_OUTPUT","errorMessage":"Processor workflow ${workflow.id} returned invalid output format. Expected ProcessorStepOutput.","messagePattern":"Processor workflow (.+?) returned invalid output format\\. Expected ProcessorStepOutput\\.","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/processors/runner.ts","lineNumber":628,"sourceCode":"      throw new MastraError({\n        category: 'USER',\n        domain: 'AGENT',\n        id: 'PROCESSOR_WORKFLOW_FAILED',\n        text: `Processor workflow ${workflow.id} failed with status: ${result.status}${detailStr}`,\n      });\n    }\n\n    // Extract and validate the output from the workflow result\n    const output = result.result;\n\n    if (!output || typeof output !== 'object') {\n      // No output means no changes - return input unchanged\n      return input;\n    }\n\n    // Validate it has the expected ProcessorStepOutput shape\n    if (!('phase' in output) || !('messages' in output || 'part' in output || 'messageList' in output)) {\n      throw new MastraError({\n        category: 'USER',\n        domain: 'AGENT',\n        id: 'PROCESSOR_WORKFLOW_INVALID_OUTPUT',\n        text: `Processor workflow ${workflow.id} returned invalid output format. Expected ProcessorStepOutput.`,\n      });\n    }\n\n    return output as ProcessorStepOutput;\n  }\n\n  async runOutputProcessors(\n    messageList: MessageList,\n    observabilityContext?: ObservabilityContext,\n    requestContext?: RequestContext,\n    retryCount: number = 0,\n    writer?: ProcessorStreamWriter,\n    result?: OutputResult,\n  ): Promise<MessageList> {","sourceCodeStart":610,"sourceCodeEnd":646,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/processors/runner.ts#L610-L646","documentation":"A workflow used as a processor must return a ProcessorStepOutput — an object with a phase field and one of messages, part, or messageList. If the workflow returns nothing meaningful the runner passes input through, but if it returns an object lacking that shape, executeWorkflowAsProcessor throws MastraError PROCESSOR_WORKFLOW_INVALID_OUTPUT to catch contract violations early.","triggerScenarios":"runOutputProcessors / runInputProcessors / runProcessOutputStep / runProcessToolResult executes a workflow-as-processor whose final step returns an object without 'phase' or without any of 'messages' | 'part' | 'messageList' (e.g. it returns its own arbitrary result object).","commonSituations":"Reusing an ordinary business workflow as a processor without adapting its output; refactoring ProcessorStepOutput shape after a version upgrade; returning { success: true, data } style payloads from the last workflow step.","solutions":["Make the workflow's final step return a valid ProcessorStepOutput: { phase: ..., messages/messageList/part: ... }.","If the workflow is not meant to transform messages, don't register it as a processor — call it separately.","Check @mastra/core docs/types for ProcessorStepOutput in your version and match its shape (older versions differ).","Add a runtime check/logging on the workflow's output to confirm phase and messages fields before registering."],"exampleFix":"// before (last step)\nreturn { ok: true, result: cleaned };\n// after\nreturn { phase: 'output', messages: cleanedMessages };","handlingStrategy":"validation","validationCode":"const out = getLastStepOutput(wf);\nconst isProcessorStepOutput = out && typeof out === 'object' && 'phase' in out && ('messages' in out || 'part' in out || 'messageList' in out);\nif (!isProcessorStepOutput) throw new Error('Workflow final step must return ProcessorStepOutput');","typeGuard":"function isProcessorStepOutput(o) {\n  return o !== null && typeof o === 'object' &&\n    'phase' in o && ('messages' in o || 'part' in o || 'messageList' in o);\n}","tryCatchPattern":"try {\n  await runProcessors(input);\n} catch (e) {\n  if (e?.id === 'PROCESSOR_WORKFLOW_INVALID_OUTPUT') {\n    // fix the workflow's final return value to ProcessorStepOutput shape\n  } else throw e;\n}","preventionTips":["Type workflow return values as ProcessorStepOutput at authoring time.","Don't register ordinary workflows as processors unless they return the processor contract.","Re-check output shape after @mastra/core upgrades."],"tags":["workflows","processors","schema-validation","mastra-error"],"backgroundTag":"invalid-processor-output","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}