ApplyGuardrail - Amazon Bedrock

ApplyGuardrail

The action to apply a guardrail.

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", "type": "string" } ] }, "contextualGroundingPolicy": { "filters": [ { "action": "string", "score": number, "threshold": number, "type": "string" } ] }, "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" } ] } } ], "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

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 of missing access permissions.

HTTP Status Code: 403

InternalServerException

An internal server error occurred. Retry your request.

HTTP Status Code: 500

ResourceNotFoundException

The specified resource ARN was not found. Check the ARN and try your request again.

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 throttled because of service-wide limitations. Resubmit your request later or in a different region. You can also purchase Provisioned Throughput to increase the rate or number of tokens you can process.

HTTP Status Code: 429

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: