{"record":{"id":"c854891f937491be","repo":"mastra-ai/mastra","slug":"dynamic-workflow-def-id-failed-validation-wit","errorCode":null,"errorMessage":"Dynamic workflow \"${def.id}\" failed validation with ${issues.length} issue(s):\n${details}","messagePattern":"Dynamic workflow \"(.+?)\" failed validation with (.+?) issue\\(s\\):\n(.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/workflows/dynamic/validate/index.ts","lineNumber":66,"sourceCode":"    index,\n    [\n      ...validateWorkflowStructure(def),\n      ...validateWorkflowSchemas(def),\n      ...validateWorkflowRefs(def, index),\n      ...inference.issues,\n    ],\n    inference.stepOutputs,\n    inference.entryInputs,\n    inference.finalOutput,\n  );\n}\n\n/** Throwing presentation of {@link validateDynamicWorkflow} for the save path. */\nexport function assertValidDynamicWorkflow(def: WorkflowValidationInput, index: WorkflowRegistryIndex = {}): void {\n  const issues = validateDynamicWorkflow(def, index);\n  if (issues.length === 0) return;\n  const details = issues.map(issue => `- [${issue.code}] ${issue.path}: ${issue.message}`).join('\\n');\n  throw new Error(`Dynamic workflow \"${def.id}\" failed validation with ${issues.length} issue(s):\\n${details}`);\n}\n","sourceCodeStart":48,"sourceCodeEnd":68,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/workflows/dynamic/validate/index.ts#L48-L68","documentation":"When a dynamically created workflow definition is registered via addDynamicWorkflows, Mastra validates it with validateDynamicWorkflow. If any issues are found, assertValidDynamicWorkflow throws this aggregated Error listing each issue code, path, and message. It is a save-time guard so invalid workflow definitions never enter the registry.","triggerScenarios":"Calling mastra.addDynamicWorkflows(...) (or the corresponding server/API route) with a definition whose steps, edges, variables, or references fail structural validation — e.g. missing step ids, dangling edges, invalid variable paths, duplicate ids, or references to non-registered agents/tools.","commonSituations":"Programmatic workflow generation (LLM-authored or codegen'd workflows) producing slightly invalid graphs; hand-edited dynamic workflow JSON; renaming steps without updating edges or variable bindings; submitting workflows through the dynamic-workflow API endpoint.","solutions":["Read the issue list in the error message; fix each [code] at the given path in the workflow definition.","Ensure every step referenced by edges/conditions actually exists in the definition and has a unique id.","Check variable bindings (paths, kinds, step ids) match the declared step schemas.","If the workflow references agents/tools by id, register them on the Mastra instance or pass instances directly before saving.","Re-run validation client-side with validateDynamicWorkflow (non-throwing) before calling addDynamicWorkflows to get structured issues."],"exampleFix":"// before\nawait mastra.addDynamicWorkflows({ id: 'wf', steps: { a: {...} }, edges: [{ from: 'a', to: 'missingStep' }] });\n// after\nconst issues = validateDynamicWorkflow(def);\nif (issues.length) console.error(issues); // fix dangling edges first\nawait mastra.addDynamicWorkflows({ id: 'wf', steps: { a: {...} }, edges: [{ from: 'a', to: 'b' }], ... });","handlingStrategy":"validation","validationCode":"import { validateDynamicWorkflow } from './workflows/dynamic/validate';\nconst issues = validateDynamicWorkflow(def, {});\nif (issues.length > 0) {\n  throw new Error('Invalid workflow: ' + issues.map(i => `[${i.code}] ${i.path}: ${i.message}`).join('; '));\n}\nawait mastra.addDynamicWorkflows(def);","typeGuard":null,"tryCatchPattern":"try { await mastra.addDynamicWorkflows(def); } catch (e) { if (e.message.includes('failed validation')) { logIssues(parseIssues(e.message)); } else throw e; }","preventionTips":["Validate definitions with validateDynamicWorkflow before saving.","Keep a canonical generator function for dynamic workflows rather than hand-built objects.","Add unit tests that validate every shipped dynamic workflow definition.","Lint for dangling edge targets and duplicate step ids in workflow JSON."],"tags":["validation","workflows","dynamic-workflows"],"backgroundTag":"schema-validation-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}