From 8c1290dcd2bcb12cba8fab8dfd4c8a94e0c85382 Mon Sep 17 00:00:00 2001 From: yuneng-jiang Date: Tue, 2 Dec 2025 11:26:29 -0800 Subject: [PATCH] Indent and import fix --- .../guardrail_hooks/bedrock_guardrails.py | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py b/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py index f9c3caf494..bd1e805361 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py +++ b/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py @@ -20,6 +20,7 @@ from typing import ( AsyncGenerator, List, Literal, + NamedTuple, Optional, Tuple, Union, @@ -1291,38 +1292,38 @@ class BedrockGuardrail(CustomGuardrail, BaseAWSLLM): request_data=request_data, ) - bedrock_response = await self.make_bedrock_api_request( - source="INPUT", - messages=mock_messages, - request_data=request_data, + bedrock_response = await self.make_bedrock_api_request( + source="INPUT", + messages=mock_messages, + request_data=request_data, + ) + + if bedrock_response.get("action") == "BLOCKED": + raise Exception( + f"Content blocked by Bedrock guardrail: {bedrock_response.get('reason', 'Unknown reason')}" ) - if bedrock_response.get("action") == "BLOCKED": - raise Exception( - f"Content blocked by Bedrock guardrail: {bedrock_response.get('reason', 'Unknown reason')}" - ) - - # Apply any masking that was applied by the guardrail - masked_text = text - output_list = bedrock_response.get("output") - if output_list: - # If the guardrail returned modified content, use that - for output_item in output_list: + # Apply any masking that was applied by the guardrail + masked_text = text + output_list = bedrock_response.get("output") + if output_list: + # If the guardrail returned modified content, use that + for output_item in output_list: + text_content = output_item.get("text") + if text_content: + masked_text = str(text_content) + break + else: + outputs_list = bedrock_response.get("outputs") + if outputs_list: + # Fallback to outputs field if output is not available + for output_item in outputs_list: text_content = output_item.get("text") if text_content: masked_text = str(text_content) break - else: - outputs_list = bedrock_response.get("outputs") - if outputs_list: - # Fallback to outputs field if output is not available - for output_item in outputs_list: - text_content = output_item.get("text") - if text_content: - masked_text = str(text_content) - break - masked_texts.append(masked_text) + masked_texts.append(masked_text) verbose_proxy_logger.debug( "Bedrock Guardrail: Successfully applied guardrail"