-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
I'm getting the below error message when using Bedrock Guardrails + boto3 Converse through the gateway, even though the same request works fine directly against Bedrock.
Error message
botocore.exceptions.ClientError: An error occurred (400) when calling the Converse operation: {'error': 'Error from LiteLLM endpoint: {"error":{"message":"litellm.BadRequestError: BedrockException - {\\"message\\":\\"A conversation must start with a user message. Try again with a conversation that starts with a user message.\\"}\\n. Pass in default user message via `completion(..,user_continue_message=)` or enable `litellm.modify_params=True`.\\nFor Proxy: do via `litellm_settings::modify_params: True` or user_continue_message under `litellm_params`. Received Model Group=us.anthropic.claude-3-5-sonnet-20241022-v2:0\\nAvailable Model Group Fallbacks=None","type":null,"param":null,"code":"400"}}'}
Minimal reproducible example
The below code assumes you have the gateway deployed and an Amazon Bedrock Guardrail configured in your same active AWS region - and yields the error:
import boto3
from botocore import UNSIGNED
from botocore.config import Config
# (br client setup begins)
proxy_url = "https://YOUR-GATEWAY-URL/bedrock"
proxy_token = "sk-YOUR-GATEWAY-API-TOKEN"
br = boto3.client(
"bedrock-runtime",
config=Config(signature_version=UNSIGNED),
endpoint_url=proxy_url,
)
def add_authorization_header(request, **_):
request.headers["Authorization"] = f"Bearer {proxy_token}"
br.meta.events.register("request-created.*", add_authorization_header)
# (br client setup ends)
resp = br.converse(
**{
'modelId': 'us.anthropic.claude-3-5-sonnet-20241022-v2:0',
'messages': [
{
'role': 'user',
'content': [
{
'guardContent': {
'text': {
'text': "How's the weather?"
}
}
}
]
}
],
'system': [
{
'text': 'You are a cool cat'
}
],
'inferenceConfig': {'maxTokens': 4096, 'temperature': 1.0},
'additionalModelRequestFields': {},
'guardrailConfig': {
'guardrailIdentifier': 'YOUR-BEDROCK-GUARDRAIL-ID',
'guardrailVersion': 'DRAFT',
'trace': 'enabled_full',
}
}
)
print(resp)
...However, replacing the br client setup section with just br = boto3.client("bedrock-runtime")
(not using the proxy/gateway) seems to work just fine.
Additional info
Tried upgrading to LiteLLM v1.69.0-stable and current main branch code of this solution, and still seeing same issue.
Metadata
Metadata
Assignees
Labels
No labels