Anonymizer¶
langsmith.anonymizer
¶
FUNCTION | DESCRIPTION |
---|---|
create_anonymizer |
Create an anonymizer function. |
StringNode
¶
StringNodeProcessor
¶
Processes a list of string nodes for masking.
METHOD | DESCRIPTION |
---|---|
mask_nodes |
Accept and return a list of string nodes to be masked. |
mask_nodes
abstractmethod
¶
mask_nodes(nodes: list[StringNode]) -> list[StringNode]
Accept and return a list of string nodes to be masked.
ReplacerOptions
¶
StringNodeRule
¶
RuleNodeProcessor
¶
Bases: StringNodeProcessor
String node processor that uses a list of rules to replace sensitive data.
METHOD | DESCRIPTION |
---|---|
__init__ |
Initialize the processor with a list of rules. |
mask_nodes |
Mask nodes using the rules. |
rules
instance-attribute
¶
rules: list[StringNodeRule] = [
{
"pattern": rule["pattern"]
if isinstance(rule["pattern"], Pattern)
else compile(rule["pattern"]),
"replace": rule["replace"] if isinstance(get("replace"), str) else "[redacted]",
}
for rule in rules
]
List of rules to apply for replacing sensitive data.
Each rule is a StringNodeRule, which contains a regex pattern to match and an optional replacement string.
CallableNodeProcessor
¶
Bases: StringNodeProcessor
String node processor that uses a callable function to replace sensitive data.
METHOD | DESCRIPTION |
---|---|
__init__ |
Initialize the processor with a callable function. |
mask_nodes |
Mask nodes using the callable function. |
func
instance-attribute
¶
The callable function used to replace sensitive data.
It can be either a function that takes a single string argument and returns a string, or a function that takes a string and a list of path elements (strings or integers) and returns a string.
accepts_path
instance-attribute
¶
Indicates whether the callable function accepts a path argument.
If True, the function expects two arguments: the string to be processed and the path to that string. If False, the function expects only the string to be processed.
__init__
¶
Initialize the processor with a callable function.
mask_nodes
¶
mask_nodes(nodes: list[StringNode]) -> list[StringNode]
Mask nodes using the callable function.