feat(redact_messages.py): allow remove sensitive key information before passing to logging integration

This commit is contained in:
Krrish Dholakia 2024-07-22 20:58:02 -07:00
parent 0b9e93d863
commit 548e4f53f8
7 changed files with 65 additions and 4 deletions

View file

@ -87,3 +87,33 @@ def redact_message_input_output_from_logging(
# by default return result
return result
def redact_user_api_key_info(metadata: dict) -> dict:
"""
removes any user_api_key_info before passing to logging object, if flag set
Usage:
SDK
```python
litellm.redact_user_api_key_info = True
```
PROXY:
```yaml
litellm_settings:
redact_user_api_key_info: true
```
"""
if litellm.redact_user_api_key_info is not True:
return metadata
new_metadata = {}
for k, v in metadata.items():
if isinstance(k, str) and k.startswith("user_api_key"):
pass
else:
new_metadata[k] = v
return new_metadata