Merge pull request #17378 from BerriAI/litellm_indent_import_fix

[Fix] Bedrock Guardrail Indent and Import fix
This commit is contained in:
yuneng-jiang 2025-12-02 11:28:12 -08:00 committed by GitHub
commit 61b0dbd726
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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"