Skip to content

update_guardrail async

update_guardrail(
    guardrail_identifier: GuardrailIdentifier,
    name: GuardrailName,
    blocked_input_messaging: GuardrailBlockedMessaging,
    blocked_outputs_messaging: GuardrailBlockedMessaging,
    *,
    config_overrides: Optional[AsyncBedrockClientConfig] = None,
    description: Optional[GuardrailDescription] = None,
    topic_policy_config: Optional[GuardrailTopicPolicyConfig] = None,
    content_policy_config: Optional[GuardrailContentPolicyConfig] = None,
    word_policy_config: Optional[GuardrailWordPolicyConfig] = None,
    sensitive_information_policy_config: Optional[
        GuardrailSensitiveInformationPolicyConfig
    ] = None,
    contextual_grounding_policy_config: Optional[
        GuardrailContextualGroundingPolicyConfig
    ] = None,
    automated_reasoning_policy_config: Optional[
        GuardrailAutomatedReasoningPolicyConfig
    ] = None,
    cross_region_config: Optional[GuardrailCrossRegionConfig] = None,
    kms_key_id: Optional[KmsKeyId] = None,
) -> UpdateGuardrailResponse

Updates a guardrail with the values you specify.

  • Specify a name and optional description.

  • Specify messages for when the guardrail successfully blocks a prompt or a model response in the blockedInputMessaging and blockedOutputsMessaging fields.

  • Specify topics for the guardrail to deny in the topicPolicyConfig object. Each GuardrailTopicConfig object in the topicsConfig list pertains to one topic.

    • Give a name and description so that the guardrail can properly identify the topic.

    • Specify DENY in the type field.

    • (Optional) Provide up to five prompts that you would categorize as belonging to the topic in the examples list.

  • Specify filter strengths for the harmful categories defined in Amazon Bedrock in the contentPolicyConfig object. Each GuardrailContentFilterConfig object in the filtersConfig list pertains to a harmful category. For more information, see Content filters. For more information about the fields in a content filter, see GuardrailContentFilterConfig.

    • Specify the category in the type field.

    • Specify the strength of the filter for prompts in the inputStrength field and for model responses in the strength field of the GuardrailContentFilterConfig.

  • (Optional) For security, include the ARN of a KMS key in the kmsKeyId field.

Parameters:

Raises:

