- Completely hide inputs and outputs using environment variables or Client configuration.
- Hide metadata to remove or transform run metadata.
- Apply rule-based masking with regex patterns or anonymization libraries to selectively redact sensitive information.
- Process inputs and outputs for individual functions with function-level customization.
- Use third-party anonymizers like Microsoft Presidio and Amazon Comprehend for advanced PII detection.
If your compliance or privacy requirements mandate that certain operations should never be traced at all (for example, clients with zero-retention policies), consider using conditional tracing to disable tracing selectively for specific requests instead of masking data.
Hide inputs and outputs
If you want to completely hide the inputs and outputs of your traces, you can set the following environment variables when running your application:hide_inputs and hide_outputs parameters on the Client object (hideInputs and hideOutputs in TypeScript).
The following example returns an empty object for both hide_inputs and hide_outputs, but you can customize this to your needs:
Hide metadata
Thehide_metadata parameter allows you to control whether run metadata is hidden or transformed when tracing with the LangSmith Python SDK. Metadata is passed with the extra parameter when creating runs (e.g., extra={"metadata": {...}}). hide_metadata is useful for removing sensitive information, complying with privacy requirements, or reducing the amount of data sent to LangSmith. You can configure metadata hiding in two ways:
-
Using the SDK:
-
Using environment variables:
hide_metadata parameter accepts three types of values:
True: Completely removes all metadata (sends an empty dictionary).FalseorNone: Preserves metadata as-is (default behavior).Callable: A custom function that transforms the metadata dictionary.
metadata field in the extra parameter for all runs created or updated by the Client, including runs created through the @traceable decorator or LangChain integrations.
Hide all metadata
Sethide_metadata=True to remove all metadata completely from runs sent to LangSmith:
Custom transformation
Use a callable function to selectively filter, redact, or modify metadata before it’s sent to LangSmith:Rule-based masking of inputs and outputs
This feature is available in the following LangSmith SDK versions:
- Python: 0.1.81 and above
- TypeScript: 0.1.33 and above
create_anonymizer / createAnonymizer function and pass the newly created anonymizer when instantiating the Client. The anonymizer can be either constructed from a list of regex patterns and the replacement values or from a function that accepts and returns a string value.
The anonymizer will be skipped for inputs if LANGSMITH_HIDE_INPUTS = true. Same applies for outputs if LANGSMITH_HIDE_OUTPUTS = true.
However, if inputs or outputs are to be sent to Client, the anonymizer method will take precedence over functions found in hide_inputs and hide_outputs. By default, the create_anonymizer will only look at maximum of 10 nesting levels deep, which can be configured via the max_depth parameter.
Improving the performance of
anonymizer API is on our roadmap! If you are encountering performance issues, please contact support via support.langchain.com.
hide_inputs and hide_outputs parameters to achieve the same effect. You can also use these parameters to process the inputs and outputs more efficiently.
Processing inputs and outputs for a single function
The
process_outputs parameter is available in LangSmith SDK version 0.1.98 and above for Python.process_inputs and process_outputs parameters of the @traceable decorator.
These parameters accept functions that allow you to transform the inputs and outputs of a specific function before they are logged to LangSmith. This is useful for reducing payload size, removing sensitive information, or customizing how an object should be serialized and represented in LangSmith for a particular function.
Here’s an example of how to use process_inputs and process_outputs:
process_inputs creates a new dictionary with processed input data, and process_outputs transforms the output into a specific format before logging to LangSmith.
For asynchronous functions, the usage is similar:
hide_inputs and hide_outputs) when both are defined.
Examples
You can combine rule-based masking with various anonymizers to scrub sensitive information from inputs and outputs. The following examples will cover working with regex, Microsoft Presidio, and Amazon Comprehend.Regex
The implementation below is not exhaustive and may miss some formats or edge cases. Test any implementation thoroughly before using it in production.
The non-anonymized run will look like this in LangSmith:
Microsoft Presidio
The implementation below provides a general example of how to anonymize sensitive information in messages exchanged between a user and an LLM. It is not exhaustive and does not account for all cases. Test any implementation thoroughly before using it in production.
The non-anonymized run will look like this in LangSmith:
Amazon Comprehend
The implementation below provides a general example of how to anonymize sensitive information in messages exchanged between a user and an LLM. It is not exhaustive and does not account for all cases. Test any implementation thoroughly before using it in production.
The non-anonymized run will look like this in LangSmith: