{"record":{"id":"c286961a2950dcfd","repo":"eyaltoledano/claude-task-master","slug":"invalid-template-structure-missing-required-field","errorCode":null,"errorMessage":"Invalid template structure: missing required fields (id, prompts.default)","messagePattern":"Invalid template structure: missing required fields \\(id, prompts\\.default\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/prompt-manager.js","lineNumber":149,"sourceCode":"\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) {\n\t\tif (!template.parameters) return;\n\n\t\tconst errors = [];\n\n\t\tfor (const [paramName, paramConfig] of Object.entries(","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/prompt-manager.js#L131-L167","documentation":"Fallback structural check in PromptManager.loadTemplate, used only when no schema validator is available (validatePrompt is true/absent). It rejects templates missing any of the minimum required fields: id, prompts, or prompts.default, ensuring the manager can always resolve a default prompt.","triggerScenarios":"Calling template(promptId) on a template that lacks `id`, lacks `prompts`, or lacks `prompts.default`, while the manager runs without a JSON-Schema validator — i.e. structurally broken/incomplete template objects.","commonSituations":"Minimal custom template stubs that only define variants (e.g. prompts.research) without a `default`, truncated/failed JSON loads, or templates copied from examples that assumed schema validation was active.","solutions":["Add a `prompts.default` entry to the template (plus its `id`).","Ensure the template object has all three: id, prompts, prompts.default.","Fix the source JSON/file if the template was truncated on load.","Optionally enable schema validation so future errors point at exact fields."],"exampleFix":"// before\n{ \"id\": \"research-gen\", \"prompts\": { \"research\": { \"user\": \"...\" } } }\n// after\n{ \"id\": \"research-gen\", \"prompts\": { \"default\": { \"system\": \"...\", \"user\": \"...\" }, \"research\": { \"user\": \"...\" } } }","handlingStrategy":"validation","validationCode":"function assertTemplateStructure(tpl) {\n  if (!tpl || !tpl.id || !tpl.prompts || !tpl.prompts.default) {\n    throw new Error(`Template ${tpl?.id ?? '(unknown)'} missing required fields: id, prompts.default`);\n  }\n}\n// run before registering the template","typeGuard":"const hasRequiredTemplateFields = (t) =>\n  Boolean(t && typeof t === 'object' && t.id && t.prompts && t.prompts.default);","tryCatchPattern":"if (!hasRequiredTemplateFields(rawTemplate)) {\n  throw new Error('Custom template must define id and prompts.default before registration');\n}","preventionTips":["Always include a prompts.default entry, even when adding specialized variants.","Sanity-check templates loaded from files for truncation/parse errors.","Adopt the schema validator so structural gaps are caught with field-level detail.","Use a template factory helper that enforces the required fields."],"tags":["validation","templates","prompts","structure"],"backgroundTag":"missing-required-field","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}