validate_template_parameters
Validate template parameters before execution to identify errors and warnings, ensuring workflow compatibility in ComfyUI.
Instructions
Validate parameters for a template without generating.
Checks if provided parameters are valid for the template and returns detailed validation results.
Args: template_name: Name of the template parameters: Dictionary of parameters to validate
Returns: Validation results with errors and warnings
Examples: validate_template_parameters("text2img_basic", {"width": "512"})
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| template_name | Yes | ||
| parameters | Yes |
Implementation Reference
- comfy_mcp/mcp/server.py:519-545 (handler)MCP tool handler for 'validate_template_parameters'. Delegates validation to TemplateManager instance.@mcp.tool def validate_template_parameters( template_name: str, parameters: dict ) -> dict: """Validate parameters for a template without generating. Checks if provided parameters are valid for the template and returns detailed validation results. Args: template_name: Name of the template parameters: Dictionary of parameters to validate Returns: Validation results with errors and warnings Examples: validate_template_parameters("text2img_basic", {"width": "512"}) """ try: validation = template_manager.validate_parameters(template_name, parameters) return validation except Exception as e: raise ToolError(f"Error validating parameters: {e}")
- Core validation logic in TemplateManager. Extracts required parameters from DSL using regex, checks for missing/extra parameters, and performs type/range validations for common parameters like width, height, steps, cfg, seed, denoise.def validate_parameters( self, template_name: str, parameters: Dict[str, str], source: str = "auto" ) -> Dict[str, List[str]]: """Validate parameters for a template.""" # Try to find template in custom or official template = None if source in ["auto", "custom"]: template = self.custom_templates.get(template_name) if not template and source in ["auto", "official"]: official_template = official_manager.get_template(template_name) if official_template and official_template.dsl_content: # Create minimal template object for validation template = type('Template', (), { 'parameters': {}, 'dsl_content': official_template.dsl_content })() if not template: return { "valid": False, "errors": [f"Template '{template_name}' not found"], "warnings": [] } errors = [] warnings = [] # Check for required parameters (those in template but not provided) template_params = template.parameters or {} required_params = set(self._extract_parameters_from_dsl(template.dsl_content)) provided_params = set(parameters.keys()) missing_params = required_params - provided_params if missing_params: errors.append(f"Missing required parameters: {', '.join(missing_params)}") # Check for extra parameters extra_params = provided_params - required_params if extra_params: warnings.append(f"Extra parameters will be ignored: {', '.join(extra_params)}") # Validate specific parameter types/constraints for param_name, param_value in parameters.items(): if param_name in template_params: validation_errors = self._validate_parameter_value( param_name, param_value, template_name ) errors.extend(validation_errors) return { "valid": len(errors) == 0, "errors": errors, "warnings": warnings }