validate_template_parameters
Validate input parameters against a predefined template schema to ensure compatibility with AI model requirements before processing.
Instructions
Validate parameters against a template schema.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes |
Implementation Reference
- The core handler function for the 'validate_template_parameters' tool. It performs validation by instantiating the TemplateInput Pydantic model, which triggers field validators for template existence and parameter schema compliance.def validate_template_parameters(input: dict[str, Any]) -> bool: """Validate parameters against a template schema.""" template_input = TemplateInput(**input) return True # If we get here, validation passed
- Pydantic model defining the input schema for the tool. Contains field validators that check if the template exists in TEMPLATES and validates parameters against the JSON schema defined in the template.class TemplateInput(BaseModel): """Input for template-based operations.""" template: str = Field(..., description="Template identifier") parameters: dict[str, Any] = Field(default_factory=dict, description="Template parameters") @field_validator("template") def validate_template(cls, v: str) -> str: """Validate template identifier.""" if v not in TEMPLATES: raise ValueError(f"Unknown template: {v}") return v @field_validator("parameters") def validate_parameters(cls, v: dict[str, Any], values: dict[str, Any]) -> dict[str, Any]: """Validate template parameters.""" if "template" not in values: return v template = TEMPLATES[values["template"]] try: jsonschema.validate(v, template["parameter_schema"]) except jsonschema.exceptions.ValidationError as e: raise ValueError(f"Invalid parameters: {e.message}") from e return v
- Defines the TEMPLATES dictionary imported into server.py, which contains preset configurations used for template validation. Individual templates reference parameter_schema defined in other files.TEMPLATES: dict[str, dict[str, Any]] = { "quality": QUALITY_PRESETS, "style": STYLE_PRESETS, "aspect_ratio": ASPECT_RATIO_PRESETS, "negative_prompt": NEGATIVE_PROMPT_PRESETS, }
- Aggregates all template definitions (including those with parameter_schema) into a single TEMPLATES dictionary, though server.py imports directly from common_configs."""Parameter templates for Replicate models.""" from .common_configs import TEMPLATES as COMMON_TEMPLATES from .stable_diffusion import TEMPLATES as SD_TEMPLATES from .controlnet import TEMPLATES as CONTROLNET_TEMPLATES # Merge all templates TEMPLATES = { **COMMON_TEMPLATES, **SD_TEMPLATES, **CONTROLNET_TEMPLATES, } __all__ = ["TEMPLATES"]