From 9f914f8d479d58d7ccc045784fe614dfea9a1219 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Fri, 13 Oct 2023 23:50:10 -0600 Subject: langchain --- stdout_filterer.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 stdout_filterer.py (limited to 'stdout_filterer.py') diff --git a/stdout_filterer.py b/stdout_filterer.py new file mode 100644 index 0000000..c4cf845 --- /dev/null +++ b/stdout_filterer.py @@ -0,0 +1,15 @@ +import re + + +class RedactPhoneNumbers: + def __init__(self, stream): + self.stream = stream + + def write(self, text): + # Regular expression to match phone numbers + phone_regex = r"(\+\d{1,2}\s?)?1?\-?\.?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}" + redacted_text = re.sub(phone_regex, "****", text) + self.stream.write(redacted_text) + + def flush(self): + self.stream.flush() -- cgit v1.2.3