mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 03:04:13 +00:00
feat(redact_messages.py): allow remove sensitive key information before passing to logging integration
This commit is contained in:
parent
0b9e93d863
commit
548e4f53f8
7 changed files with 65 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue