mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-13 08:52:02 +00:00
fix(guardrails): sync content filter logging
This commit is contained in:
parent
b4f5e46a44
commit
06377b9047
2 changed files with 24 additions and 1 deletions
|
|
@ -20,7 +20,7 @@ from fastapi import HTTPException
|
|||
from litellm import Router
|
||||
from litellm._logging import verbose_proxy_logger
|
||||
from litellm.constants import DEFAULT_MAX_RECURSE_DEPTH
|
||||
from litellm.integrations.custom_guardrail import CustomGuardrail
|
||||
from litellm.integrations.custom_guardrail import CustomGuardrail, log_guardrail_information
|
||||
from litellm.proxy._types import UserAPIKeyAuth
|
||||
from litellm.types.utils import (
|
||||
CallTypes,
|
||||
|
|
@ -1864,6 +1864,7 @@ class ContentFilterGuardrail(CustomGuardrail):
|
|||
if filtered_arguments != arguments:
|
||||
self._set_tool_call_arguments(tool_call, filtered_arguments)
|
||||
|
||||
@log_guardrail_information
|
||||
async def apply_guardrail(
|
||||
self,
|
||||
inputs: "GenericGuardrailAPIInputs",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ Tests for the Content Filter Guardrail
|
|||
import json
|
||||
import os
|
||||
import sys
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
|
@ -232,6 +233,27 @@ class TestContentFilterGuardrail:
|
|||
assert "[EMAIL_REDACTED]" in result[0]
|
||||
assert "test@example.com" not in result[0]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_apply_guardrail_syncs_information_to_logging_obj(self):
|
||||
guardrail = ContentFilterGuardrail(guardrail_name="test-logging-sync")
|
||||
request_data = {"metadata": {}}
|
||||
logging_obj = SimpleNamespace(
|
||||
litellm_params={"metadata": {}},
|
||||
model_call_details={},
|
||||
)
|
||||
|
||||
await guardrail.apply_guardrail(
|
||||
inputs={"texts": ["A normal request"]},
|
||||
request_data=request_data,
|
||||
input_type="request",
|
||||
logging_obj=logging_obj,
|
||||
)
|
||||
|
||||
entries = logging_obj.litellm_params["metadata"]["standard_logging_guardrail_information"]
|
||||
assert len(entries) == 1
|
||||
assert entries[0]["guardrail_name"] == "test-logging-sync"
|
||||
assert entries[0]["guardrail_status"] == "success"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_apply_guardrail_blocked_word_mask(self):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue