mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-08 22:21:35 +00:00
handle logging_only logic for guardrails
This commit is contained in:
parent
528154764b
commit
f1111f9a1b
2 changed files with 23 additions and 1 deletions
|
|
@ -25,6 +25,7 @@ from litellm import (
|
|||
)
|
||||
from litellm.caching import DualCache, InMemoryCache, S3Cache
|
||||
from litellm.cost_calculator import _select_model_name_for_cost_calc
|
||||
from litellm.integrations.custom_guardrail import CustomGuardrail
|
||||
from litellm.integrations.custom_logger import CustomLogger
|
||||
from litellm.litellm_core_utils.redact_messages import (
|
||||
redact_message_input_output_from_logging,
|
||||
|
|
@ -1350,7 +1351,23 @@ class Logging:
|
|||
## LOGGING HOOK ##
|
||||
|
||||
for callback in callbacks:
|
||||
if isinstance(callback, CustomLogger):
|
||||
if isinstance(callback, CustomGuardrail):
|
||||
from litellm.types.guardrails import GuardrailEventHooks
|
||||
|
||||
if (
|
||||
callback.should_run_guardrail(
|
||||
data=self.model_call_details,
|
||||
event_type=GuardrailEventHooks.logging_only,
|
||||
)
|
||||
is not True
|
||||
):
|
||||
self.model_call_details, result = await callback.async_logging_hook(
|
||||
kwargs=self.model_call_details,
|
||||
result=result,
|
||||
call_type=self.call_type,
|
||||
)
|
||||
continue
|
||||
elif isinstance(callback, CustomLogger):
|
||||
self.model_call_details, result = await callback.async_logging_hook(
|
||||
kwargs=self.model_call_details,
|
||||
result=result,
|
||||
|
|
|
|||
|
|
@ -84,6 +84,10 @@ class LitellmParams(TypedDict, total=False):
|
|||
guardrailIdentifier: Optional[str]
|
||||
guardrailVersion: Optional[str]
|
||||
|
||||
# Presidio params
|
||||
output_parse_pii: Optional[bool]
|
||||
presidio_ad_hoc_recognizers: Optional[str]
|
||||
|
||||
|
||||
class Guardrail(TypedDict):
|
||||
guardrail_name: str
|
||||
|
|
@ -98,6 +102,7 @@ class GuardrailEventHooks(str, Enum):
|
|||
pre_call = "pre_call"
|
||||
post_call = "post_call"
|
||||
during_call = "during_call"
|
||||
logging_only = "logging_only"
|
||||
|
||||
|
||||
class BedrockTextContent(TypedDict, total=False):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue