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

Support for Guardrails for Amazon Bedrock #25

Closed
brnaba-aws opened this issue Apr 25, 2024 · 4 comments
Closed

Support for Guardrails for Amazon Bedrock #25

brnaba-aws opened this issue Apr 25, 2024 · 4 comments

Comments

@brnaba-aws
Copy link
Contributor

brnaba-aws commented Apr 25, 2024

Guardrails for Amazon Bedrock since GA has changed the payload when using boto3.
This is the new payload content:

response = client.invoke_model(
    body=b'bytes'|file,
    contentType='string',
    accept='string',
    modelId='string',
    trace='ENABLED'|'DISABLED',
    guardrailIdentifier='string',
    guardrailVersion='string'
)

Changes in BedrockBase are needed. I'll also create a PR

@brnaba-aws
Copy link
Contributor Author

This is the PR : #26

@brnaba-aws
Copy link
Contributor Author

fix in #26

@MaverickScientist
Copy link

langchain-aws version used: 0.1.4

Have tried all the below scenarios:

  1.  guardrails={ "trace": False,
                 "accept": "application/json",
                 "contentType": "application/json",
                 "modelId": model_id,
     "guardrailIdentifier": "identifier", --> "id" of the Guardrail I created using Bedrock Console.
     "guardrailVersion": "5"}
    
  2. guardrail_kwargs={"guardrailIdentifier": "identifier", "guardrailVersion": "5"}

  3. guardrails={ "trace": False,
    "guardrailIdentifier": "xxxx" --> the ARN of the guardrail I created using Bedrock Console.
    "guardrailVersion": "5"}

  4. guardrails={ "trace": False,
    "guardrailIdentifier": "identifier", --> "id" of the Guardrail I created using Bedrock Console.
    "guardrailVersion": "5"}

Adding the exception below:

  1. 2024-05-19 15:27:29,346 ERROR root ScriptRunner.scriptThread : Error Occured: Error raised by bedrock service: Parameter validation failed:
    Unknown parameter in input: "guardrailIdentifier", must be one of: body, contentType, accept, modelId
    Unknown parameter in input: "guardrailVersion", must be one of: body, contentType, accept, modelId

Tried the alternative as below:
guardrails={ "trace": False,
"id": "identifier", --> "id" of the Guardrail I created using Bedrock Console.
"version": "5"}

Got the exception as below:

Error Occured: Guardrails must be a dictionary with 'guardrailIdentifier' and 'guardrailVersion' keys.

The below option doesn't give any error but eventually has no relevance as the identifier value is None:

guardrails={ "trace": False,
"guardrailIdentifier": None
"guardrailVersion": "5"}

Please suggest the correct way of passing the guardrail parameter for it to work.

PS: I have tested the Guardrail from Bedrock Console and it works like a charm.

@brnaba-aws
Copy link
Contributor Author

Which version of boto3 are you using?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants