Skip to content

Bedrock - Converse API - Described guardrails format not working #6482

@rd37011

Description

@rd37011

Describe the issue

I am able to chat with my model via ConverseCommand without issues. I recently created a guardrail on the AWS Console, and I was able to achieve the desired results.

When I attempted to integrate the guardrail using guardrailConfig on ConverseCommandInput and adding the guardContent property to the latest message (I am trying to run the guardrail on the last user message) I get a ValidationException: Guardrail was enabled but input is in incorrect format., even though the format in the message below matches the example.

I hope it's a simple fix on my end and I've messed up the format somehow.

Here is a simplified code snippet that results in the error I'm seeing:

const client = new BedrockRuntimeClient({
      region: 'us-west-2',
    })
    const input: ConverseCommandInput = {
      modelId: 'meta.llama3-1-8b-instruct-v1:0',
      messages: [
        {
            "role": "user",
            "content": [
                {
                    "text": 'Give me a recipe for mayonnaise',
                }
            ]
        },
        {
          "role": "assistant",
          "content": [
              {
                  "text": 'Sure! The recipe for mayonnaise is...',
              },
          ]
      },
      {
        "role": "user",
        "content": [
            {
                "guardContent": {
                    "text": {
                        "text": 'Is mayonnaise an instrument?'
                    }
                }
            }
        ]
    }],
      guardrailConfig: { 
        guardrailIdentifier: "arn:aws:bedrock:us-east-1:<acct_id>:guardrail/<guardrail_id>",
        guardrailVersion: "Version 1",
    },
      inferenceConfig: {
        maxTokens: 512,
        temperature: 0.2,
        topP: 1,
        stopSequences: [],
      },
      system: [
        {
          text: 'You are a helpful assistant.'
        },
      ],
    }
    
    const command = new ConverseCommand(input)
    const response = await client.send(command)

Links

https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/bedrock-runtime/command/ConverseCommand/
https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-use-converse-api.html#guardrails-use-converse-api-call-configure

Metadata

Metadata

Assignees

Labels

documentationThis is a problem with documentation.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions