Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rd37011 opened this issue Sep 17, 2024 · 3 comments
Closed

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

rd37011 opened this issue Sep 17, 2024 · 3 comments
Assignees
Labels
documentation This is a problem with documentation.

Comments

@rd37011
Copy link

rd37011 commented Sep 17, 2024

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

@rd37011 rd37011 added documentation This is a problem with documentation. needs-triage This issue or PR still needs to be triaged. labels Sep 17, 2024
@rd37011
Copy link
Author

rd37011 commented Sep 17, 2024

In case anyone else comes across this again - ValidationException: Guardrail was enabled but input is in incorrect format.
I was able to figure out through trial and error that the guardrails must be located in the same region as the foundational model being used. Once I switched to a model in us-east-1, my request worked. That being said, this was not explicitly mentioned in any resources I consulted.

Would love for the resulting error message to be a bit more descriptive - e.g. "ValidationException: Guardrail region must match model region" or something to that effect, assuming of course that is the behavior.

@aBurmeseDev
Copy link
Member

Hi @rd37011 - thanks for reaching out and sharing the feedback.

I've confirmed with service team Bedrock that this's expected behavior to have same region for both model and guardrails. Since the error comes from service team rather than SDK, I've forwarded this feedback to the team.

Please feel free to reach out again. Closing the issue.

@aBurmeseDev aBurmeseDev self-assigned this Sep 18, 2024
@aBurmeseDev aBurmeseDev removed the needs-triage This issue or PR still needs to be triaged. label Sep 18, 2024
Copy link

github-actions bot commented Oct 3, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation This is a problem with documentation.
Projects
None yet
Development

No branches or pull requests

2 participants