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
gefragt vor 5 Monaten1669 Aufrufe
1 Antwort
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
beantwortet vor 5 Monaten
profile picture
EXPERTE
überprüft vor 2 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen