Make sure every mode is logged correctly

This commit is contained in:
clyang 2026-04-20 15:03:28 +08:00
parent 7ebcee7581
commit c70bbbe583
No known key found for this signature in database
GPG key ID: D52FE178A5104AD1

View file

@ -70,6 +70,7 @@ _RATIONALE_TRUNCATE_CHARS = 200
_DEFAULT_POLICIES = [
"Default_Policy_SystemPromptEnforcement",
"Default_Policy_HarmfulContentProtection",
"Default_Policy_GeneralPromptAttackProtection",
]
@ -207,6 +208,15 @@ class XecGuardGuardrail(CustomGuardrail):
StandardLoggingGuardrailInformation entry so the scan decision
reaches downstream loggers (Langfuse, DataDog, etc.).
"""
if (
isinstance(kwargs, dict)
and "litellm_params" in kwargs
and "metadata" in kwargs["litellm_params"]
and "standard_logging_guardrail_information"in kwargs["litellm_params"]["metadata"]
and kwargs["litellm_params"]["metadata"]["standard_logging_guardrail_information"]
):
return kwargs, result
start_time = datetime.now()
try:
assistant_text = self._extract_assistant_text_from_response(result)
@ -575,4 +585,4 @@ class XecGuardGuardrail(CustomGuardrail):
return (
f"Blocked by XecGuard grounding: rules=[{rules_str}] "
f"trace_id={trace_id} rationale={rationale}"
)
)