Prompt

class aws_cdk.aws_bedrock_alpha.Prompt(scope, id, *, prompt_name, default_variant=None, description=None, kms_key=None, tags=None, variants=None)

Bases: PromptBase

(experimental) Class to create (or import) a Prompt with CDK.

Prompts are a specific set of inputs that guide Foundation Models (FMs) on Amazon Bedrock to generate an appropriate response or output for a given task or instruction. You can optimize the prompt for specific use cases and models.

See:

https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-management.html

Stability:

experimental

CloudformationResource:

AWS::Bedrock::Prompt

ExampleMetadata:

fixture=default infused

Example:

cmk = kms.Key(self, "cmk")
claude_model = bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0

variant1 = bedrock.PromptVariant.text(
    variant_name="variant1",
    model=claude_model,
    prompt_variables=["topic"],
    prompt_text="This is my first text prompt. Please summarize our conversation on: {{topic}}.",
    inference_configuration=bedrock.PromptInferenceConfiguration.text(
        temperature=1,
        top_p=0.999,
        max_tokens=2000
    )
)

prompt1 = bedrock.Prompt(self, "prompt1",
    prompt_name="prompt1",
    description="my first prompt",
    default_variant=variant1,
    variants=[variant1],
    kms_key=cmk
)

(experimental) ************************************************************************ CONSTRUCTOR ***********************************************************************.

Parameters:
  • scope (Construct)

  • id (str)

  • prompt_name (str) – (experimental) The name of the prompt. This will be used as the physical name of the prompt. Allowed Pattern: ^([0-9a-zA-Z][_-]?){1,100}$

  • default_variant (Optional[IPromptVariant]) – (experimental) The Prompt Variant that will be used by default. Default: - No default variant provided.

  • description (Optional[str]) – (experimental) A description of what the prompt does. Default: - No description provided. Maximum Length: 200

  • kms_key (Optional[IKey]) – (experimental) The KMS key that the prompt is encrypted with. Default: - AWS owned and managed key.

  • tags (Optional[Mapping[str, str]]) – (experimental) Tags to apply to the prompt. Default: - No tags applied.

  • variants (Optional[Sequence[IPromptVariant]]) – (experimental) The variants of your prompt. Variants can use different messages, models, or configurations so that you can compare their outputs to decide the best variant for your use case. Maximum of 1 variants. Default: - No additional variants provided.

Stability:

experimental

Methods

add_variant(variant)

(experimental) Adds a prompt variant to the prompt.

Parameters:

variant (IPromptVariant) –

  • The prompt variant to add.

Stability:

experimental

Throws:

ValidationError if adding the variant would exceed the maximum allowed variants

Return type:

None

apply_removal_policy(policy)

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you’ve removed it from the CDK application or because you’ve made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

Parameters:

policy (RemovalPolicy)

Return type:

None

create_version(description=None)

(experimental) Creates a prompt version, a static snapshot of your prompt that can be deployed to production.

Parameters:

description (Optional[str]) –

  • Optional description for the version.

Default:
  • No description provided

Return type:

PromptVersion

Returns:

A PromptVersion object containing the version details including ARN and version string

Stability:

experimental

grant_get(grantee)

(experimental) Grant the given identity permissions to get the prompt.

Parameters:

grantee (IGrantable) –

  • The IAM principal to grant permissions to.

Default:

  • Default grant configuration:

  • actions: [‘bedrock:GetPrompt’]

  • resourceArns: [this.promptArn]

Return type:

Grant

Returns:

An IAM Grant object representing the granted permissions

Stability:

experimental

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

PROPERTY_INJECTION_ID = '@aws-cdk.aws-bedrock-alpha.Prompt'
description

(experimental) The description of the prompt.

Stability:

experimental

env

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.

kms_key

(experimental) The KMS key that the prompt is encrypted with.

Stability:

experimental

node

The tree node.

prompt_arn

(experimental) The ARN of the prompt.

Stability:

experimental

Attribute:

true

Example:

"arn:aws:bedrock:us-east-1:123456789012:prompt/PROMPT12345"
prompt_id

(experimental) The ID of the prompt.

Stability:

experimental

Attribute:

true

Example:

"PROMPT12345"
prompt_name

(experimental) The name of the prompt.

Stability:

experimental

Attribute:

true

prompt_version

(experimental) The version of the prompt.

Stability:

experimental

Attribute:

true

stack

The stack in which this resource is defined.

variants

(experimental) The variants of the prompt.

Stability:

experimental

Static Methods

classmethod from_prompt_attributes(scope, id, *, prompt_arn, kms_key=None, prompt_version=None)

(experimental) Creates a Prompt reference from an existing prompt’s attributes.

Parameters:
  • scope (Construct) –

    • The construct scope.

  • id (str) –

    • Identifier of the construct.

  • prompt_arn (str) – (experimental) The ARN of the prompt.

  • kms_key (Optional[IKey]) – (experimental) Optional KMS encryption key associated with this prompt. Default: undefined - An AWS managed key is used

  • prompt_version (Optional[str]) – (experimental) The version of the prompt. Default: “DRAFT”

Default:
  • For attrs.promptVersion: ‘DRAFT’ if no explicit version is provided

Return type:

IPrompt

Returns:

An IPrompt reference to the existing prompt

Stability:

experimental

classmethod is_construct(x)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters:

x (Any) – Any object.

Return type:

bool

Returns:

true if x is an object created from a class which extends Construct.

classmethod is_owned_resource(construct)

Returns true if the construct was created by CDK, and false otherwise.

Parameters:

construct (IConstruct)

Return type:

bool

classmethod is_resource(construct)

Check whether the given construct is a Resource.

Parameters:

construct (IConstruct)

Return type:

bool