{"record":{"id":"da46b6b5f01ac078","repo":"eyaltoledano/claude-task-master","slug":"schema-validation-failed-errors","errorCode":null,"errorMessage":"Schema validation failed: ${errors}","messagePattern":"Schema validation failed: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/prompt-manager.js","lineNumber":144,"sourceCode":"\t * Load a prompt template from the imported prompts\n\t * @private\n\t */\n\tloadTemplate(promptId) {\n\t\t// Get template from the map\n\t\tconst template = this.prompts.get(promptId);\n\n\t\tif (!template) {\n\t\t\tthrow new Error(`Prompt template '${promptId}' not found`);\n\t\t}\n\n\t\t// Schema validation if available (do this first for detailed errors)\n\t\tif (this.validatePrompt && this.validatePrompt !== true) {\n\t\t\tconst valid = this.validatePrompt(template);\n\t\t\tif (!valid) {\n\t\t\t\tconst errors = this.validatePrompt.errors\n\t\t\t\t\t.map((err) => `${err.instancePath || 'root'}: ${err.message}`)\n\t\t\t\t\t.join(', ');\n\t\t\t\tthrow new Error(`Schema validation failed: ${errors}`);\n\t\t\t}\n\t\t} else {\n\t\t\t// Fallback basic validation if no schema validation available\n\t\t\tif (!template.id || !template.prompts || !template.prompts.default) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Invalid template structure: missing required fields (id, prompts.default)'\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn template;\n\t}\n\n\t/**\n\t * Validate parameters against template schema\n\t * @private\n\t */\n\tvalidateParameters(template, variables) {","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/prompt-manager.js#L126-L162","documentation":"Thrown by PromptManager.loadTemplate after fetching a template when its JSON-Schema validator (this.validatePrompt) returns invalid. The message aggregates all validator errors as 'path: message' pairs (instancePath defaults to 'root'), pinpointing which fields of the template object violate the prompt schema.","triggerScenarios":"Registering/loading a template object whose shape deviates from the prompt schema — wrong types, missing required properties, or unexpected values — then calling template(promptId) with schema validation enabled.","commonSituations":"Hand-authored or hand-edited custom prompt templates with typos or missing fields, templates written for an older schema version, or JSON with wrong types (e.g. prompts as string instead of object) imported into the manager.","solutions":["Read the interpolated errors list and fix each cited path/field in the template definition.","Validate the template JSON against the prompt schema offline before registering.","Copy a known-good built-in template as the base for custom prompts.","If schema is from an older version, update the template to the current schema."],"exampleFix":"// before (missing prompt text)\n{ \"id\": \"task-update\", \"prompts\": {} }\n// after\n{ \"id\": \"task-update\", \"prompts\": { \"default\": { \"system\": \"...\", \"user\": \"...\" } } }","handlingStrategy":"validation","validationCode":"function validateTemplateShape(tpl, validatePrompt) {\n  if (validatePrompt && validatePrompt !== true) {\n    const valid = validatePrompt(tpl);\n    if (!valid) {\n      const errors = validatePrompt.errors.map(e => `${e.instancePath || 'root'}: ${e.message}`).join(', ');\n      throw new Error(`Template '${tpl?.id}' fails schema: ${errors}`);\n    }\n  }\n}\n// call before registering: validateTemplateShape(myTemplate, ajvValidate);","typeGuard":null,"tryCatchPattern":"try {\n  const tpl = promptManager.template(promptId);\n} catch (e) {\n  if (e.message.startsWith('Schema validation failed:')) {\n    console.error('Fix these template fields:', e.message.replace('Schema validation failed: ', ''));\n    return null;\n  }\n  throw e;\n}","preventionTips":["Validate template JSON against the schema at build/registration time, not at use time.","Derive custom templates from a shipped, known-valid example.","Keep templates in version control and schema-check them in CI.","Update templates when the prompt schema version changes."],"tags":["schema-validation","templates","prompts","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}