The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
handle logging_only logic for guardrails
Ishaan Jafff1111f9a1bc9
diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.pyindex 537ca15a477..eb77a0a198c 100644--- a/litellm/litellm_core_utils/litellm_logging.py+++ b/litellm/litellm_core_utils/litellm_logging.py@@ -25,6 +25,7 @@ from litellm import ()from litellm.caching import DualCache, InMemoryCache, S3Cachefrom litellm.cost_calculator import _select_model_name_for_cost_calc+from litellm.integrations.custom_guardrail import CustomGuardrailfrom litellm.integrations.custom_logger import CustomLoggerfrom 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,diff --git a/litellm/types/guardrails.py b/litellm/types/guardrails.pyindex 10f4be7e1eb..cb70de5052d 100644--- a/litellm/types/guardrails.py+++ b/litellm/types/guardrails.py@@ -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):