Skip to content

Commit

Permalink
fix bedrock applying guardrails where content is a list
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaan-jaff committed Jan 24, 2025
1 parent a7cd42c commit 4918398
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
CustomGuardrail,
log_guardrail_information,
)
from litellm.litellm_core_utils.prompt_templates.common_utils import (
convert_content_list_to_str,
)
from litellm.llms.bedrock.base_aws_llm import BaseAWSLLM
from litellm.llms.custom_httpx.http_handler import (
get_async_httpx_client,
Expand All @@ -36,6 +39,7 @@
BedrockTextContent,
GuardrailEventHooks,
)
from litellm.types.llms.openai import AllMessageValues
from litellm.types.utils import ModelResponse

GUARDRAIL_NAME = "bedrock"
Expand All @@ -62,20 +66,20 @@ def __init__(

def convert_to_bedrock_format(
self,
messages: Optional[List[Dict[str, str]]] = None,
messages: Optional[List[AllMessageValues]] = None,
response: Optional[Union[Any, ModelResponse]] = None,
) -> BedrockRequest:
bedrock_request: BedrockRequest = BedrockRequest(source="INPUT")
bedrock_request_content: List[BedrockContentItem] = []

if messages:
for message in messages:
content = message.get("content")
if isinstance(content, str):
bedrock_content_item = BedrockContentItem(
text=BedrockTextContent(text=content)
bedrock_content_item = BedrockContentItem(
text=BedrockTextContent(
text=convert_content_list_to_str(message=message)
)
bedrock_request_content.append(bedrock_content_item)
)
bedrock_request_content.append(bedrock_content_item)

bedrock_request["content"] = bedrock_request_content
if response:
Expand Down

0 comments on commit 4918398

Please sign in to comment.