DocsFeaturesMasking

Masking

Masking is a feature that allows precise control over the data sent to the Langfuse server. 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.

The process works as follows:

  1. You define a custom masking function and pass it to the Langfuse client constructor.
  2. All event inputs and outputs are processed through this function.
  3. The masked data is then sent to the Langfuse server.

This approach ensures that you have complete control over the event input and output data traced by your application.

Define a masking function:

def masking_function(data):
  if isinstance(data, str) and data.startswith("SECRET_"):
    return "REDACTED"
 
  return data

Use with the @observe() decorator:

from langfuse.decorators import langfuse_context, observe
 
langfuse_context.configure(mask=masking_function)
 
@observe()
def fn():
    return "SECRET_DATA"
 
fn()
 
langfuse_context.flush()
 
# The trace output in Langfuse will have the output masked as "REDACTED".

Use with the low-level SDK:

from langfuse import Langfuse
 
langfuse = Langfuse(mask=masking_function)
 
trace = langfuse.trace(output="SECRET_DATA")
 
langfuse.flush()
 
# The trace output in Langfuse will have the output masked as "REDACTED".

Was this page useful?

Questions? We're here to help

Subscribe to updates