Class: LangsmithrbRails::Redactor
- Inherits:
-
Object
- Object
- LangsmithrbRails::Redactor
- Defined in:
- lib/langsmithrb_rails/redactor.rb
Overview
PII redaction utility for LangSmith traces
Constant Summary collapse
- PATTERNS =
Common PII patterns
{ email: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/, phone: /\b(\+\d{1,2}\s?)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}\b/, credit_card: /\b(?:\d{4}[-\s]?){3}\d{4}\b|\b\d{13,16}\b/, ssn: /\b\d{3}[-\s]?\d{2}[-\s]?\d{4}\b/, ip_address: /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/ }.freeze
Class Attribute Summary collapse
-
.allowlist ⇒ Object
Allowlist of patterns that should not be redacted.
-
.custom_patterns ⇒ Object
Custom patterns to redact beyond the defaults.
Class Method Summary collapse
-
.scrub(input) ⇒ Object
Scrub PII from the input.
-
.setup ⇒ Object
Initialize the class variables.
Class Attribute Details
.allowlist ⇒ Object
Allowlist of patterns that should not be redacted
17 18 19 |
# File 'lib/langsmithrb_rails/redactor.rb', line 17 def allowlist @allowlist end |
.custom_patterns ⇒ Object
Custom patterns to redact beyond the defaults
20 21 22 |
# File 'lib/langsmithrb_rails/redactor.rb', line 20 def custom_patterns @custom_patterns end |
Class Method Details
.scrub(input) ⇒ Object
Scrub PII from the input
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/langsmithrb_rails/redactor.rb', line 31 def scrub(input) return input unless Config[:redact_by_default] case input when String scrub_string(input) when Hash input.transform_values { |v| scrub(v) } when Array input.map { |item| scrub(item) } else input end end |
.setup ⇒ Object
Initialize the class variables
23 24 25 26 |
# File 'lib/langsmithrb_rails/redactor.rb', line 23 def setup @allowlist = [] @custom_patterns = {} end |