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
Indent and import fix
yuneng-jiang8c1290dcd2bc
diff --git a/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py b/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.pyindex f9c3caf4944..bd1e805361c 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"