ApplyGuardrail
The action to apply a guardrail.
For troubleshooting some of the common errors you might encounter when using the ApplyGuardrail
API,
see Troubleshooting Amazon Bedrock API Error Codes in the Amazon Bedrock User Guide
Request Syntax
POST /guardrail/guardrailIdentifier
/version/guardrailVersion
/apply HTTP/1.1
Content-type: application/json
{
"content": [
{ ... }
],
"source": "string
"
}
URI Request Parameters
The request uses the following URI parameters.
- guardrailIdentifier
-
The guardrail identifier used in the request to apply the guardrail.
Length Constraints: Minimum length of 0. Maximum length of 2048.
Pattern:
^(([a-z0-9]+)|(arn:aws(-[^:]+)?:bedrock:[a-z0-9-]{1,20}:[0-9]{12}:guardrail/[a-z0-9]+))$
Required: Yes
- guardrailVersion
-
The guardrail version used in the request to apply the guardrail.
Pattern:
^(([1-9][0-9]{0,7})|(DRAFT))$
Required: Yes
Request Body
The request accepts the following data in JSON format.
- content
-
The content details used in the request to apply the guardrail.
Type: Array of GuardrailContentBlock objects
Required: Yes
- source
-
The source of data used in the request to apply the guardrail.
Type: String
Valid Values:
INPUT | OUTPUT
Required: Yes
Response Syntax
HTTP/1.1 200
Content-type: application/json
{
"action": "string",
"assessments": [
{
"contentPolicy": {
"filters": [
{
"action": "string",
"confidence": "string",
"filterStrength": "string",
"type": "string"
}
]
},
"contextualGroundingPolicy": {
"filters": [
{
"action": "string",
"score": number,
"threshold": number,
"type": "string"
}
]
},
"invocationMetrics": {
"guardrailCoverage": {
"images": {
"guarded": number,
"total": number
},
"textCharacters": {
"guarded": number,
"total": number
}
},
"guardrailProcessingLatency": number,
"usage": {
"contentPolicyUnits": number,
"contextualGroundingPolicyUnits": number,
"sensitiveInformationPolicyFreeUnits": number,
"sensitiveInformationPolicyUnits": number,
"topicPolicyUnits": number,
"wordPolicyUnits": number
}
},
"sensitiveInformationPolicy": {
"piiEntities": [
{
"action": "string",
"match": "string",
"type": "string"
}
],
"regexes": [
{
"action": "string",
"match": "string",
"name": "string",
"regex": "string"
}
]
},
"topicPolicy": {
"topics": [
{
"action": "string",
"name": "string",
"type": "string"
}
]
},
"wordPolicy": {
"customWords": [
{
"action": "string",
"match": "string"
}
],
"managedWordLists": [
{
"action": "string",
"match": "string",
"type": "string"
}
]
}
}
],
"guardrailCoverage": {
"images": {
"guarded": number,
"total": number
},
"textCharacters": {
"guarded": number,
"total": number
}
},
"outputs": [
{
"text": "string"
}
],
"usage": {
"contentPolicyUnits": number,
"contextualGroundingPolicyUnits": number,
"sensitiveInformationPolicyFreeUnits": number,
"sensitiveInformationPolicyUnits": number,
"topicPolicyUnits": number,
"wordPolicyUnits": number
}
}
Response Elements
If the action is successful, the service sends back an HTTP 200 response.
The following data is returned in JSON format by the service.
- action
-
The action taken in the response from the guardrail.
Type: String
Valid Values:
NONE | GUARDRAIL_INTERVENED
- assessments
-
The assessment details in the response from the guardrail.
Type: Array of GuardrailAssessment objects
- guardrailCoverage
-
The guardrail coverage details in the apply guardrail response.
Type: GuardrailCoverage object
- outputs
-
The output details in the response from the guardrail.
Type: Array of GuardrailOutputContent objects
- usage
-
The usage details in the response from the guardrail.
Type: GuardrailUsage object
Errors
For information about the errors that are common to all actions, see Common Errors.
- AccessDeniedException
-
The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
HTTP Status Code: 403
- InternalServerException
-
An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
HTTP Status Code: 500
- ResourceNotFoundException
-
The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound in the Amazon Bedrock User Guide
HTTP Status Code: 404
- ServiceQuotaExceededException
-
Your request exceeds the service quota for your account. You can view your quotas at Viewing service quotas. You can resubmit your request later.
HTTP Status Code: 400
- ThrottlingException
-
Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
HTTP Status Code: 429
- ValidationException
-
The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
HTTP Status Code: 400
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: