langchain.utilities.opaqueprompts.sanitize

langchain.utilities.opaqueprompts.sanitize(input: Union[str, Dict[str, str]]) Dict[str, Union[str, Dict[str, str]]][source]

Sanitize input string or dict of strings by replacing sensitive data with placeholders.

It returns the sanitized input string or dict of strings and the secure context as a dict following the format: {

“sanitized_input”: <sanitized input string or dict of strings>, “secure_context”: <secure context>

}

The secure context is a bytes object that is needed to de-sanitize the response from the LLM.

Parameters

input – Input string or dict of strings.

Returns

Sanitized input string or dict of strings and the secure context as a dict following the format: {

”sanitized_input”: <sanitized input string or dict of strings>, “secure_context”: <secure context>

}

The secure_context needs to be passed to the desanitize function.

Raises
  • ValueError – If the input is not a string or dict of strings.

  • ImportError – If the opaqueprompts Python package is not installed.