BedrockRuntime / Client / apply_guardrail
apply_guardrail#
- BedrockRuntime.Client.apply_guardrail(**kwargs)#
- The action to apply a guardrail. - See also: AWS API Documentation - Request Syntax- response = client.apply_guardrail( guardrailIdentifier='string', guardrailVersion='string', source='INPUT'|'OUTPUT', content=[ { 'text': { 'text': 'string', 'qualifiers': [ 'grounding_source'|'query'|'guard_content', ] } }, ] ) - Parameters:
- guardrailIdentifier (string) – - [REQUIRED] - The guardrail identifier used in the request to apply the guardrail. 
- guardrailVersion (string) – - [REQUIRED] - The guardrail version used in the request to apply the guardrail. 
- source (string) – - [REQUIRED] - The source of data used in the request to apply the guardrail. 
- content (list) – - [REQUIRED] - The content details used in the request to apply the guardrail. - (dict) – - The content block to be evaluated by the guardrail. - Note- This is a Tagged Union structure. Only one of the following top level keys can be set: - text.- text (dict) – - Text within content block to be evaluated by the guardrail. - text (string) – [REQUIRED] - The input text details to be evaluated by the guardrail. 
- qualifiers (list) – - The qualifiers describing the text block. - (string) – 
 
 
 
 
 
- Return type:
- dict 
- Returns:
- Response Syntax- { 'usage': { 'topicPolicyUnits': 123, 'contentPolicyUnits': 123, 'wordPolicyUnits': 123, 'sensitiveInformationPolicyUnits': 123, 'sensitiveInformationPolicyFreeUnits': 123, 'contextualGroundingPolicyUnits': 123 }, 'action': 'NONE'|'GUARDRAIL_INTERVENED', 'outputs': [ { 'text': 'string' }, ], 'assessments': [ { 'topicPolicy': { 'topics': [ { 'name': 'string', 'type': 'DENY', 'action': 'BLOCKED' }, ] }, 'contentPolicy': { 'filters': [ { 'type': 'INSULTS'|'HATE'|'SEXUAL'|'VIOLENCE'|'MISCONDUCT'|'PROMPT_ATTACK', 'confidence': 'NONE'|'LOW'|'MEDIUM'|'HIGH', 'action': 'BLOCKED' }, ] }, 'wordPolicy': { 'customWords': [ { 'match': 'string', 'action': 'BLOCKED' }, ], 'managedWordLists': [ { 'match': 'string', 'type': 'PROFANITY', 'action': 'BLOCKED' }, ] }, 'sensitiveInformationPolicy': { 'piiEntities': [ { 'match': 'string', 'type': 'ADDRESS'|'AGE'|'AWS_ACCESS_KEY'|'AWS_SECRET_KEY'|'CA_HEALTH_NUMBER'|'CA_SOCIAL_INSURANCE_NUMBER'|'CREDIT_DEBIT_CARD_CVV'|'CREDIT_DEBIT_CARD_EXPIRY'|'CREDIT_DEBIT_CARD_NUMBER'|'DRIVER_ID'|'EMAIL'|'INTERNATIONAL_BANK_ACCOUNT_NUMBER'|'IP_ADDRESS'|'LICENSE_PLATE'|'MAC_ADDRESS'|'NAME'|'PASSWORD'|'PHONE'|'PIN'|'SWIFT_CODE'|'UK_NATIONAL_HEALTH_SERVICE_NUMBER'|'UK_NATIONAL_INSURANCE_NUMBER'|'UK_UNIQUE_TAXPAYER_REFERENCE_NUMBER'|'URL'|'USERNAME'|'US_BANK_ACCOUNT_NUMBER'|'US_BANK_ROUTING_NUMBER'|'US_INDIVIDUAL_TAX_IDENTIFICATION_NUMBER'|'US_PASSPORT_NUMBER'|'US_SOCIAL_SECURITY_NUMBER'|'VEHICLE_IDENTIFICATION_NUMBER', 'action': 'ANONYMIZED'|'BLOCKED' }, ], 'regexes': [ { 'name': 'string', 'match': 'string', 'regex': 'string', 'action': 'ANONYMIZED'|'BLOCKED' }, ] }, 'contextualGroundingPolicy': { 'filters': [ { 'type': 'GROUNDING'|'RELEVANCE', 'threshold': 123.0, 'score': 123.0, 'action': 'BLOCKED'|'NONE' }, ] } }, ] } - Response Structure- (dict) – - usage (dict) – - The usage details in the response from the guardrail. - topicPolicyUnits (integer) – - The topic policy units processed by the guardrail. 
- contentPolicyUnits (integer) – - The content policy units processed by the guardrail. 
- wordPolicyUnits (integer) – - The word policy units processed by the guardrail. 
- sensitiveInformationPolicyUnits (integer) – - The sensitive information policy units processed by the guardrail. 
- sensitiveInformationPolicyFreeUnits (integer) – - The sensitive information policy free units processed by the guardrail. 
- contextualGroundingPolicyUnits (integer) – - The contextual grounding policy units processed by the guardrail. 
 
- action (string) – - The action taken in the response from the guardrail. 
- outputs (list) – - The output details in the response from the guardrail. - (dict) – - The output content produced by the guardrail. - text (string) – - The specific text for the output content produced by the guardrail. 
 
 
- assessments (list) – - The assessment details in the response from the guardrail. - (dict) – - A behavior assessment of the guardrail policies used in a call to the Converse API. - topicPolicy (dict) – - The topic policy. - topics (list) – - The topics in the assessment. - (dict) – - Information about a topic guardrail. - name (string) – - The name for the guardrail. 
- type (string) – - The type behavior that the guardrail should perform when the model detects the topic. 
- action (string) – - The action the guardrail should take when it intervenes on a topic. 
 
 
 
- contentPolicy (dict) – - The content policy. - filters (list) – - The content policy filters. - (dict) – - The content filter for a guardrail. - type (string) – - The guardrail type. 
- confidence (string) – - The guardrail confidence. 
- action (string) – - The guardrail action. 
 
 
 
- wordPolicy (dict) – - The word policy. - customWords (list) – - Custom words in the assessment. - (dict) – - A custom word configured in a guardrail. - match (string) – - The match for the custom word. 
- action (string) – - The action for the custom word. 
 
 
- managedWordLists (list) – - Managed word lists in the assessment. - (dict) – - A managed word configured in a guardrail. - match (string) – - The match for the managed word. 
- type (string) – - The type for the managed word. 
- action (string) – - The action for the managed word. 
 
 
 
- sensitiveInformationPolicy (dict) – - The sensitive information policy. - piiEntities (list) – - The PII entities in the assessment. - (dict) – - A Personally Identifiable Information (PII) entity configured in a guardrail. - match (string) – - The PII entity filter match. 
- type (string) – - The PII entity filter type. 
- action (string) – - The PII entity filter action. 
 
 
- regexes (list) – - The regex queries in the assessment. - (dict) – - A Regex filter configured in a guardrail. - name (string) – - The regex filter name. 
- match (string) – - The regesx filter match. 
- regex (string) – - The regex query. 
- action (string) – - The region filter action. 
 
 
 
- contextualGroundingPolicy (dict) – - The contextual grounding policy used for the guardrail assessment. - filters (list) – - The filter details for the guardrails contextual grounding filter. - (dict) – - The details for the guardrails contextual grounding filter. - type (string) – - The contextual grounding filter type. 
- threshold (float) – - The threshold used by contextual grounding filter to determine whether the content is grounded or not. 
- score (float) – - The score generated by contextual grounding filter. 
- action (string) – - The action performed by the guardrails contextual grounding filter. 
 
 
 
 
 
 
 
 - Exceptions- BedrockRuntime.Client.exceptions.AccessDeniedException
- BedrockRuntime.Client.exceptions.ResourceNotFoundException
- BedrockRuntime.Client.exceptions.ThrottlingException
- BedrockRuntime.Client.exceptions.InternalServerException
- BedrockRuntime.Client.exceptions.ValidationException
- BedrockRuntime.Client.exceptions.ServiceQuotaExceededException