"""Guardrail interfaces for Yoker tools.
Provides the Guardrail abstract base class that concrete guardrail
implementations must follow. Guardrails validate tool parameters before
execution to enforce permission boundaries.
"""
from abc import ABC, abstractmethod
from typing import Any
from yoker.tools.schema import ValidationResult
[docs]
class Guardrail(ABC):
"""Abstract base class for tool guardrails.
Guardrails validate tool parameters against permission boundaries
before a tool is executed. Each tool type will have specific
guardrail implementations (e.g., path restrictions for filesystem tools).
Example:
class PathGuardrail(Guardrail):
def validate(self, tool_name: str, params: dict[str, Any]) -> ValidationResult:
path = params.get("path", "")
if not path.startswith("/allowed"):
return ValidationResult(valid=False, reason="Path not allowed")
return ValidationResult(valid=True)
"""
[docs]
@abstractmethod
def validate(self, tool_name: str, value: str | dict[str, Any]) -> ValidationResult:
"""Validate tool parameters.
Args:
tool_name: Name of the tool being validated.
value: Either the extracted parameter value or the full params dict.
Returns:
ValidationResult indicating whether parameters are valid.
"""
__all__ = [
"Guardrail",
"ValidationResult",
]