eyaltoledano/claude-task-master · error
Invalid template structure: missing required fields (id, pro
Error message
Invalid template structure: missing required fields (id, prompts.default)
What it means
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.
Source
Thrown at scripts/modules/prompt-manager.js:149
const template = this.prompts.get(promptId);
if (!template) {
throw new Error(`Prompt template '${promptId}' not found`);
}
// Schema validation if available (do this first for detailed errors)
if (this.validatePrompt && this.validatePrompt !== true) {
const valid = this.validatePrompt(template);
if (!valid) {
const errors = this.validatePrompt.errors
.map((err) => `${err.instancePath || 'root'}: ${err.message}`)
.join(', ');
throw new Error(`Schema validation failed: ${errors}`);
}
} else {
// Fallback basic validation if no schema validation available
if (!template.id || !template.prompts || !template.prompts.default) {
throw new Error(
'Invalid template structure: missing required fields (id, prompts.default)'
);
}
}
return template;
}
/**
* Validate parameters against template schema
* @private
*/
validateParameters(template, variables) {
if (!template.parameters) return;
const errors = [];
for (const [paramName, paramConfig] of Object.entries(View on GitHub (pinned to c0c98d367c)
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.
Example fix
// before
{ "id": "research-gen", "prompts": { "research": { "user": "..." } } }
// after
{ "id": "research-gen", "prompts": { "default": { "system": "...", "user": "..." }, "research": { "user": "..." } } } Defensive patterns
Strategy: validation
Validate before calling
function assertTemplateStructure(tpl) {
if (!tpl || !tpl.id || !tpl.prompts || !tpl.prompts.default) {
throw new Error(`Template ${tpl?.id ?? '(unknown)'} missing required fields: id, prompts.default`);
}
}
// run before registering the template Type guard
const hasRequiredTemplateFields = (t) => Boolean(t && typeof t === 'object' && t.id && t.prompts && t.prompts.default);
Try / catch
if (!hasRequiredTemplateFields(rawTemplate)) {
throw new Error('Custom template must define id and prompts.default before registration');
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.
Related errors
- Schema validation failed: ${errors}
- Dynamic slash command "${name}" must contain $ARGUMENTS plac
- Prompt template '${promptId}' not found
- Parameter validation failed: ${errors.join('; ')}
- Failed to load prompt template: ${error.message}
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/c286961a2950dcfd.
Report an issue: GitHub.