Files
zeekay 6db5cf2d7e feat: Add GitHub Actions workflow for Docker builds
- Add docker-publish.yml workflow for ghcr.io
- Add production-ready Dockerfile (if missing)
- Enable automated builds on push to main
- Support for semantic versioning tags
2025-07-23 23:06:26 -05:00

63 lines
1.7 KiB
Python

"""Parameter validation utilities for Hanzo AI tools.
This module provides utilities for validating parameters in tool functions.
"""
from typing import TypeVar, final
T = TypeVar("T")
@final
class ValidationResult:
"""Result of a parameter validation."""
def __init__(self, is_valid: bool, error_message: str = ""):
"""Initialize a validation result.
Args:
is_valid: Whether the parameter is valid
error_message: Optional error message for invalid parameters
"""
self.is_valid: bool = is_valid
self.error_message: str = error_message
@property
def is_error(self) -> bool:
"""Check if the validation resulted in an error.
Returns:
True if there was a validation error, False otherwise
"""
return not self.is_valid
def validate_path_parameter(
path: str | None, parameter_name: str = "path"
) -> ValidationResult:
"""Validate a path parameter.
Args:
path: The path parameter to validate
parameter_name: The name of the parameter (for error messages)
Returns:
A ValidationResult indicating whether the parameter is valid
"""
# Check for None
if path is None:
return ValidationResult(
is_valid=False,
error_message=f"Path parameter '{parameter_name}' is required but was None",
)
# Check for empty path
if path.strip() == "":
return ValidationResult(
is_valid=False,
error_message=f"Path parameter '{parameter_name}' is required but was empty string",
)
# Path is valid
return ValidationResult(is_valid=True)