Bedrock error when calling

0
  bedrock_client = boto3.client(
    service_name="bedrock-runtime",
    region_name="us-east-1"
    )
 llm = Bedrock(
        model_id=modelID,
        client=bedrock_client,
        model_kwargs={"max_tokens_to_sample":300,"temperature":.5,"top_k":250,"top_p":0.999,"anthropic_version":"bedrock-2023-05-31"},
    )

It throws error as ValueError: Error raised by bedrock service: An error occurred (ValidationException) when calling the InvokeModel operation: Malformed input request: 5 schema violations found, please reformat your input and try again. Please give me some suggestions for solving this error.

Dipika
asked 4 months ago1327 views
1 Answer
1

@Dipika Thanks for reaching out.

As the error message says, there has been a validation error for the input prompt. Not all FMs have the same input prompt format. For instance: The input prompt format for Claude is as below.

# Claude requires you to enclose the prompt as follows:
            enclosed_prompt = "Human: " + prompt + "\n\nAssistant:"

            body = {
                "prompt": enclosed_prompt,
                "max_tokens_to_sample": 200,
                "temperature": 0.5,
                "stop_sequences": ["\n\nHuman:"],
            }

Please find the detailed examples here for different programming languages:

https://docs.aws.amazon.com/code-library/latest/ug/bedrock-runtime_code_examples_actions.html

Thanks, Arjun

AWS
answered 4 months ago
profile picture
EXPERT
reviewed a month 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