{"record":{"id":"5e15f19d4ba7c332","repo":"mastra-ai/mastra","slug":"describebadplaceholder-template-idx-rawexpr-5e15f1","errorCode":null,"errorMessage":"${describeBadPlaceholder(template, idx, rawExpr)} requires a request-context key — use ${requestContext.<key>}.","messagePattern":"(.+?) requires a request-context key — use (.+?)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/workflows/mapping-template.ts","lineNumber":76,"sourceCode":"      throw new Error(\n        `${describeBadPlaceholder(template, idx, rawExpr)} has empty or whitespace-padded contents. ` +\n          `Use \\${<scope>.<path>} with no surrounding whitespace.`,\n      );\n    }\n    const { scope, rest } = parseTemplatePlaceholder(rawExpr);\n    if (scope === 'stepResults') {\n      const innerDot = rest.indexOf('.');\n      const stepId = innerDot === -1 ? rest : rest.slice(0, innerDot);\n      if (!stepId) {\n        throw new Error(\n          `${describeBadPlaceholder(template, idx, rawExpr)} must be of the form \\${stepResults.<stepId>} or \\${stepResults.<stepId>.<path>}.`,\n        );\n      }\n      continue;\n    }\n    if (scope === 'requestContext') {\n      if (!rest) {\n        throw new Error(\n          `${describeBadPlaceholder(template, idx, rawExpr)} requires a request-context key — use \\${requestContext.<key>}.`,\n        );\n      }\n      continue;\n    }\n    if ((TEMPLATE_NAMESPACES as readonly string[]).includes(scope)) continue;\n    throw new Error(\n      `${describeBadPlaceholder(template, idx, rawExpr)} references unknown namespace \"${scope}\". ` +\n        `Use one of: ${TEMPLATE_NAMESPACES.join(', ')}.`,\n    );\n  }\n}\n\n/**\n * Collects the step ids referenced by `${stepResults.<stepId>}` /\n * `${stepResults.<stepId>.<path>}` placeholders in a template. Assumes the\n * template already passed {@link validateTemplate}; malformed placeholders are\n * skipped. Used by validation to scope-check template references against the","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/workflows/mapping-template.ts#L58-L94","documentation":"requestContext-scoped placeholders must name a key: ${requestContext.<key>}. If the placeholder is exactly \"${requestContext}\" with no key, validateTemplate throws because there is nothing to look up in the request context.","triggerScenarios":"Writing \"${requestContext}\" alone in a mapping template passed to mapVariable/map/analyzeMapConfig.","commonSituations":"Assuming the whole request context can be injected as one value; deleting the key after the dot during edits.","solutions":["Specify the key: \"${requestContext.userId}\".","If multiple values are needed, reference each key in separate placeholders or build it in a preceding step.","Add build-time validateTemplate() coverage for templates."],"exampleFix":"// before\nmapVariable({ value: '${requestContext}' });\n// after\nmapVariable({ value: '${requestContext.tenantId}' });","handlingStrategy":"validation","validationCode":"const tpl = '${requestContext.tenantId}';\nfor (const m of tpl.matchAll(/\\$\\{([^}]*)\\}/g)) {\n  const [scope, key] = m[1].split('.');\n  if (scope === 'requestContext' && !key) throw new Error(`${m[0]} needs a requestContext key`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  validateTemplate(tpl);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('request-context key')) {\n    console.error(`Template '${tpl}' must name a requestContext key`);\n  } else throw err;\n}","preventionTips":["Reference individual requestContext keys, never the whole context.","Keep a list of known requestContext keys and validate templates against it.","Validate templates with validateTemplate() at module load or in tests."],"tags":["workflow","template","request-context","syntax"],"backgroundTag":"template-syntax-error","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}