From 32116cf4339e95fa8459cc7c08952d0aa5ead165 Mon Sep 17 00:00:00 2001 From: Shin Date: Sat, 7 Feb 2026 01:45:29 +0000 Subject: [PATCH] fix(pangea): use elif to prevent UnboundLocalError and handle None messages Address Greptile review feedback: - Make branches mutually exclusive using elif to prevent input_messages from being overwritten - Handle case where data.get('messages') returns None to avoid passing invalid payload to Pangea API --- .../proxy/guardrails/guardrail_hooks/pangea/pangea.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/guardrails/guardrail_hooks/pangea/pangea.py b/litellm/proxy/guardrails/guardrail_hooks/pangea/pangea.py index 3f36e175461..55c7e72c36f 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/pangea/pangea.py +++ b/litellm/proxy/guardrails/guardrail_hooks/pangea/pangea.py @@ -250,10 +250,13 @@ class PangeaHandler(CustomGuardrail): if isinstance(response, TextCompletionResponse): # Assume the earlier call type as well input_messages = _TextCompletionRequest(data).get_messages() - if not isinstance(response, ModelResponse): - return + elif isinstance(response, ModelResponse): + messages = data.get("messages") + if messages is None: + return # No messages to check + input_messages = cast(List[Dict[Any, Any]], messages) else: - input_messages = cast(List[Dict[Any, Any]], data.get("messages")) + return if choices := response.get("choices"): if isinstance(choices, list):