-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
ApplyGuardrail doesnt apply ContextualGrouding on boto3 API #4292
Comments
Thanks for reaching out. The create_guardrail and apply_guardrail commands make requests to the CreateGuardrail and ApplyGuardrail APIs, so if the behavior is not working as expected then that could be an issue with the APIs rather than the SDK directly. Based on these docs, I would expect to see Can also you confirm that you're referencing the correct guardrail in your |
Greetings! It looks like this issue hasn’t been active in longer than five days. We encourage you to check if this is still an issue in the latest release. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or upvote with a reaction on the initial post to prevent automatic closure. If the issue is already closed, please feel free to open a new one. |
Hi @tim-finnigan, sorry for the wait. I haven't been able to use Guardrails using
And is giving me this:
And here is the
|
Thanks for following up. Is your guardrail also in the us-east-1 region? I found a comment (aws/aws-sdk-js-v3#6482 (comment)) from someone using the JS SDK saying that using the wrong region was causing the same error. Are you able to invoke the model successfully without specifying a guardrail? Also I didn't see the |
Sorry again for the wait. It appears that both the model and the guardrail are in import boto3
session = boto3.Session(aws_access_key_id='KEY,
aws_secret_access_key='KEY',
aws_session_token='TOKEN'
)
bedrock = session.client('bedrock','us-east-1')
bedrock_runtime = session.client('bedrock-runtime','us-east-1') Yes, when invoking the model without guardrails it work fine, but when calling with the guardrail it gives the ValidationException.
|
Thanks for following up — can you share full debug logs (with any sensitive info redacted) when that error occurs? If we can see that API response then we can share that with the Bedrock team for further review. |
I also got the same error message. The below snippet from documentation clearly states the possibility of error and I used guardrailVersion variable along with the invoke_model api
Using guardrailVersion resolved the error. Below is a snippet from the boto3 docs |
Describe the bug
Setting up a Guardrail with only ContextualGrounding Policy (threshold of 0,8 on both scores) and then running ApplyGuardrail passing each qualifier type doesnt work, but it does on Console. Images for reference:
Boto3
Console
Regression Issue
Expected Behavior
Guardrail should work the same on boto3 and console.
Current Behavior
ContextualGrouding doesn't work the on boto3
Reproduction Steps
response = bedrock.create_guardrail(
name='testing_guardrail_10',
blockedInputMessaging='Input blocked!',
blockedOutputsMessaging='Output blocked!',
contextualGroundingPolicyConfig=
{
'filtersConfig':
[
{
'type': 'GROUNDING',
'threshold': 0.8
},
{
'type': 'RELEVANCE',
'threshold': 0.8
}
]
}
)
source = 'London is the capital of UK. Tokyo is the capital of Japan'
input = 'What is 2+2?'
output = 'Tokyo is the capital city of Japan, while some sources list Nagoya or Osaka as the largest city by population. London is the capital city of the United Kingdom, but some sources list Birmingham as the largest city by population.'
bedrock_runtime.apply_guardrail(
guardrailIdentifier='tvc6ts6fnjrh',
guardrailVersion='DRAFT',
source='INPUT',
content=[
{
'text': {
'text': source,
'qualifiers': ['grounding_source']
}
},
{
'text': {
'text': input,
'qualifiers': ['query']
}
},
{
'text': {
'text': output,
'qualifiers': ['guard_content']
}
}
]
)
The text was updated successfully, but these errors were encountered: