hierRAG / src /core /utils.py
ikram98ai's picture
refactoring the code and adding mcp
9f772a8
import re
def mask_pii(text: str) -> str:
"""Mask Personally Identifiable Information"""
# Email addresses
text = re.sub(r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b', '[EMAIL]', text)
# Phone numbers
text = re.sub(r'\b(?:\d{3}[-.]?\d{4}|\d{3}[-.]?\d{3}[-.]?\d{4})\b', '[PHONE]', text)
# Credit card numbers
text = re.sub(r'\b\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}\b', '[CREDIT_CARD]', text)
# Social Security Numbers
text = re.sub(r'\b\d{3}-\d{2}-\d{4}\b', '[SSN]', text)
return text