langchain_community.utilities.opaqueprompts
.sanitize¶
- langchain_community.utilities.opaqueprompts.sanitize(input: Union[str, Dict[str, str]]) Dict[str, Union[str, Dict[str, str]]] [source]¶
对输入字符串或字符串字典进行清理,将敏感数据替换为占位符。
它返回清理后的输入字符串或字符串字典,以及作为字典的安全上下文,格式如下: {
“sanitized_input”: <清理后的输入字符串或字符串字典>, “secure_context”: <安全上下文>
}
安全上下文是一个字节对象,需要用于从LLM的响应中去除清理。
- 参数:
input: 输入字符串或字符串字典。
- 返回:
清理后的输入字符串或字符串字典,以及作为字典的安全上下文,格式如下: {
“sanitized_input”: <清理后的输入字符串或字符串字典>, “secure_context”: <安全上下文>
}
需要将`secure_context`传递给`desanitize`函数。
- 抛出:
ValueError: 如果输入不是字符串或字符串字典。 ImportError: 如果未安装`opaqueprompts` Python包。
- Parameters
input (Union[str, Dict[str, str]]) –
- Return type
Dict[str, Union[str, Dict[str, str]]]