validate_prompt
Check parameters against a prompt template to ensure compatibility before rendering, preventing errors in automated workflows.
Instructions
Validate parameters against a prompt template without rendering
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| templateId | Yes | The ID of the template | |
| parameters | Yes | Parameters to validate |
Implementation Reference
- src/prompts/prompts.ts:293-312 (registration)Registers the 'validate_prompt' MCP tool with Zod input schema (templateId and parameters) and a handler that calls registry.prompts.validate and returns JSON result.server.tool( "validate_prompt", "Validate parameters against a prompt template without rendering", { templateId: z.string().describe("The ID of the template"), parameters: z.record(z.any()).describe("Parameters to validate"), }, async (args) => { const validation = registry.prompts.validate(args.templateId, args.parameters); return { content: [ { type: "text", text: JSON.stringify(validation, null, 2), }, ], }; } );
- src/core/prompt-manager.ts:252-287 (handler)Main handler logic in PromptManager.validate: checks template existence, required parameters via helper, and performs type checking on provided parameters./** * Validate parameters against a template without rendering */ validate( templateId: string, params: Record<string, unknown> ): { valid: boolean; errors: string[] } { const template = this.get(templateId); if (!template) { return { valid: false, errors: [`Template not found: ${templateId}`] }; } const paramValidation = validateParameters(template, params); if (!paramValidation.valid) { return { valid: false, errors: [`Missing required parameters: ${paramValidation.missing.join(", ")}`], }; } // Type validation const errors: string[] = []; for (const param of template.parameters) { const value = params[param.name]; if (value !== undefined && !this.validateType(value, param.type)) { errors.push( `Parameter '${param.name}' should be type '${param.type}', got '${typeof value}'` ); } } return { valid: errors.length === 0, errors, }; }
- src/core/prompt-manager.ts:24-34 (helper)Helper function to validate presence of required parameters.function validateParameters( template: PromptTemplate, params: Record<string, unknown> ): { valid: boolean; missing: string[] } { const required = template.parameters.filter((p) => p.required); const missing = required.filter((p) => !(p.name in params)); return { valid: missing.length === 0, missing: missing.map((p) => p.name), }; }
- src/core/prompt-manager.ts:292-307 (helper)Private helper for type validation of parameter values against expected types.private validateType(value: unknown, expectedType: string): boolean { switch (expectedType) { case "string": return typeof value === "string"; case "number": return typeof value === "number"; case "boolean": return typeof value === "boolean"; case "array": return Array.isArray(value); case "object": return typeof value === "object" && value !== null && !Array.isArray(value); default: return true; } }