Demos / backend /classes /company_pii_scorer.py
nikhile-galileo's picture
Adding finance protect demo
e68d535
raw
history blame
725 Bytes
from typing import Any, Union, Type, List
import re
# Define regex patterns for each keyword, allowing for flexible spacing and separators
keyword_patterns = [
r"Fairfield\sCDC",
r"Fairfield",
]
def scorer_fn(*, index: Union[int, str], node_input: str, node_output: str, **kwargs: Any) -> Union[float, int, bool, str, None]:
# Check if any of the regex patterns match in the input
for pattern in keyword_patterns:
if re.search(pattern, node_output, re.IGNORECASE):
# If pattern found, check if output is valid JSON
return 1
# No patterns found
return 0
def score_type() -> Type:
return int
def scoreable_node_types_fn() -> List[str]:
return ["llm", "chat"]