From 93e4f4aea98607d7111e39f374d7bae8ea3dac34 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 22 May 2026 14:47:13 +0000 Subject: [PATCH] Remove dead code in purview_dlp: _resolve_user_id_for_blocking never returns falsy The method either returns a non-empty trusted user id or raises HTTPException, so the 'if not user_id' guards in async_pre_call_hook and async_post_call_success_hook were unreachable. Tighten the return type to str and drop the dead checks to make the fail-closed behavior explicit. Co-authored-by: Yassin Kortam --- .../guardrail_hooks/microsoft_purview/purview_dlp.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/litellm/proxy/guardrails/guardrail_hooks/microsoft_purview/purview_dlp.py b/litellm/proxy/guardrails/guardrail_hooks/microsoft_purview/purview_dlp.py index 27bbe91f045..b8e28f9a861 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/microsoft_purview/purview_dlp.py +++ b/litellm/proxy/guardrails/guardrail_hooks/microsoft_purview/purview_dlp.py @@ -257,7 +257,7 @@ class MicrosoftPurviewDLPGuardrail(PurviewGuardrailBase, CustomGuardrail): self, data: Dict[str, Any], user_api_key_dict: Any, - ) -> Optional[str]: + ) -> str: """Resolve user ID for blocking (pre_call / post_call) DLP hooks. Uses only trusted proxy-authenticated sources (``_resolve_trusted_user_id``). @@ -307,8 +307,6 @@ class MicrosoftPurviewDLPGuardrail(PurviewGuardrailBase, CustomGuardrail): ) -> Optional[Dict[str, Any]]: """Check user prompt against Purview DLP policies before LLM call.""" user_id = self._resolve_user_id_for_blocking(data, user_api_key_dict) - if not user_id: - return data prompt_text: Optional[str] = None is_text_completion = call_type in ("text_completion", "atext_completion") @@ -360,8 +358,6 @@ class MicrosoftPurviewDLPGuardrail(PurviewGuardrailBase, CustomGuardrail): this hook for requests that have a streaming iterator hook defined. """ user_id = self._resolve_user_id_for_blocking(data, user_api_key_dict) - if not user_id: - return response parts = self._completion_response_text_parts(response)