{"record":{"id":"55e289251fcbc173","repo":"mastra-ai/mastra","slug":"label-references-stepresults-stepid-but-step","errorCode":null,"errorMessage":"${label} references stepResults.${stepId} but step \"${stepId}\" has no successful output (not run yet, not registered, failed, or produced no output).","messagePattern":"(.+?) references stepResults\\.(.+?) but step \"(.+?)\" has no successful output \\(not run yet, not registered, failed, or produced no output\\)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/workflows/mapping-template.ts","lineNumber":171,"sourceCode":"    case 'inputData':\n      return stringifyTemplateValue(traverseMappingPath(ctx.inputData, rest, label), template, idx, rawExpr);\n    case 'initData':\n      return stringifyTemplateValue(traverseMappingPath(ctx.getInitData(), rest, label), template, idx, rawExpr);\n    case 'state':\n      return stringifyTemplateValue(traverseMappingPath(ctx.state, rest, label), template, idx, rawExpr);\n    case 'requestContext':\n      return stringifyTemplateValue(ctx.requestContext.get(rest), template, idx, rawExpr);\n    case 'stepResults': {\n      const innerDot = rest.indexOf('.');\n      const stepId = innerDot === -1 ? rest : rest.slice(0, innerDot);\n      const subPath = innerDot === -1 ? '' : rest.slice(innerDot + 1);\n      const stepResult = ctx.getStepResult(stepId);\n      // Nullish (not just null) so a step that \"succeeded\" with `undefined`\n      // output is reported as missing too — consistent with how predicates\n      // treat nullish step results. Nullish *path values inside* a present\n      // result still render as '' via stringifyTemplateValue.\n      if (stepResult == null) {\n        throw new Error(\n          `${label} references stepResults.${stepId} but step \"${stepId}\" has no successful output ` +\n            `(not run yet, not registered, failed, or produced no output).`,\n        );\n      }\n      return stringifyTemplateValue(traverseMappingPath(stepResult, subPath, label), template, idx, rawExpr);\n    }\n    default:\n      // validateTemplate guarantees this branch is unreachable for well-formed\n      // workflows; this is a safety net for templates that bypassed validation\n      // (e.g. constructed programmatically and pushed into stepFlow).\n      throw new Error(\n        `${label} references unknown namespace \"${scope}\". Use one of: ${TEMPLATE_NAMESPACES.join(', ')}.`,\n      );\n  }\n}\n","sourceCodeStart":153,"sourceCodeEnd":187,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/workflows/mapping-template.ts#L153-L187","documentation":"Resolving ${stepResults.<stepId>...} requires that the referenced step has a successful (non-nullish) result in the mapping context. If getStepResult(stepId) returns null/undefined — the step hasn't run, isn't registered in this workflow, failed, or succeeded with undefined output — the template cannot be resolved and it throws explaining why.","triggerScenarios":"A mapping template references stepResults.someStep while someStep runs after the mapping point, belongs to a different workflow (not registered), failed, or returned undefined; also triggered when a step \"succeeds\" with undefined output.","commonSituations":"Referencing a step that executes later in the flow (ordering mistake); typos in step IDs; steps wrapped/renamed during refactors; conditional branches where the step didn't execute on this path.","solutions":["Ensure the referenced step runs BEFORE the mapping/variable is used in the workflow graph.","Fix the step ID to match the registered step's ID (check the error's stepId against createWorkflow's step list).","If the step is conditionally skipped, guard the template/mapping or supply a fallback via requestContext or an earlier step.","Make the producing step return a defined output (at minimum an object) even on trivial success."],"exampleFix":"// before\n// step chain: evaluate -> uses ${stepResults.fetchUser.name}, but fetchUser runs after evaluate\n.then(evaluate)\n.then(fetchUser)\n// after\n.then(fetchUser)\n.then(evaluate) // now stepResults.fetchUser exists when evaluate maps","handlingStrategy":"validation","validationCode":"const snap = run.workflowRunStatus;\nconst registeredStepIds = workflow.stepGraph ? Object.keys(workflow.stepGraph) : [];\nconst tpl = '${stepResults.fetchUser.name}';\nconst id = tpl.match(/\\$\\{stepResults\\.([^.}]+)/)?.[1];\nif (id && !registeredStepIds.includes(id)) throw new Error(`${id} is not a step in this workflow`);","typeGuard":null,"tryCatchPattern":"try {\n  run.workflow.mapVariable({ value: '${stepResults.fetchUser.name}' });\n} catch (err) {\n  if (err instanceof Error && err.message.includes('has no successful output')) {\n    console.error('Check step ordering/registration: fetchUser must run and succeed before this mapping');\n  } else throw err;\n}","preventionTips":["Verify the referenced step appears earlier in the workflow chain than the mapping that uses it.","Keep step IDs as shared constants to avoid typos.","Ensure steps always return a defined output object, even for trivial success.","Handle conditional branches: don't map results of steps that may be skipped on a path."],"tags":["workflow","template","step-results","ordering"],"backgroundTag":"missing-step-result","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}