python_function.py
1 from typing import Callable 2 3 from evidently.guardrails.core import GuardException 4 from evidently.guardrails.core import GuardrailBase 5 6 7 class PythonFunction(GuardrailBase): 8 def __init__(self, function: Callable[[str], bool]): 9 super().__init__() 10 self.function = function 11 12 def name(self) -> str: 13 return f"python_function_{self.function.__name__}" 14 15 def validate(self, data: str): 16 if self.function(data): 17 return 18 raise GuardException(self)