- Redact sensitive information from trace or observation inputs and outputs.
- Customize the content of events before transmission.
- Implement fine-grained data filtering based on your specific requirements.
How it works
- You define a custom masking function and pass it to the ABV client constructor.
- All event inputs and outputs are processed through this function.
- The masked data is then sent to the ABV server.
Python SDK
Install packageJS/TS SDK
Install packages.env file in your project root and a package like dotenv to load the variables.
Createinstrumentation.ts file and use dotenv package to load the variables.
Additional parameters are provided to get trace visible in the UI immediately.
Import the instrumentation.ts file at the top of your application.
To prevent sensitive data from being sent to ABV, you can provide a mask function to the ABVSpanProcessor. This function will be applied to the input, output, and metadata of every observation.
The function receives an object { data }, where data is the stringified JSON of the attribute’s value. It should return the masked data.
Simple example with masked data
Examples
Now, we’ll show you examples how to use the masking feature. We’ll use the ABV decorator for this, but you can also use the low-level SDK or the JS/TS SDK analogously.Example 1: Redacting Credit Card Numbers
In this example, we’ll demonstrate how to redact credit card numbers from strings using a regular expression. This helps in complying with PCI DSS by ensuring that credit card numbers are not transmitted or stored improperly. Steps:- Import necessary modules.
- Define a masking function that uses a regular expression to detect and replace credit card numbers.
- Configure the masking function in ABV.
- Create a sample function to simulate processing sensitive data.
- Observe the trace to see the masked output.
Example 2: Using the llm-guard library
Use the Anonymize scanner from llm-guard to remove personal names and PII. See the llm-guard documentation for more details.
Example 3: Masking Email and Phone Numbers
You can extend the masking function to redact other types of PII such as email addresses and phone numbers using regular expressions.