Source code in docs_src/capo_bedrock/_services/async_bedrock.py
async def update_guardrail(
    self,
    guardrail_identifier: "capo_bedrock.types.guardrail_identifier.GuardrailIdentifier",
    name: "capo_bedrock.types.guardrail_name.GuardrailName",
    blocked_input_messaging: "capo_bedrock.types.guardrail_blocked_messaging.GuardrailBlockedMessaging",
    blocked_outputs_messaging: "capo_bedrock.types.guardrail_blocked_messaging.GuardrailBlockedMessaging",
    *,
    config_overrides: Optional[AsyncBedrockClientConfig] = None,
    description: Optional[
        "capo_bedrock.types.guardrail_description.GuardrailDescription"
    ] = None,
    topic_policy_config: Optional[
        "capo_bedrock.types.guardrail_topic_policy_config.GuardrailTopicPolicyConfig"
    ] = None,
    content_policy_config: Optional[
        "capo_bedrock.types.guardrail_content_policy_config.GuardrailContentPolicyConfig"
    ] = None,
    word_policy_config: Optional[
        "capo_bedrock.types.guardrail_word_policy_config.GuardrailWordPolicyConfig"
    ] = None,
    sensitive_information_policy_config: Optional[
        "capo_bedrock.types.guardrail_sensitive_information_policy_config.GuardrailSensitiveInformationPolicyConfig"
    ] = None,
    contextual_grounding_policy_config: Optional[
        "capo_bedrock.types.guardrail_contextual_grounding_policy_config.GuardrailContextualGroundingPolicyConfig"
    ] = None,
    automated_reasoning_policy_config: Optional[
        "capo_bedrock.types.guardrail_automated_reasoning_policy_config.GuardrailAutomatedReasoningPolicyConfig"
    ] = None,
    cross_region_config: Optional[
        "capo_bedrock.types.guardrail_cross_region_config.GuardrailCrossRegionConfig"
    ] = None,
    kms_key_id: Optional["capo_bedrock.types.kms_key_id.KmsKeyId"] = None,
) -> "capo_bedrock.types.update_guardrail_response.UpdateGuardrailResponse":
    """<p>Updates a guardrail with the values you specify.</p> <ul> <li> <p>Specify a <code>name</code> and optional <code>description</code>.</p> </li> <li> <p>Specify messages for when the guardrail successfully blocks a prompt or a model response in the <code>blockedInputMessaging</code> and <code>blockedOutputsMessaging</code> fields.</p> </li> <li> <p>Specify topics for the guardrail to deny in the <code>topicPolicyConfig</code> object. Each <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_GuardrailTopicConfig.html">GuardrailTopicConfig</a> object in the <code>topicsConfig</code> list pertains to one topic.</p> <ul> <li> <p>Give a <code>name</code> and <code>description</code> so that the guardrail can properly identify the topic.</p> </li> <li> <p>Specify <code>DENY</code> in the <code>type</code> field.</p> </li> <li> <p>(Optional) Provide up to five prompts that you would categorize as belonging to the topic in the <code>examples</code> list.</p> </li> </ul> </li> <li> <p>Specify filter strengths for the harmful categories defined in Amazon Bedrock in the <code>contentPolicyConfig</code> object. Each <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_GuardrailContentFilterConfig.html">GuardrailContentFilterConfig</a> object in the <code>filtersConfig</code> list pertains to a harmful category. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-content-filters">Content filters</a>. For more information about the fields in a content filter, see <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_GuardrailContentFilterConfig.html">GuardrailContentFilterConfig</a>.</p> <ul> <li> <p>Specify the category in the <code>type</code> field.</p> </li> <li> <p>Specify the strength of the filter for prompts in the <code>inputStrength</code> field and for model responses in the <code>strength</code> field of the <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_GuardrailContentFilterConfig.html">GuardrailContentFilterConfig</a>.</p> </li> </ul> </li> <li> <p>(Optional) For security, include the ARN of a KMS key in the <code>kmsKeyId</code> field.</p> </li> </ul>

    Args:
        guardrail_identifier: <p>The unique identifier of the guardrail. This can be an ID or the ARN.</p>
        name: <p>A name for the guardrail.</p>
        description: <p>A description of the guardrail.</p>
        topic_policy_config: <p>The topic policy to configure for the guardrail.</p>
        content_policy_config: <p>The content policy to configure for the guardrail.</p>
        word_policy_config: <p>The word policy to configure for the guardrail.</p>
        sensitive_information_policy_config: <p>The sensitive information policy to configure for the guardrail.</p>
        contextual_grounding_policy_config: <p>The contextual grounding policy configuration used to update a guardrail.</p>
        automated_reasoning_policy_config: <p>Updated configuration for Automated Reasoning policies associated with the guardrail.</p>
        cross_region_config: <p>The system-defined guardrail profile that you're using with your guardrail. Guardrail profiles define the destination Amazon Web Services Regions where guardrail inference requests can be automatically routed.</p> <p>For more information, see the <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-cross-region.html">Amazon Bedrock User Guide</a>.</p>
        blocked_input_messaging: <p>The message to return when the guardrail blocks a prompt.</p>
        blocked_outputs_messaging: <p>The message to return when the guardrail blocks a model response.</p>
        kms_key_id: <p>The ARN of the KMS key with which to encrypt the guardrail.</p>

    Raises:
        capo_bedrock.errors.access_denied_exception.AccessDeniedException: <p>The request is denied because of missing access permissions.</p>
        capo_bedrock.errors.conflict_exception.ConflictException: <p>Error occurred because of a conflict while performing an operation.</p>
        capo_bedrock.errors.internal_server_exception.InternalServerException: <p>An internal server error occurred. Retry your request.</p>
        capo_bedrock.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource Amazon Resource Name (ARN) was not found. Check the Amazon Resource Name (ARN) and try your request again.</p>
        capo_bedrock.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The number of requests exceeds the service quota. Resubmit your request later.</p>
        capo_bedrock.errors.throttling_exception.ThrottlingException: <p>The number of requests exceeds the limit. Resubmit your request later.</p>
        capo_bedrock.errors.validation_exception.ValidationException: <p>Input validation failed. Check your request parameters and retry the request.</p>
        capo_bedrock.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_bedrock.types.update_guardrail_request.UpdateGuardrailRequest]",
    ) -> AsyncOperationResponse[
        "capo_bedrock.types.update_guardrail_response.UpdateGuardrailResponse"
    ]:
        import capo_bedrock._operations.amazon_bedrock_control_plane_service.update_guardrail

        (
            output,
            http_response,
        ) = await capo_bedrock._operations.amazon_bedrock_control_plane_service.update_guardrail.async_update_guardrail(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_bedrock.types.update_guardrail_request.UpdateGuardrailRequest",
    ) -> dict[str, Any]:
        import capo_bedrock.types.update_guardrail_request

        return capo_bedrock.types.update_guardrail_request.redact_sensitive(input_)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("UpdateGuardrail", redact_input=_redact_input),
    )
    input_: capo_bedrock.types.update_guardrail_request.UpdateGuardrailRequest = {
        "guardrail_identifier": guardrail_identifier,
        "name": name,
        "blocked_input_messaging": blocked_input_messaging,
        "blocked_outputs_messaging": blocked_outputs_messaging,
    }
    if description is not None:
        input_["description"] = description
    if topic_policy_config is not None:
        input_["topic_policy_config"] = topic_policy_config
    if content_policy_config is not None:
        input_["content_policy_config"] = content_policy_config
    if word_policy_config is not None:
        input_["word_policy_config"] = word_policy_config
    if sensitive_information_policy_config is not None:
        input_["sensitive_information_policy_config"] = (
            sensitive_information_policy_config
        )
    if contextual_grounding_policy_config is not None:
        input_["contextual_grounding_policy_config"] = (
            contextual_grounding_policy_config
        )
    if automated_reasoning_policy_config is not None:
        input_["automated_reasoning_policy_config"] = (
            automated_reasoning_policy_config
        )
    if cross_region_config is not None:
        input_["cross_region_config"] = cross_region_config
    if kms_key_id is not None:
        input_["kms_key_id"] = kms_key_id

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output