Skip to content

create_prompt

create_prompt(
    name: PromptName,
    *,
    config_overrides: Optional[BedrockAgentClientConfig] = None,
    description: Optional[PromptDescription] = None,
    customer_encryption_key_arn: Optional[KmsKeyArn] = None,
    default_variant: Optional[PromptVariantName] = None,
    variants: Optional[PromptVariantList] = None,
    client_token: Optional[ClientToken] = None,
    tags: Optional[TagsMap] = None,
) -> CreatePromptResponse

Creates a prompt in your prompt library that you can add to a flow. For more information, see Prompt management in Amazon Bedrock, Create a prompt using Prompt management and Prompt flows in Amazon Bedrock in the Amazon Bedrock User Guide.

Parameters:

  • name (PromptName) –

    A name for the prompt.

  • description (Optional[PromptDescription], default: None ) –

    A description for the prompt.

  • customer_encryption_key_arn (Optional[KmsKeyArn], default: None ) –

    The Amazon Resource Name (ARN) of the KMS key to encrypt the prompt.

  • default_variant (Optional[PromptVariantName], default: None ) –

    The name of the default variant for the prompt. This value must match the name field in the relevant PromptVariant object.

  • variants (Optional[PromptVariantList], default: None ) –

    A list of objects, each containing details about a variant of the prompt.

  • client_token (Optional[ClientToken], default: None ) –

    A unique, case-sensitive identifier to ensure that the API request completes no more than one time. If this token matches a previous request, Amazon Bedrock ignores the request, but does not return an error. For more information, see Ensuring idempotency.

  • tags (Optional[TagsMap], default: None ) –

    Any tags that you want to attach to the prompt. For more information, see Tagging resources in Amazon Bedrock.

Raises:

Source code in docs_src/capo_bedrock_agent/_services/bedrock_agent.py
def create_prompt(
    self,
    name: "capo_bedrock_agent.types.prompt_name.PromptName",
    *,
    config_overrides: Optional[BedrockAgentClientConfig] = None,
    description: Optional[
        "capo_bedrock_agent.types.prompt_description.PromptDescription"
    ] = None,
    customer_encryption_key_arn: Optional[
        "capo_bedrock_agent.types.kms_key_arn.KmsKeyArn"
    ] = None,
    default_variant: Optional[
        "capo_bedrock_agent.types.prompt_variant_name.PromptVariantName"
    ] = None,
    variants: Optional[
        "capo_bedrock_agent.types.prompt_variant_list.PromptVariantList"
    ] = None,
    client_token: Optional[
        "capo_bedrock_agent.types.client_token.ClientToken"
    ] = None,
    tags: Optional["capo_bedrock_agent.types.tags_map.TagsMap"] = None,
) -> "capo_bedrock_agent.types.create_prompt_response.CreatePromptResponse":
    """<p>Creates a prompt in your prompt library that you can add to a flow. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-management.html">Prompt management in Amazon Bedrock</a>, <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-management-create.html">Create a prompt using Prompt management</a> and <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/flows.html">Prompt flows in Amazon Bedrock</a> in the Amazon Bedrock User Guide.</p>

    Args:
        name: <p>A name for the prompt.</p>
        description: <p>A description for the prompt.</p>
        customer_encryption_key_arn: <p>The Amazon Resource Name (ARN) of the KMS key to encrypt the prompt.</p>
        default_variant: <p>The name of the default variant for the prompt. This value must match the <code>name</code> field in the relevant <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_PromptVariant.html">PromptVariant</a> object.</p>
        variants: <p>A list of objects, each containing details about a variant of the prompt.</p>
        client_token: <p>A unique, case-sensitive identifier to ensure that the API request completes no more than one time. If this token matches a previous request, Amazon Bedrock ignores the request, but does not return an error. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html">Ensuring idempotency</a>.</p>
        tags: <p>Any tags that you want to attach to the prompt. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/tagging.html">Tagging resources in Amazon Bedrock</a>.</p>

    Raises:
        capo_bedrock_agent.errors.access_denied_exception.AccessDeniedException: <p>The request is denied because of missing access permissions.</p>
        capo_bedrock_agent.errors.conflict_exception.ConflictException: <p>There was a conflict performing an operation.</p>
        capo_bedrock_agent.errors.internal_server_exception.InternalServerException: <p>An internal server error occurred. Retry your request.</p>
        capo_bedrock_agent.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The number of requests exceeds the service quota. Resubmit your request later.</p>
        capo_bedrock_agent.errors.throttling_exception.ThrottlingException: <p>The number of requests exceeds the limit. Resubmit your request later.</p>
        capo_bedrock_agent.errors.validation_exception.ValidationException: <p>Input validation failed. Check your request parameters and retry the request.</p>
        capo_bedrock_agent.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_bedrock_agent.types.create_prompt_request.CreatePromptRequest]",
    ) -> OperationResponse[
        "capo_bedrock_agent.types.create_prompt_response.CreatePromptResponse"
    ]:
        import capo_bedrock_agent._operations.amazon_bedrock_agent_build_time_lambda.create_prompt

        output, http_response = (
            capo_bedrock_agent._operations.amazon_bedrock_agent_build_time_lambda.create_prompt.create_prompt(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_bedrock_agent.types.create_prompt_request.CreatePromptRequest",
    ) -> dict[str, Any]:
        import capo_bedrock_agent.types.create_prompt_request

        return capo_bedrock_agent.types.create_prompt_request.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_bedrock_agent.types.create_prompt_response.CreatePromptResponse",
    ) -> dict[str, Any]:
        import capo_bedrock_agent.types.create_prompt_response

        return capo_bedrock_agent.types.create_prompt_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CreatePrompt", redact_input=_redact_input, redact_output=_redact_output
        ),
    )
    input_: capo_bedrock_agent.types.create_prompt_request.CreatePromptRequest = {
        "name": name
    }
    if description is not None:
        input_["description"] = description
    if customer_encryption_key_arn is not None:
        input_["customer_encryption_key_arn"] = customer_encryption_key_arn
    if default_variant is not None:
        input_["default_variant"] = default_variant
    if variants is not None:
        input_["variants"] = variants
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if tags is not None:
        input_["tags"] = tags

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output