Skip to main content
Masking is a feature that allows precise control over the tracing data sent to the ABV server. With custom masking functions, you can control and sanitize the data that gets traced and sent to the server. Whether it’s for compliance reasons or to protect user privacy, masking sensitive data is a crucial step in responsible application development. It enables you to:
  1. Redact sensitive information from trace or observation inputs and outputs.
  2. Customize the content of events before transmission.
  3. Implement fine-grained data filtering based on your specific requirements.
Learn more about ABV’s data security and privacy measures concerning the stored data in our security and compliance overview.

How it works

  1. You define a custom masking function and pass it to the ABV client constructor.
  2. All event inputs and outputs are processed through this function.
  3. The masked data is then sent to the ABV server.
This approach ensures that you have complete control over the event input and output data traced by your application.

Python SDK

Install package
Define a masking function before the client initialization. The masking function will apply to all event inputs and outputs regardless of the ABV-maintained integration you are using.
Apply the masking function when initializing the ABV client:
So it will look like below, with the decorator:
Using context managers:

JS/TS SDK

Install packages
Add credentials Add your ABV credentials to your environment variables. Make sure that you have a .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
Masked data will be shown in UI: Input: “Hello, ABV! My card number is ***MASKED_CREDIT_CARD*** ” Output: “This is my first trace! And my card number is ***MASKED_CREDIT_CARD***” See JS/TS SDK docs for more details.

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:
  1. Import necessary modules.
  2. Define a masking function that uses a regular expression to detect and replace credit card numbers.
  3. Configure the masking function in ABV.
  4. Create a sample function to simulate processing sensitive data.
  5. 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.