CreateGuardrail
Creates a guardrail to detect and filter harmful content in your generative AI application.
Amazon Bedrock Guardrails provides the following safeguards (also known as policies) to detect and filter harmful content:
-
Content filters - Detect and filter harmful text or image content in input prompts or model responses. Filtering is done based on detection of certain predefined harmful content categories: Hate, Insults, Sexual, Violence, Misconduct and Prompt Attack. You also can adjust the filter strength for each of these categories.
-
Denied topics - Define a set of topics that are undesirable in the context of your application. The filter will help block them if detected in user queries or model responses.
-
Word filters - Configure filters to help block undesirable words, phrases, and profanity (exact match). Such words can include offensive terms, competitor names, etc.
-
Sensitive information filters - Configure filters to help block or mask sensitive information, such as personally identifiable information (PII), or custom regex in user inputs and model responses. Blocking or masking is done based on probabilistic detection of sensitive information in standard formats in entities such as SSN number, Date of Birth, address, etc. This also allows configuring regular expression based detection of patterns for identifiers.
-
Contextual grounding check - Help detect and filter hallucinations in model responses based on grounding in a source and relevance to the user query.
For more information, see How Amazon Bedrock Guardrails works.
Request Syntax
POST /guardrails HTTP/1.1
Content-type: application/json
{
"blockedInputMessaging": "string
",
"blockedOutputsMessaging": "string
",
"clientRequestToken": "string
",
"contentPolicyConfig": {
"filtersConfig": [
{
"inputAction": "string
",
"inputEnabled": boolean
,
"inputModalities": [ "string
" ],
"inputStrength": "string
",
"outputAction": "string
",
"outputEnabled": boolean
,
"outputModalities": [ "string
" ],
"outputStrength": "string
",
"type": "string
"
}
],
"tierConfig": {
"tierName": "string
"
}
},
"contextualGroundingPolicyConfig": {
"filtersConfig": [
{
"action": "string
",
"enabled": boolean
,
"threshold": number
,
"type": "string
"
}
]
},
"crossRegionConfig": {
"guardrailProfileIdentifier": "string
"
},
"description": "string
",
"kmsKeyId": "string
",
"name": "string
",
"sensitiveInformationPolicyConfig": {
"piiEntitiesConfig": [
{
"action": "string
",
"inputAction": "string
",
"inputEnabled": boolean
,
"outputAction": "string
",
"outputEnabled": boolean
,
"type": "string
"
}
],
"regexesConfig": [
{
"action": "string
",
"description": "string
",
"inputAction": "string
",
"inputEnabled": boolean
,
"name": "string
",
"outputAction": "string
",
"outputEnabled": boolean
,
"pattern": "string
"
}
]
},
"tags": [
{
"key": "string
",
"value": "string
"
}
],
"topicPolicyConfig": {
"tierConfig": {
"tierName": "string
"
},
"topicsConfig": [
{
"definition": "string
",
"examples": [ "string
" ],
"inputAction": "string
",
"inputEnabled": boolean
,
"name": "string
",
"outputAction": "string
",
"outputEnabled": boolean
,
"type": "string
"
}
]
},
"wordPolicyConfig": {
"managedWordListsConfig": [
{
"inputAction": "string
",
"inputEnabled": boolean
,
"outputAction": "string
",
"outputEnabled": boolean
,
"type": "string
"
}
],
"wordsConfig": [
{
"inputAction": "string
",
"inputEnabled": boolean
,
"outputAction": "string
",
"outputEnabled": boolean
,
"text": "string
"
}
]
}
}
URI Request Parameters
The request does not use any URI parameters.
Request Body
The request accepts the following data in JSON format.
- blockedInputMessaging
-
The message to return when the guardrail blocks a prompt.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 500.
Required: Yes
- blockedOutputsMessaging
-
The message to return when the guardrail blocks a model response.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 500.
Required: Yes
- clientRequestToken
-
A unique, case-sensitive identifier to ensure that the API request completes no more than once. If this token matches a previous request, Amazon Bedrock ignores the request, but does not return an error. For more information, see Ensuring idempotency in the Amazon S3 User Guide.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 256.
Pattern:
[a-zA-Z0-9](-*[a-zA-Z0-9])*
Required: No
- contentPolicyConfig
-
The content filter policies to configure for the guardrail.
Type: GuardrailContentPolicyConfig object
Required: No
- contextualGroundingPolicyConfig
-
The contextual grounding policy configuration used to create a guardrail.
Type: GuardrailContextualGroundingPolicyConfig object
Required: No
- crossRegionConfig
-
The system-defined guardrail profile that you're using with your guardrail. Guardrail profiles define the destination AWS Regions where guardrail inference requests can be automatically routed.
For more information, see the Amazon Bedrock User Guide.
Type: GuardrailCrossRegionConfig object
Required: No
- description
-
A description of the guardrail.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 200.
Required: No
- kmsKeyId
-
The ARN of the AWS KMS key that you use to encrypt the guardrail.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 2048.
Pattern:
(arn:aws(-[^:]+)?:kms:[a-zA-Z0-9-]*:[0-9]{12}:((key/[a-zA-Z0-9-]{36})|(alias/[a-zA-Z0-9-_/]+)))|([a-zA-Z0-9-]{36})|(alias/[a-zA-Z0-9-_/]+)
Required: No
- name
-
The name to give the guardrail.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 50.
Pattern:
[0-9a-zA-Z-_]+
Required: Yes
- sensitiveInformationPolicyConfig
-
The sensitive information policy to configure for the guardrail.
Type: GuardrailSensitiveInformationPolicyConfig object
Required: No
-
The tags that you want to attach to the guardrail.
Type: Array of Tag objects
Array Members: Minimum number of 0 items. Maximum number of 200 items.
Required: No
- topicPolicyConfig
-
The topic policies to configure for the guardrail.
Type: GuardrailTopicPolicyConfig object
Required: No
- wordPolicyConfig
-
The word policy you configure for the guardrail.
Type: GuardrailWordPolicyConfig object
Required: No
Response Syntax
HTTP/1.1 202
Content-type: application/json
{
"createdAt": "string",
"guardrailArn": "string",
"guardrailId": "string",
"version": "string"
}
Response Elements
If the action is successful, the service sends back an HTTP 202 response.
The following data is returned in JSON format by the service.
- createdAt
-
The time at which the guardrail was created.
Type: Timestamp
- guardrailArn
-
The ARN of the guardrail.
Type: String
Length Constraints: Minimum length of 0. Maximum length of 2048.
Pattern:
arn:aws(-[^:]+)?:bedrock:[a-z0-9-]{1,20}:[0-9]{12}:guardrail/[a-z0-9]+
- guardrailId
-
The unique identifier of the guardrail that was created.
Type: String
Length Constraints: Minimum length of 0. Maximum length of 64.
Pattern:
[a-z0-9]+
- version
-
The version of the guardrail that was created. This value will always be
DRAFT
.Type: String
Length Constraints: Fixed length of 5.
Pattern:
DRAFT
Errors
For information about the errors that are common to all actions, see Common Errors.
- AccessDeniedException
-
The request is denied because of missing access permissions.
HTTP Status Code: 403
- ConflictException
-
Error occurred because of a conflict while performing an operation.
HTTP Status Code: 400
- InternalServerException
-
An internal server error occurred. Retry your request.
HTTP Status Code: 500
- ResourceNotFoundException
-
The specified resource Amazon Resource Name (ARN) was not found. Check the Amazon Resource Name (ARN) and try your request again.
HTTP Status Code: 404
- ServiceQuotaExceededException
-
The number of requests exceeds the service quota. Resubmit your request later.
HTTP Status Code: 400
- ThrottlingException
-
The number of requests exceeds the limit. Resubmit your request later.
HTTP Status Code: 429
- TooManyTagsException
-
The request contains more tags than can be associated with a resource (50 tags per resource). The maximum number of tags includes both existing tags and those included in your current request.
HTTP Status Code: 400
- ValidationException
-
Input validation failed. Check your request parameters and retry the request.
HTTP Status Code: 400
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: