aboutsummaryrefslogtreecommitdiff
path: root/stdout_filterer.py
diff options
context:
space:
mode:
authorNavan Chauhan <navanchauhan@gmail.com>2023-10-13 23:50:10 -0600
committerNavan Chauhan <navanchauhan@gmail.com>2023-10-13 23:50:10 -0600
commit9f914f8d479d58d7ccc045784fe614dfea9a1219 (patch)
treedb5a58ae9bdae7a7aa139c6220e048c359657298 /stdout_filterer.py
parent6edba6384b42fa03785ac5887e91eb310e876ced (diff)
langchain
Diffstat (limited to 'stdout_filterer.py')
-rw-r--r--stdout_filterer.py15
1 files changed, 15 insertions, 0 deletions
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()