Masking Function Causes Major Latency #10550
Replies: 2 comments 2 replies
-
|
Good news—the masking function already executes in a background thread and should not add latency to your application execution(1). According to the documentation, the mask is applied in the background thread and does not add latency to the execution of the application(2). This means your Presidio-based masking function should run asynchronously without blocking your main application flow. However, if you're still experiencing performance issues, here are some things to verify: 1. Ensure you're using the correct masking setup: When initializing the Langfuse client with your masking function, use this pattern(3): from langfuse import Langfuse
def pii_masker(data: any, **kwargs) -> any:
# Your Presidio-based masking logic here
if isinstance(data, str):
# Apply masking
return masked_data
elif isinstance(data, dict):
return {k: pii_masker(data=v) for k, v in data.items()}
elif isinstance(data, list):
return [pii_masker(data=item) for item in data]
return data
langfuse = Langfuse(mask=pii_masker)2. Pass the masking function to the LangChain CallbackHandler: from langfuse.langchain import CallbackHandler
handler = CallbackHandler(mask=pii_masker)3. Optimize your masking function: Since the masking function is called for each piece of data (inputs, outputs, metadata), consider optimizing your Presidio calls. The function should be as efficient as possible even though it runs in the background(3). If you're still experiencing doubled response times despite the background execution, this suggests the issue might be elsewhere in your setup. Double-check that you're not accidentally blocking on the masking operation or that your Presidio configuration isn't causing unexpected synchronous behavior. 📚 Sources:
Have another question? Just tag @inkeep. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @hananmannhelloheart, inkeep is correct, the masking function should not add latency. Could you share a minimal viable code snippet to reproduce this on our end? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
We're tracing our LangChain/LangGraph application using the Langfuse callback handler. We've implemented a Presidio-based masking function and are passing it to the Langfuse client to redact sensitive data before logging.
The Issue: The synchronous execution of the data masking function is causing significant performance degradation.
The Result: Our overall response time is doubling, severely impacting user experience.
We need to execute this data processing off the main thread to maintain high performance. Could you please advise on the official or recommended pattern for integrating a custom, computationally intensive masking function with the Langfuse client so that it executes non-blockingly?
Beta Was this translation helpful? Give feedback.
All reactions