> **Experimental**
>
> `@aws-cdk/aws-bedrock-alpha` is an [**experimental**](/stability) (alpha) package: its API may change in any release, without a major version bump.
# Prompt

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.

Extends: Construct › Resource › PromptBase › Prompt
Implements: IPrompt, IResource, IEnvironmentAware, IConstruct, IDependable

- Stability: [Experimental](/cdk/api/stability.html)
- CloudFormation: [`AWS::Bedrock::Prompt`](https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-management.html)
- Source: [`bedrock/prompts/prompt.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0-alpha.0/packages/@aws-cdk/aws-bedrock-alpha/bedrock/prompts/prompt.ts#L180)

## Example

```ts
const cmk = new kms.Key(this, 'cmk', {});
const claudeModel = bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0;

const variant1 = bedrock.PromptVariant.text({
  variantName: 'variant1',
  model: claudeModel,
  promptVariables: ['topic'],
  promptText: 'This is my first text prompt. Please summarize our conversation on: {{topic}}.',
  inferenceConfiguration: bedrock.PromptInferenceConfiguration.text({
    temperature: 1.0,
    topP: 0.999,
    maxTokens: 2000,
  }),
});

const prompt1 = new bedrock.Prompt(this, 'prompt1', {
  promptName: 'prompt1',
  description: 'my first prompt',
  defaultVariant: variant1,
  variants: [variant1],
  kmsKey: cmk,
});
```

## Initializer

```ts
new Prompt(scope: Construct, id: string, props: PromptProps)
```

## Construct Props

- `defaultVariant`: [IPromptVariant](/cdk/api/v2/docs/@aws-cdk_aws-bedrock-alpha.IPromptVariant.html) = No default variant provided. — The Prompt Variant that will be used by default.

- `description`: string = No description provided. Maximum Length: 200 — A description of what the prompt does.

  **Default:** No description provided. Maximum Length: 200

- `kmsKey`: [IKey](/cdk/api/v2/docs/aws-cdk-lib.aws_kms.IKey.html) = AWS owned and managed key. — The KMS key that the prompt is encrypted with.

- `promptName`: string (required) — The name of the prompt.

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

- `tags`: { [key: string]: string } = No tags applied. — Tags to apply to the prompt.

- `variants`: [IPromptVariant](/cdk/api/v2/docs/@aws-cdk_aws-bedrock-alpha.IPromptVariant.html)[] = No additional variants provided. — 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.

## Properties

- `description`: string — The description of the prompt.

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) (required) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `kmsKey`: [IKey](/cdk/api/v2/docs/aws-cdk-lib.aws_kms.IKey.html) — The KMS key that the prompt is encrypted with.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) (required) — The tree node.

- `promptArn`: string (required) — The ARN of the prompt.

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

- `promptId`: string (required) — The ID of the prompt.

  ```ts
  "PROMPT12345"
  ```

- `promptName`: string (required) — The name of the prompt.

- `promptVersion`: string (required) — The version of the prompt.

- `PROPERTY_INJECTION_ID`: string (required) (static) — Uniquely identifies this class.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) (required) — The stack in which this resource is defined.

- `variants`: [IPromptVariant](/cdk/api/v2/docs/@aws-cdk_aws-bedrock-alpha.IPromptVariant.html)[] (required) — The variants of the prompt.

## Methods

- `addVariant(variant: IPromptVariant): void` — Adds a prompt variant to the prompt.

  **Parameters**

  - `variant` — - The prompt variant to add.

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — 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`).

- `createVersion(description?: string): PromptVersion` — Creates a prompt version, a static snapshot of your prompt that can be deployed to production.

  **Parameters**

  - `description` — - Optional description for the version.

  **Returns:** A PromptVersion object containing the version details including ARN and version string

- `fromPromptAttributes(scope: Construct, id: string, attrs: PromptAttributes): IPrompt` (static) — Creates a Prompt reference from an existing prompt's attributes.

  **Parameters**

  - `scope` — - The construct scope.
  - `id` — - Identifier of the construct.
  - `attrs` — - Attributes of the existing prompt.

  **Returns:** An IPrompt reference to the existing prompt

- `grantGet(grantee: IGrantable): Grant` — Grant the given identity permissions to get the prompt.

  [disable-awslint:no-grants]

  **Parameters**

  - `grantee` — - The IAM principal to grant permissions to.

  **Returns:** An IAM Grant object representing the granted permissions

- `isConstruct(x: any): boolean` (static) — 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 object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
