Bedrock: Claude 2.1 System Prompts Support?

1

Does Bedrock support Claude 2.1 system prompts? Here is Bedrock's release discussing system prompts in Claude 1.s (https://aws.amazon.com/about-aws/whats-new/2023/11/claude-2-1-foundation-model-anthropic-amazon-bedrock/) but the Claude 2.1 sample API request in Bedrock still starts with "\n\nHuman" and I get an error when try to use system prompt (without the \n\nHuman" in the prompt value below.

{ "modelId": "anthropic.claude-v2:1", "contentType": "application/json", "accept": "/", "body": { "prompt": "\n\nHuman: Hello world\n\nAssistant:", "max_tokens_to_sample": 300, "temperature": 0.5, "top_k": 250, "top_p": 1, "stop_sequences": [ "\n\nHuman:" ], "anthropic_version": "bedrock-2023-05-31" } }

Thank you!

DJL
asked 5 months ago942 views
2 Answers
0

Hi, the short answer:

For Claude 2.1, which is using the Text Completion API, you have to add "System: Your system prompt" in front of "\n\nHuman", like in this example:

system_prompt = "All your output must be pirate speech 🦜"
user_prompt = "Tell me a story."
prompt = "System:" + system_prompt + "\n\nHuman: " + user_prompt + "\n\nAssistant:"

For Claude 3, which uses the new Messages API, you can add a system parameter to the request body, like in this example:

{
  "system": "All your output must be pirate speech 🦜",
  "anthropic_version": "bedrock-2023-05-31",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Tell me a story."
        }
      ]
    }
  ]
}

For fully functional code examples, check out my blog post on the topic: Use System Prompts with Anthropic Claude on Amazon Bedrock

answered 2 months ago
-1

Thank you for your question. It is supported as Amazon Bedrock is simply an access point for using various FMs. Taking a look at the Anthropic documentation and without looking at your code in depth it seems that maybe there is a formatting issue in your prompt. There is still a need for a human prompt to be part of the request.

AWS
answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions