Skip to content
v2.273.0

Amazon Bedrock Construct Library ​

Version 2.273.0-alpha.0

Separate package

@aws-cdk/aws-bedrock-alpha is not part of aws-cdk-lib — install it separately:

sh
npm install @aws-cdk/aws-bedrock-alpha
pip install aws-cdk.aws-bedrock-alpha

This module is experimental (alpha): its API may change in any release, without a major version bump.


cdk-constructs: Experimental

The APIs of higher level constructs in this module are experimental and under active development. They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and breaking changes will be announced in the release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.


LanguagePackage
Typescript Logo TypeScript@aws-cdk/aws-bedrock-alpha

Amazon Bedrock is a fully managed service that offers a choice of high-performing foundation models (FMs) from leading AI companies and Amazon through a single API, along with a broad set of capabilities you need to build generative AI applications with security, privacy, and responsible AI.

This construct library facilitates the deployment of Bedrock Agents, enabling you to create sophisticated AI applications that can interact with your systems and data sources.

Agents ​

Amazon Bedrock Agents allow generative AI applications to automate complex, multistep tasks by seamlessly integrating with your company's systems, APIs, and data sources. It uses the reasoning of foundation models (FMs), APIs, and data to break down user requests, gather relevant information, and efficiently complete tasks.

Create an Agent ​

Building an agent is straightforward and fast. The following example creates an Agent with a simple instruction and default prompts:

ts
const agent = new bedrock.Agent(this, 'Agent', {
  foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
  instruction: 'You are a helpful and friendly agent that answers questions about literature.',
});
python
agent = bedrock.Agent(self, "Agent",
    foundation_model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
    instruction="You are a helpful and friendly agent that answers questions about literature."
)
java
Agent agent = Agent.Builder.create(this, "Agent")
        .foundationModel(BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0)
        .instruction("You are a helpful and friendly agent that answers questions about literature.")
        .build();
csharp
var agent = new Agent(this, "Agent", new AgentProps {
    FoundationModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
    Instruction = "You are a helpful and friendly agent that answers questions about literature."
});
go
agent := bedrock.NewAgent(this, jsii.String("Agent"), &AgentProps{
	FoundationModel: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_HAIKU_V1_0(),
	Instruction: jsii.String("You are a helpful and friendly agent that answers questions about literature."),
})

You can also create an agent with a guardrail:

ts
// Create a guardrail to filter inappropriate content
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
  guardrailName: 'my-BedrockGuardrails',
  description: 'Legal ethical guardrails.',
});

guardrail.addContentFilter({
  type: bedrock.ContentFilterType.SEXUAL,
  inputStrength: bedrock.ContentFilterStrength.HIGH,
  outputStrength: bedrock.ContentFilterStrength.MEDIUM,
});

// Create an agent with the guardrail
const agentWithGuardrail = new bedrock.Agent(this, 'AgentWithGuardrail', {
  foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
  instruction: 'You are a helpful and friendly agent that answers questions about literature.',
  guardrail: guardrail,
});
python
# Create a guardrail to filter inappropriate content
guardrail = bedrock.Guardrail(self, "bedrockGuardrails",
    guardrail_name="my-BedrockGuardrails",
    description="Legal ethical guardrails."
)

guardrail.add_content_filter(
    type=bedrock.ContentFilterType.SEXUAL,
    input_strength=bedrock.ContentFilterStrength.HIGH,
    output_strength=bedrock.ContentFilterStrength.MEDIUM
)

# Create an agent with the guardrail
agent_with_guardrail = bedrock.Agent(self, "AgentWithGuardrail",
    foundation_model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
    instruction="You are a helpful and friendly agent that answers questions about literature.",
    guardrail=guardrail
)
java
// Create a guardrail to filter inappropriate content
Guardrail guardrail = Guardrail.Builder.create(this, "bedrockGuardrails")
        .guardrailName("my-BedrockGuardrails")
        .description("Legal ethical guardrails.")
        .build();

guardrail.addContentFilter(ContentFilter.builder()
        .type(ContentFilterType.SEXUAL)
        .inputStrength(ContentFilterStrength.HIGH)
        .outputStrength(ContentFilterStrength.MEDIUM)
        .build());

// Create an agent with the guardrail
Agent agentWithGuardrail = Agent.Builder.create(this, "AgentWithGuardrail")
        .foundationModel(BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0)
        .instruction("You are a helpful and friendly agent that answers questions about literature.")
        .guardrail(guardrail)
        .build();
csharp
// Create a guardrail to filter inappropriate content
var guardrail = new Guardrail(this, "bedrockGuardrails", new GuardrailProps {
    GuardrailName = "my-BedrockGuardrails",
    Description = "Legal ethical guardrails."
});

guardrail.AddContentFilter(new ContentFilter {
    Type = ContentFilterType.SEXUAL,
    InputStrength = ContentFilterStrength.HIGH,
    OutputStrength = ContentFilterStrength.MEDIUM
});

// Create an agent with the guardrail
var agentWithGuardrail = new Agent(this, "AgentWithGuardrail", new AgentProps {
    FoundationModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
    Instruction = "You are a helpful and friendly agent that answers questions about literature.",
    Guardrail = guardrail
});
go
// Create a guardrail to filter inappropriate content
guardrail := bedrock.NewGuardrail(this, jsii.String("bedrockGuardrails"), &GuardrailProps{
	GuardrailName: jsii.String("my-BedrockGuardrails"),
	Description: jsii.String("Legal ethical guardrails."),
})

guardrail.AddContentFilter(&ContentFilter{
	Type: bedrock.ContentFilterType_SEXUAL,
	InputStrength: bedrock.ContentFilterStrength_HIGH,
	OutputStrength: bedrock.ContentFilterStrength_MEDIUM,
})

// Create an agent with the guardrail
agentWithGuardrail := bedrock.NewAgent(this, jsii.String("AgentWithGuardrail"), &AgentProps{
	FoundationModel: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_HAIKU_V1_0(),
	Instruction: jsii.String("You are a helpful and friendly agent that answers questions about literature."),
	Guardrail: guardrail,
})

Agent Properties ​

The Bedrock Agent class supports the following properties.

NameTypeRequiredDescription
namestringNoThe name of the agent. Defaults to a name generated by CDK
instructionstringYesThe instruction used by the agent that determines how it will perform its task. Must have a minimum of 40 characters
foundationModelIBedrockInvokableYesThe foundation model used for orchestration by the agent
existingRoleiam.IRoleNoThe existing IAM Role for the agent to use. Must have a trust policy allowing Bedrock service to assume the role. Defaults to a new created role
shouldPrepareAgentbooleanNoSpecifies whether to automatically update the DRAFT version of the agent after making changes. Defaults to false
idleSessionTTLDurationNoHow long sessions should be kept open for the agent. Session expires if no conversation occurs during this time. Defaults to 1 hour
kmsKeykms.IKeyNoThe KMS key of the agent if custom encryption is configured. Defaults to AWS managed key
descriptionstringNoA description of the agent. Defaults to no description
actionGroupsAgentActionGroup[]NoThe Action Groups associated with the agent
guardrailIGuardrailNoThe guardrail that will be associated with the agent. Defaults to no guardrail
memoryMemoryNoThe type and configuration of the memory to maintain context across multiple sessions and recall past interactions. Defaults to no memory
promptOverrideConfigurationPromptOverrideConfigurationNoOverrides some prompt templates in different parts of an agent sequence configuration
userInputEnabledbooleanNoSelect whether the agent can prompt additional information from the user when it lacks enough information. Defaults to false
codeInterpreterEnabledbooleanNoSelect whether the agent can generate, run, and troubleshoot code when trying to complete a task. Defaults to false
forceDeletebooleanNoWhether to delete the resource even if it's in use. Defaults to true
agentCollaborationAgentCollaborationNoConfiguration for agent collaboration settings, including type and collaborators. This property allows you to define how the agent collaborates with other agents and what collaborators it can work with. Defaults to no agent collaboration configuration
customOrchestrationExecutorCustomOrchestrationExecutorNoThe Lambda function to use for custom orchestration. If provided, orchestrationType is set to CUSTOM_ORCHESTRATION. If not provided, orchestrationType defaults to DEFAULT. Defaults to default orchestration

Action Groups ​

An action group defines functions your agent can call. The functions are Lambda functions. The action group uses an OpenAPI schema to tell the agent what your functions do and how to call them.

Action Group Properties ​

The AgentActionGroup class supports the following properties.

NameTypeRequiredDescription
namestringNoThe name of the action group. Defaults to a name generated in the format 'action_group_quick_start_UUID'
descriptionstringNoA description of the action group
apiSchemaApiSchemaNoThe OpenAPI schema that defines the functions in the action group
executorActionGroupExecutorNoThe Lambda function that executes the actions in the group
enabledbooleanNoWhether the action group is enabled. Defaults to true
forceDeletebooleanNoWhether to delete the resource even if it's in use. Defaults to false
functionSchemaFunctionSchemaNoDefines functions that each define parameters that the agent needs to invoke from the user
parentActionGroupSignatureParentActionGroupSignatureNoThe AWS Defined signature for enabling certain capabilities in your agent

There are three ways to provide an API schema for your action group:

From a local asset file (requires binding to scope):

ts
const actionGroupFunction = new lambda.Function(this, 'ActionGroupFunction', {
  runtime: lambda.Runtime.PYTHON_3_12,
  handler: 'index.handler',
  code: lambda.Code.fromAsset(path.join(__dirname, '../lambda/action-group')),
});

// When using ApiSchema.fromLocalAsset, you must bind the schema to a scope
const schema = bedrock.ApiSchema.fromLocalAsset(path.join(__dirname, 'action-group.yaml'));
schema.bind(this);

const actionGroup = new bedrock.AgentActionGroup({
  name: 'query-library',
  description: 'Use these functions to get information about the books in the library.',
  executor: bedrock.ActionGroupExecutor.fromLambda(actionGroupFunction),
  enabled: true,
  apiSchema: schema,
});

const agent = new bedrock.Agent(this, 'Agent', {
  foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
  instruction: 'You are a helpful and friendly agent that answers questions about literature.',
});

agent.addActionGroup(actionGroup);
python
action_group_function = lambda_.Function(self, "ActionGroupFunction",
    runtime=lambda_.Runtime.PYTHON_3_12,
    handler="index.handler",
    code=lambda_.Code.from_asset(path.join(__dirname, "../lambda/action-group"))
)

# When using ApiSchema.fromLocalAsset, you must bind the schema to a scope
schema = bedrock.ApiSchema.from_local_asset(path.join(__dirname, "action-group.yaml"))
schema.bind(self)

action_group = bedrock.AgentActionGroup(
    name="query-library",
    description="Use these functions to get information about the books in the library.",
    executor=bedrock.ActionGroupExecutor.from_lambda(action_group_function),
    enabled=True,
    api_schema=schema
)

agent = bedrock.Agent(self, "Agent",
    foundation_model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
    instruction="You are a helpful and friendly agent that answers questions about literature."
)

agent.add_action_group(action_group)
java
Function actionGroupFunction = Function.Builder.create(this, "ActionGroupFunction")
        .runtime(Runtime.PYTHON_3_12)
        .handler("index.handler")
        .code(Code.fromAsset(join(__dirname, "../lambda/action-group")))
        .build();

// When using ApiSchema.fromLocalAsset, you must bind the schema to a scope
AssetApiSchema schema = ApiSchema.fromLocalAsset(join(__dirname, "action-group.yaml"));
schema.bind(this);

AgentActionGroup actionGroup = AgentActionGroup.Builder.create()
        .name("query-library")
        .description("Use these functions to get information about the books in the library.")
        .executor(ActionGroupExecutor.fromLambda(actionGroupFunction))
        .enabled(true)
        .apiSchema(schema)
        .build();

Agent agent = Agent.Builder.create(this, "Agent")
        .foundationModel(BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0)
        .instruction("You are a helpful and friendly agent that answers questions about literature.")
        .build();

agent.addActionGroup(actionGroup);
csharp
var actionGroupFunction = new Function(this, "ActionGroupFunction", new FunctionProps {
    Runtime = Runtime.PYTHON_3_12,
    Handler = "index.handler",
    Code = Code.FromAsset(Join(__dirname, "../lambda/action-group"))
});

// When using ApiSchema.fromLocalAsset, you must bind the schema to a scope
var schema = ApiSchema.FromLocalAsset(Join(__dirname, "action-group.yaml"));
schema.Bind(this);

var actionGroup = new AgentActionGroup(new AgentActionGroupProps {
    Name = "query-library",
    Description = "Use these functions to get information about the books in the library.",
    Executor = ActionGroupExecutor.FromLambda(actionGroupFunction),
    Enabled = true,
    ApiSchema = schema
});

var agent = new Agent(this, "Agent", new AgentProps {
    FoundationModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
    Instruction = "You are a helpful and friendly agent that answers questions about literature."
});

agent.AddActionGroup(actionGroup);
go
actionGroupFunction := lambda.NewFunction(this, jsii.String("ActionGroupFunction"), &FunctionProps{
	Runtime: lambda.Runtime_PYTHON_3_12(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromAsset(path.join(__dirname, jsii.String("../lambda/action-group"))),
})

// When using ApiSchema.fromLocalAsset, you must bind the schema to a scope
schema := bedrock.ApiSchema_FromLocalAsset(path.join(__dirname, jsii.String("action-group.yaml")))
schema.Bind(this)

actionGroup := bedrock.NewAgentActionGroup(&AgentActionGroupProps{
	Name: jsii.String("query-library"),
	Description: jsii.String("Use these functions to get information about the books in the library."),
	Executor: bedrock.ActionGroupExecutor_FromLambda(actionGroupFunction),
	Enabled: jsii.Boolean(true),
	ApiSchema: schema,
})

agent := bedrock.NewAgent(this, jsii.String("Agent"), &AgentProps{
	FoundationModel: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_HAIKU_V1_0(),
	Instruction: jsii.String("You are a helpful and friendly agent that answers questions about literature."),
})

agent.AddActionGroup(actionGroup)

From an inline OpenAPI schema:

ts
const inlineSchema = bedrock.ApiSchema.fromInline(`
openapi: 3.0.3
info:
  title: Library API
  version: 1.0.0
paths:
  /search:
    get:
      summary: Search for books
      operationId: searchBooks
      parameters:
        - name: query
          in: query
          required: true
          schema:
            type: string
`);

const actionGroupFunction = new lambda.Function(this, 'ActionGroupFunction', {
  runtime: lambda.Runtime.PYTHON_3_12,
  handler: 'index.handler',
  code: lambda.Code.fromAsset(path.join(__dirname, '../lambda/action-group')),
});

const actionGroup = new bedrock.AgentActionGroup({
  name: 'query-library',
  description: 'Use these functions to get information about the books in the library.',
  executor: bedrock.ActionGroupExecutor.fromLambda(actionGroupFunction),
  enabled: true,
  apiSchema: inlineSchema,
});

const agent = new bedrock.Agent(this, 'Agent', {
  foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
  instruction: 'You are a helpful and friendly agent that answers questions about literature.',
});

agent.addActionGroup(actionGroup);
python
inline_schema = bedrock.ApiSchema.from_inline("""
    openapi: 3.0.3
    info:
      title: Library API
      version: 1.0.0
    paths:
      /search:
        get:
          summary: Search for books
          operationId: searchBooks
          parameters:
            - name: query
              in: query
              required: true
              schema:
                type: string
    """)

action_group_function = lambda_.Function(self, "ActionGroupFunction",
    runtime=lambda_.Runtime.PYTHON_3_12,
    handler="index.handler",
    code=lambda_.Code.from_asset(path.join(__dirname, "../lambda/action-group"))
)

action_group = bedrock.AgentActionGroup(
    name="query-library",
    description="Use these functions to get information about the books in the library.",
    executor=bedrock.ActionGroupExecutor.from_lambda(action_group_function),
    enabled=True,
    api_schema=inline_schema
)

agent = bedrock.Agent(self, "Agent",
    foundation_model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
    instruction="You are a helpful and friendly agent that answers questions about literature."
)

agent.add_action_group(action_group)
java
InlineApiSchema inlineSchema = ApiSchema.fromInline("\nopenapi: 3.0.3\ninfo:\n  title: Library API\n  version: 1.0.0\npaths:\n  /search:\n    get:\n      summary: Search for books\n      operationId: searchBooks\n      parameters:\n        - name: query\n          in: query\n          required: true\n          schema:\n            type: string\n");

Function actionGroupFunction = Function.Builder.create(this, "ActionGroupFunction")
        .runtime(Runtime.PYTHON_3_12)
        .handler("index.handler")
        .code(Code.fromAsset(join(__dirname, "../lambda/action-group")))
        .build();

AgentActionGroup actionGroup = AgentActionGroup.Builder.create()
        .name("query-library")
        .description("Use these functions to get information about the books in the library.")
        .executor(ActionGroupExecutor.fromLambda(actionGroupFunction))
        .enabled(true)
        .apiSchema(inlineSchema)
        .build();

Agent agent = Agent.Builder.create(this, "Agent")
        .foundationModel(BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0)
        .instruction("You are a helpful and friendly agent that answers questions about literature.")
        .build();

agent.addActionGroup(actionGroup);
csharp
var inlineSchema = ApiSchema.FromInline(@"
openapi: 3.0.3
info:
  title: Library API
  version: 1.0.0
paths:
  /search:
    get:
      summary: Search for books
      operationId: searchBooks
      parameters:
        - name: query
          in: query
          required: true
          schema:
            type: string
");

var actionGroupFunction = new Function(this, "ActionGroupFunction", new FunctionProps {
    Runtime = Runtime.PYTHON_3_12,
    Handler = "index.handler",
    Code = Code.FromAsset(Join(__dirname, "../lambda/action-group"))
});

var actionGroup = new AgentActionGroup(new AgentActionGroupProps {
    Name = "query-library",
    Description = "Use these functions to get information about the books in the library.",
    Executor = ActionGroupExecutor.FromLambda(actionGroupFunction),
    Enabled = true,
    ApiSchema = inlineSchema
});

var agent = new Agent(this, "Agent", new AgentProps {
    FoundationModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
    Instruction = "You are a helpful and friendly agent that answers questions about literature."
});

agent.AddActionGroup(actionGroup);
go
inlineSchema := bedrock.ApiSchema_FromInline(jsii.String(`
openapi: 3.0.3
info:
  title: Library API
  version: 1.0.0
paths:
  /search:
    get:
      summary: Search for books
      operationId: searchBooks
      parameters:
        - name: query
          in: query
          required: true
          schema:
            type: string
`))

actionGroupFunction := lambda.NewFunction(this, jsii.String("ActionGroupFunction"), &FunctionProps{
	Runtime: lambda.Runtime_PYTHON_3_12(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromAsset(path.join(__dirname, jsii.String("../lambda/action-group"))),
})

actionGroup := bedrock.NewAgentActionGroup(&AgentActionGroupProps{
	Name: jsii.String("query-library"),
	Description: jsii.String("Use these functions to get information about the books in the library."),
	Executor: bedrock.ActionGroupExecutor_FromLambda(actionGroupFunction),
	Enabled: jsii.Boolean(true),
	ApiSchema: inlineSchema,
})

agent := bedrock.NewAgent(this, jsii.String("Agent"), &AgentProps{
	FoundationModel: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_HAIKU_V1_0(),
	Instruction: jsii.String("You are a helpful and friendly agent that answers questions about literature."),
})

agent.AddActionGroup(actionGroup)

From an existing S3 file:

ts
const bucket = s3.Bucket.fromBucketName(this, 'ExistingBucket', 'my-schema-bucket');
const s3Schema = bedrock.ApiSchema.fromS3File(bucket, 'schemas/action-group.yaml');

const actionGroupFunction = new lambda.Function(this, 'ActionGroupFunction', {
  runtime: lambda.Runtime.PYTHON_3_12,
  handler: 'index.handler',
  code: lambda.Code.fromAsset(path.join(__dirname, '../lambda/action-group')),
});

const actionGroup = new bedrock.AgentActionGroup({
  name: 'query-library',
  description: 'Use these functions to get information about the books in the library.',
  executor: bedrock.ActionGroupExecutor.fromLambda(actionGroupFunction),
  enabled: true,
  apiSchema: s3Schema,
});

const agent = new bedrock.Agent(this, 'Agent', {
  foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
  instruction: 'You are a helpful and friendly agent that answers questions about literature.',
});

agent.addActionGroup(actionGroup);
python
bucket = s3.Bucket.from_bucket_name(self, "ExistingBucket", "my-schema-bucket")
s3_schema = bedrock.ApiSchema.from_s3_file(bucket, "schemas/action-group.yaml")

action_group_function = lambda_.Function(self, "ActionGroupFunction",
    runtime=lambda_.Runtime.PYTHON_3_12,
    handler="index.handler",
    code=lambda_.Code.from_asset(path.join(__dirname, "../lambda/action-group"))
)

action_group = bedrock.AgentActionGroup(
    name="query-library",
    description="Use these functions to get information about the books in the library.",
    executor=bedrock.ActionGroupExecutor.from_lambda(action_group_function),
    enabled=True,
    api_schema=s3_schema
)

agent = bedrock.Agent(self, "Agent",
    foundation_model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
    instruction="You are a helpful and friendly agent that answers questions about literature."
)

agent.add_action_group(action_group)
java
IBucket bucket = Bucket.fromBucketName(this, "ExistingBucket", "my-schema-bucket");
S3ApiSchema s3Schema = ApiSchema.fromS3File(bucket, "schemas/action-group.yaml");

Function actionGroupFunction = Function.Builder.create(this, "ActionGroupFunction")
        .runtime(Runtime.PYTHON_3_12)
        .handler("index.handler")
        .code(Code.fromAsset(join(__dirname, "../lambda/action-group")))
        .build();

AgentActionGroup actionGroup = AgentActionGroup.Builder.create()
        .name("query-library")
        .description("Use these functions to get information about the books in the library.")
        .executor(ActionGroupExecutor.fromLambda(actionGroupFunction))
        .enabled(true)
        .apiSchema(s3Schema)
        .build();

Agent agent = Agent.Builder.create(this, "Agent")
        .foundationModel(BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0)
        .instruction("You are a helpful and friendly agent that answers questions about literature.")
        .build();

agent.addActionGroup(actionGroup);
csharp
var bucket = Bucket.FromBucketName(this, "ExistingBucket", "my-schema-bucket");
var s3Schema = ApiSchema.FromS3File(bucket, "schemas/action-group.yaml");

var actionGroupFunction = new Function(this, "ActionGroupFunction", new FunctionProps {
    Runtime = Runtime.PYTHON_3_12,
    Handler = "index.handler",
    Code = Code.FromAsset(Join(__dirname, "../lambda/action-group"))
});

var actionGroup = new AgentActionGroup(new AgentActionGroupProps {
    Name = "query-library",
    Description = "Use these functions to get information about the books in the library.",
    Executor = ActionGroupExecutor.FromLambda(actionGroupFunction),
    Enabled = true,
    ApiSchema = s3Schema
});

var agent = new Agent(this, "Agent", new AgentProps {
    FoundationModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
    Instruction = "You are a helpful and friendly agent that answers questions about literature."
});

agent.AddActionGroup(actionGroup);
go
bucket := s3.Bucket_FromBucketName(this, jsii.String("ExistingBucket"), jsii.String("my-schema-bucket"))
s3Schema := bedrock.ApiSchema_FromS3File(bucket, jsii.String("schemas/action-group.yaml"))

actionGroupFunction := lambda.NewFunction(this, jsii.String("ActionGroupFunction"), &FunctionProps{
	Runtime: lambda.Runtime_PYTHON_3_12(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromAsset(path.join(__dirname, jsii.String("../lambda/action-group"))),
})

actionGroup := bedrock.NewAgentActionGroup(&AgentActionGroupProps{
	Name: jsii.String("query-library"),
	Description: jsii.String("Use these functions to get information about the books in the library."),
	Executor: bedrock.ActionGroupExecutor_FromLambda(actionGroupFunction),
	Enabled: jsii.Boolean(true),
	ApiSchema: s3Schema,
})

agent := bedrock.NewAgent(this, jsii.String("Agent"), &AgentProps{
	FoundationModel: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_HAIKU_V1_0(),
	Instruction: jsii.String("You are a helpful and friendly agent that answers questions about literature."),
})

agent.AddActionGroup(actionGroup)

Using FunctionSchema with Action Groups ​

As an alternative to using OpenAPI schemas, you can define functions directly using the FunctionSchema class. This approach provides a more structured way to define the functions that your agent can call.

ts
const actionGroupFunction = new lambda.Function(this, 'ActionGroupFunction', {
  runtime: lambda.Runtime.PYTHON_3_12,
  handler: 'index.handler',
  code: lambda.Code.fromAsset(path.join(__dirname, '../lambda/action-group')),
});

// Define a function schema with parameters
const functionSchema = new bedrock.FunctionSchema({
  functions: [
    {
      name: 'searchBooks',
      description: 'Search for books in the library catalog',
      parameters: {
        'query': {
          type: bedrock.ParameterType.STRING,
          required: true,
          description: 'The search query string',
        },
        'maxResults': {
          type: bedrock.ParameterType.INTEGER,
          required: false,
          description: 'Maximum number of results to return',
        },
        'includeOutOfPrint': {
          type: bedrock.ParameterType.BOOLEAN,
          required: false,
          description: 'Whether to include out-of-print books',
        }
      },
      requireConfirmation: bedrock.RequireConfirmation.DISABLED,
    },
    {
      name: 'getBookDetails',
      description: 'Get detailed information about a specific book',
      parameters: {
        'bookId': {
          type: bedrock.ParameterType.STRING,
          required: true,
          description: 'The unique identifier of the book',
        }
      },
      requireConfirmation: bedrock.RequireConfirmation.ENABLED,
    }
  ]
});

// Create an action group using the function schema
const actionGroup = new bedrock.AgentActionGroup({
  name: 'library-functions',
  description: 'Functions for interacting with the library catalog',
  executor: bedrock.ActionGroupExecutor.fromLambda(actionGroupFunction),
  functionSchema: functionSchema,
  enabled: true,
});

const agent = new bedrock.Agent(this, 'Agent', {
  foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
  instruction: 'You are a helpful and friendly agent that answers questions about literature.',
  actionGroups: [actionGroup],
});
python
action_group_function = lambda_.Function(self, "ActionGroupFunction",
    runtime=lambda_.Runtime.PYTHON_3_12,
    handler="index.handler",
    code=lambda_.Code.from_asset(path.join(__dirname, "../lambda/action-group"))
)

# Define a function schema with parameters
function_schema = bedrock.FunctionSchema(
    functions=[bedrock.FunctionProps(
        name="searchBooks",
        description="Search for books in the library catalog",
        parameters={
            "query": bedrock.FunctionParameterProps(
                type=bedrock.ParameterType.STRING,
                required=True,
                description="The search query string"
            ),
            "maxResults": bedrock.FunctionParameterProps(
                type=bedrock.ParameterType.INTEGER,
                required=False,
                description="Maximum number of results to return"
            ),
            "includeOutOfPrint": bedrock.FunctionParameterProps(
                type=bedrock.ParameterType.BOOLEAN,
                required=False,
                description="Whether to include out-of-print books"
            )
        },
        require_confirmation=bedrock.RequireConfirmation.DISABLED
    ), bedrock.FunctionProps(
        name="getBookDetails",
        description="Get detailed information about a specific book",
        parameters={
            "bookId": bedrock.FunctionParameterProps(
                type=bedrock.ParameterType.STRING,
                required=True,
                description="The unique identifier of the book"
            )
        },
        require_confirmation=bedrock.RequireConfirmation.ENABLED
    )
    ]
)

# Create an action group using the function schema
action_group = bedrock.AgentActionGroup(
    name="library-functions",
    description="Functions for interacting with the library catalog",
    executor=bedrock.ActionGroupExecutor.from_lambda(action_group_function),
    function_schema=function_schema,
    enabled=True
)

agent = bedrock.Agent(self, "Agent",
    foundation_model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
    instruction="You are a helpful and friendly agent that answers questions about literature.",
    action_groups=[action_group]
)
java
Function actionGroupFunction = Function.Builder.create(this, "ActionGroupFunction")
        .runtime(Runtime.PYTHON_3_12)
        .handler("index.handler")
        .code(Code.fromAsset(join(__dirname, "../lambda/action-group")))
        .build();

// Define a function schema with parameters
FunctionSchema functionSchema = FunctionSchema.Builder.create()
        .functions(List.of(FunctionProps.builder()
                .name("searchBooks")
                .description("Search for books in the library catalog")
                .parameters(Map.of(
                        "query", FunctionParameterProps.builder()
                                .type(ParameterType.STRING)
                                .required(true)
                                .description("The search query string")
                                .build(),
                        "maxResults", FunctionParameterProps.builder()
                                .type(ParameterType.INTEGER)
                                .required(false)
                                .description("Maximum number of results to return")
                                .build(),
                        "includeOutOfPrint", FunctionParameterProps.builder()
                                .type(ParameterType.BOOLEAN)
                                .required(false)
                                .description("Whether to include out-of-print books")
                                .build()))
                .requireConfirmation(RequireConfirmation.DISABLED)
                .build(), FunctionProps.builder()
                .name("getBookDetails")
                .description("Get detailed information about a specific book")
                .parameters(Map.of(
                        "bookId", FunctionParameterProps.builder()
                                .type(ParameterType.STRING)
                                .required(true)
                                .description("The unique identifier of the book")
                                .build()))
                .requireConfirmation(RequireConfirmation.ENABLED)
                .build()))
        .build();

// Create an action group using the function schema
AgentActionGroup actionGroup = AgentActionGroup.Builder.create()
        .name("library-functions")
        .description("Functions for interacting with the library catalog")
        .executor(ActionGroupExecutor.fromLambda(actionGroupFunction))
        .functionSchema(functionSchema)
        .enabled(true)
        .build();

Agent agent = Agent.Builder.create(this, "Agent")
        .foundationModel(BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0)
        .instruction("You are a helpful and friendly agent that answers questions about literature.")
        .actionGroups(List.of(actionGroup))
        .build();
csharp
var actionGroupFunction = new Function(this, "ActionGroupFunction", new FunctionProps {
    Runtime = Runtime.PYTHON_3_12,
    Handler = "index.handler",
    Code = Code.FromAsset(Join(__dirname, "../lambda/action-group"))
});

// Define a function schema with parameters
var functionSchema = new FunctionSchema(new FunctionSchemaProps {
    Functions = new [] { new FunctionProps {
        Name = "searchBooks",
        Description = "Search for books in the library catalog",
        Parameters = new Dictionary<string, FunctionParameterProps> {
            { "query", new FunctionParameterProps {
                Type = ParameterType.STRING,
                Required = true,
                Description = "The search query string"
            } },
            { "maxResults", new FunctionParameterProps {
                Type = ParameterType.INTEGER,
                Required = false,
                Description = "Maximum number of results to return"
            } },
            { "includeOutOfPrint", new FunctionParameterProps {
                Type = ParameterType.BOOLEAN,
                Required = false,
                Description = "Whether to include out-of-print books"
            } }
        },
        RequireConfirmation = RequireConfirmation.DISABLED
    }, new FunctionProps {
        Name = "getBookDetails",
        Description = "Get detailed information about a specific book",
        Parameters = new Dictionary<string, FunctionParameterProps> {
            { "bookId", new FunctionParameterProps {
                Type = ParameterType.STRING,
                Required = true,
                Description = "The unique identifier of the book"
            } }
        },
        RequireConfirmation = RequireConfirmation.ENABLED
    } }
});

// Create an action group using the function schema
var actionGroup = new AgentActionGroup(new AgentActionGroupProps {
    Name = "library-functions",
    Description = "Functions for interacting with the library catalog",
    Executor = ActionGroupExecutor.FromLambda(actionGroupFunction),
    FunctionSchema = functionSchema,
    Enabled = true
});

var agent = new Agent(this, "Agent", new AgentProps {
    FoundationModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
    Instruction = "You are a helpful and friendly agent that answers questions about literature.",
    ActionGroups = new [] { actionGroup }
});
go
actionGroupFunction := lambda.NewFunction(this, jsii.String("ActionGroupFunction"), &FunctionProps{
	Runtime: lambda.Runtime_PYTHON_3_12(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromAsset(path.join(__dirname, jsii.String("../lambda/action-group"))),
})

// Define a function schema with parameters
functionSchema := bedrock.NewFunctionSchema(&FunctionSchemaProps{
	Functions: []FunctionProps{
		&FunctionProps{
			Name: jsii.String("searchBooks"),
			Description: jsii.String("Search for books in the library catalog"),
			Parameters: map[string]FunctionParameterProps{
				"query": &FunctionParameterProps{
					"type": bedrock.ParameterType_STRING,
					"required": jsii.Boolean(true),
					"description": jsii.String("The search query string"),
				},
				"maxResults": &FunctionParameterProps{
					"type": bedrock.ParameterType_INTEGER,
					"required": jsii.Boolean(false),
					"description": jsii.String("Maximum number of results to return"),
				},
				"includeOutOfPrint": &FunctionParameterProps{
					"type": bedrock.ParameterType_BOOLEAN,
					"required": jsii.Boolean(false),
					"description": jsii.String("Whether to include out-of-print books"),
				},
			},
			RequireConfirmation: bedrock.RequireConfirmation_DISABLED,
		},
		&FunctionProps{
			Name: jsii.String("getBookDetails"),
			Description: jsii.String("Get detailed information about a specific book"),
			Parameters: map[string]FunctionParameterProps{
				"bookId": &FunctionParameterProps{
					"type": bedrock.ParameterType_STRING,
					"required": jsii.Boolean(true),
					"description": jsii.String("The unique identifier of the book"),
				},
			},
			RequireConfirmation: bedrock.RequireConfirmation_ENABLED,
		},
	},
})

// Create an action group using the function schema
actionGroup := bedrock.NewAgentActionGroup(&AgentActionGroupProps{
	Name: jsii.String("library-functions"),
	Description: jsii.String("Functions for interacting with the library catalog"),
	Executor: bedrock.ActionGroupExecutor_FromLambda(actionGroupFunction),
	FunctionSchema: functionSchema,
	Enabled: jsii.Boolean(true),
})

agent := bedrock.NewAgent(this, jsii.String("Agent"), &AgentProps{
	FoundationModel: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_HAIKU_V1_0(),
	Instruction: jsii.String("You are a helpful and friendly agent that answers questions about literature."),
	ActionGroups: []AgentActionGroup{
		actionGroup,
	},
})

The FunctionSchema approach offers several advantages:

  • Type-safe definition of functions and parameters
  • Built-in validation of parameter names, descriptions, and other properties
  • Clear structure that maps directly to the AWS Bedrock API
  • Support for parameter types including string, number, integer, boolean, array, and object
  • Option to require user confirmation before executing specific functions

If you chose to load your schema file from S3, the construct will provide the necessary permissions to your agent's execution role to access the schema file from the specific bucket. Similar to performing the operation through the console, the agent execution role will get a permission like:

json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AmazonBedrockAgentS3PolicyProd",
            "Effect": "Allow",
            "Action": [
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::<BUCKET_NAME>/<OBJECT_KEY>"
            ],
            "Condition": {
                "StringEquals": {
                    "aws:ResourceAccount": "ACCOUNT_NUMBER"
                }
            }
        }
    ]
}
ts
// create a bucket containing the input schema
const schemaBucket = new s3.Bucket(this, 'SchemaBucket', {
  enforceSSL: true,
  versioned: true,
  publicReadAccess: false,
  blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
  encryption: s3.BucketEncryption.S3_MANAGED,
  removalPolicy: RemovalPolicy.DESTROY,
  autoDeleteObjects: true,
});

// deploy the local schema file to S3
const deployement = new aws_s3_deployment.BucketDeployment(this, 'DeployWebsite', {
  sources: [aws_s3_deployment.Source.asset(path.join(__dirname, '../inputschema'))],
  destinationBucket: schemaBucket,
  destinationKeyPrefix: 'inputschema',
});

// create the agent
const agent = new bedrock.Agent(this, 'Agent', {
  foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
  instruction: 'You are a helpful and friendly agent that answers questions about literature.',
  userInputEnabled: true,
  shouldPrepareAgent:true
});

// create a lambda function
const actionGroupFunction = new lambda.Function(this, 'ActionGroupFunction', {
  runtime: lambda.Runtime.PYTHON_3_12,
  handler: 'index.handler',
  code: lambda.Code.fromAsset(path.join(__dirname, '../lambda/action-group')),
});

// create an action group and read the schema file from S3
const actionGroup = new bedrock.AgentActionGroup({
  name: 'query-library',
  description: 'Use these functions to get information about the books in the library.',
  executor: bedrock.ActionGroupExecutor.fromLambda(actionGroupFunction),
  enabled: true,
  apiSchema: bedrock.ApiSchema.fromS3File(schemaBucket, 'inputschema/action-group.yaml'),
});

// add the action group to the agent
agent.addActionGroup(actionGroup);

// add dependency for the agent on the s3 deployment
agent.node.addDependency(deployement);
python
# create a bucket containing the input schema
schema_bucket = s3.Bucket(self, "SchemaBucket",
    enforce_ssl=True,
    versioned=True,
    public_read_access=False,
    block_public_access=s3.BlockPublicAccess.BLOCK_ALL,
    encryption=s3.BucketEncryption.S3_MANAGED,
    removal_policy=RemovalPolicy.DESTROY,
    auto_delete_objects=True
)

# deploy the local schema file to S3
deployement = aws_s3_deployment.BucketDeployment(self, "DeployWebsite",
    sources=[aws_s3_deployment.Source.asset(path.join(__dirname, "../inputschema"))],
    destination_bucket=schema_bucket,
    destination_key_prefix="inputschema"
)

# create the agent
agent = bedrock.Agent(self, "Agent",
    foundation_model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
    instruction="You are a helpful and friendly agent that answers questions about literature.",
    user_input_enabled=True,
    should_prepare_agent=True
)

# create a lambda function
action_group_function = lambda_.Function(self, "ActionGroupFunction",
    runtime=lambda_.Runtime.PYTHON_3_12,
    handler="index.handler",
    code=lambda_.Code.from_asset(path.join(__dirname, "../lambda/action-group"))
)

# create an action group and read the schema file from S3
action_group = bedrock.AgentActionGroup(
    name="query-library",
    description="Use these functions to get information about the books in the library.",
    executor=bedrock.ActionGroupExecutor.from_lambda(action_group_function),
    enabled=True,
    api_schema=bedrock.ApiSchema.from_s3_file(schema_bucket, "inputschema/action-group.yaml")
)

# add the action group to the agent
agent.add_action_group(action_group)

# add dependency for the agent on the s3 deployment
agent.node.add_dependency(deployement)
java
// create a bucket containing the input schema
Bucket schemaBucket = Bucket.Builder.create(this, "SchemaBucket")
        .enforceSSL(true)
        .versioned(true)
        .publicReadAccess(false)
        .blockPublicAccess(BlockPublicAccess.BLOCK_ALL)
        .encryption(BucketEncryption.S3_MANAGED)
        .removalPolicy(RemovalPolicy.DESTROY)
        .autoDeleteObjects(true)
        .build();

// deploy the local schema file to S3
BucketDeployment deployement = BucketDeployment.Builder.create(this, "DeployWebsite")
        .sources(List.of(Source.asset(join(__dirname, "../inputschema"))))
        .destinationBucket(schemaBucket)
        .destinationKeyPrefix("inputschema")
        .build();

// create the agent
Agent agent = Agent.Builder.create(this, "Agent")
        .foundationModel(BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0)
        .instruction("You are a helpful and friendly agent that answers questions about literature.")
        .userInputEnabled(true)
        .shouldPrepareAgent(true)
        .build();

// create a lambda function
Function actionGroupFunction = Function.Builder.create(this, "ActionGroupFunction")
        .runtime(Runtime.PYTHON_3_12)
        .handler("index.handler")
        .code(Code.fromAsset(join(__dirname, "../lambda/action-group")))
        .build();

// create an action group and read the schema file from S3
AgentActionGroup actionGroup = AgentActionGroup.Builder.create()
        .name("query-library")
        .description("Use these functions to get information about the books in the library.")
        .executor(ActionGroupExecutor.fromLambda(actionGroupFunction))
        .enabled(true)
        .apiSchema(ApiSchema.fromS3File(schemaBucket, "inputschema/action-group.yaml"))
        .build();

// add the action group to the agent
agent.addActionGroup(actionGroup);

// add dependency for the agent on the s3 deployment
agent.node.addDependency(deployement);
csharp
// create a bucket containing the input schema
var schemaBucket = new Bucket(this, "SchemaBucket", new BucketProps {
    EnforceSSL = true,
    Versioned = true,
    PublicReadAccess = false,
    BlockPublicAccess = BlockPublicAccess.BLOCK_ALL,
    Encryption = BucketEncryption.S3_MANAGED,
    RemovalPolicy = RemovalPolicy.DESTROY,
    AutoDeleteObjects = true
});

// deploy the local schema file to S3
var deployement = new BucketDeployment(this, "DeployWebsite", new BucketDeploymentProps {
    Sources = new [] { Source.Asset(Join(__dirname, "../inputschema")) },
    DestinationBucket = schemaBucket,
    DestinationKeyPrefix = "inputschema"
});

// create the agent
var agent = new Agent(this, "Agent", new AgentProps {
    FoundationModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
    Instruction = "You are a helpful and friendly agent that answers questions about literature.",
    UserInputEnabled = true,
    ShouldPrepareAgent = true
});

// create a lambda function
var actionGroupFunction = new Function(this, "ActionGroupFunction", new FunctionProps {
    Runtime = Runtime.PYTHON_3_12,
    Handler = "index.handler",
    Code = Code.FromAsset(Join(__dirname, "../lambda/action-group"))
});

// create an action group and read the schema file from S3
var actionGroup = new AgentActionGroup(new AgentActionGroupProps {
    Name = "query-library",
    Description = "Use these functions to get information about the books in the library.",
    Executor = ActionGroupExecutor.FromLambda(actionGroupFunction),
    Enabled = true,
    ApiSchema = ApiSchema.FromS3File(schemaBucket, "inputschema/action-group.yaml")
});

// add the action group to the agent
agent.AddActionGroup(actionGroup);

// add dependency for the agent on the s3 deployment
agent.Node.AddDependency(deployement);
go
// create a bucket containing the input schema
schemaBucket := s3.NewBucket(this, jsii.String("SchemaBucket"), &BucketProps{
	EnforceSSL: jsii.Boolean(true),
	Versioned: jsii.Boolean(true),
	PublicReadAccess: jsii.Boolean(false),
	BlockPublicAccess: s3.BlockPublicAccess_BLOCK_ALL(),
	Encryption: s3.BucketEncryption_S3_MANAGED,
	RemovalPolicy: awscdk.RemovalPolicy_DESTROY,
	AutoDeleteObjects: jsii.Boolean(true),
})

// deploy the local schema file to S3
deployement := awscdk.Aws_s3_deployment.NewBucketDeployment(this, jsii.String("DeployWebsite"), &BucketDeploymentProps{
	Sources: []ISource{
		awscdk.*Aws_s3_deployment.Source_Asset(path.join(__dirname, jsii.String("../inputschema"))),
	},
	DestinationBucket: schemaBucket,
	DestinationKeyPrefix: jsii.String("inputschema"),
})

// create the agent
agent := bedrock.NewAgent(this, jsii.String("Agent"), &AgentProps{
	FoundationModel: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_3_5_SONNET_V1_0(),
	Instruction: jsii.String("You are a helpful and friendly agent that answers questions about literature."),
	UserInputEnabled: jsii.Boolean(true),
	ShouldPrepareAgent: jsii.Boolean(true),
})

// create a lambda function
actionGroupFunction := lambda.NewFunction(this, jsii.String("ActionGroupFunction"), &FunctionProps{
	Runtime: lambda.Runtime_PYTHON_3_12(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromAsset(path.join(__dirname, jsii.String("../lambda/action-group"))),
})

// create an action group and read the schema file from S3
actionGroup := bedrock.NewAgentActionGroup(&AgentActionGroupProps{
	Name: jsii.String("query-library"),
	Description: jsii.String("Use these functions to get information about the books in the library."),
	Executor: bedrock.ActionGroupExecutor_FromLambda(actionGroupFunction),
	Enabled: jsii.Boolean(true),
	ApiSchema: bedrock.ApiSchema_FromS3File(schemaBucket, jsii.String("inputschema/action-group.yaml")),
})

// add the action group to the agent
agent.AddActionGroup(actionGroup)

// add dependency for the agent on the s3 deployment
agent.Node.AddDependency(deployement)

Prepare the Agent ​

The Agent constructs take an optional parameter shouldPrepareAgent to indicate that the Agent should be prepared after any updates to an agent or action group. This may increase the time to create and update those resources. By default, this value is false.

Prepare Agent Properties ​

NameTypeRequiredDescription
shouldPrepareAgentbooleanNoWhether to automatically update the DRAFT version of the agent after making changes. Defaults to false

Creating an agent alias will not prepare the agent, so if you create an alias using the AgentAlias resource then you should set shouldPrepareAgent to true.

Prompt Override Configuration ​

Bedrock Agents allows you to customize the prompts and LLM configuration for different steps in the agent sequence. The implementation provides type-safe configurations for each step type, ensuring correct usage at compile time.

Prompt Override Configuration Properties ​

NameTypeRequiredDescription
stepsPromptStepConfiguration[]YesArray of step configurations for different parts of the agent sequence
parserlambda.IFunctionNoLambda function for custom parsing of agent responses

Prompt Step Configuration Properties ​

Each step in the steps array supports the following properties:

NameTypeRequiredDescription
stepTypeAgentStepTypeYesThe type of step being configured (PRE_PROCESSING, ORCHESTRATION, POST_PROCESSING, ROUTING_CLASSIFIER, MEMORY_SUMMARIZATION, KNOWLEDGE_BASE_RESPONSE_GENERATION)
stepEnabledbooleanNoWhether this step is enabled. Defaults to true
customPromptTemplatestringNoCustom prompt template to use for this step
inferenceConfigInferenceConfigurationNoConfiguration for model inference parameters
foundationModelBedrockFoundationModelNoAlternative foundation model to use for this step (only valid for ROUTING_CLASSIFIER step)
useCustomParserbooleanNoWhether to use a custom parser for this step. Requires parser to be provided in PromptOverrideConfiguration

Inference Configuration Properties ​

When providing inferenceConfig, the following properties are supported:

NameTypeRequiredDescription
temperaturenumberNoControls randomness in the model's output (0.0-1.0)
topPnumberNoControls diversity via nucleus sampling (0.0-1.0)
topKnumberNoControls diversity by limiting the cumulative probability
maximumLengthnumberNoMaximum length of generated text
stopSequencesstring[]NoSequences where the model should stop generating

The following steps can be configured:

  • PRE_PROCESSING: Prepares the user input for orchestration
  • ORCHESTRATION: Main step that determines the agent's actions
  • POST_PROCESSING: Refines the agent's response
  • ROUTING_CLASSIFIER: Classifies and routes requests to appropriate collaborators
  • MEMORY_SUMMARIZATION: Summarizes conversation history for memory retention
  • KNOWLEDGE_BASE_RESPONSE_GENERATION: Generates responses using knowledge base content

Example with pre-processing configuration:

ts
const agent = new bedrock.Agent(this, 'Agent', {
  foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
  instruction: 'You are a helpful assistant.',
  promptOverrideConfiguration: bedrock.PromptOverrideConfiguration.fromSteps([
    {
      stepType: bedrock.AgentStepType.PRE_PROCESSING,
      stepEnabled: true,
      customPromptTemplate: 'Your custom prompt template here',
      inferenceConfig: {
        temperature: 0.0,
        topP: 1,
        topK: 250,
        maximumLength: 1,
        stopSequences: ["\n\nHuman:"],
      },
    }
  ])
});
python
agent = bedrock.Agent(self, "Agent",
    foundation_model=bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
    instruction="You are a helpful assistant.",
    prompt_override_configuration=bedrock.PromptOverrideConfiguration.from_steps([
        step_type=bedrock.AgentStepType.PRE_PROCESSING,
        step_enabled=True,
        custom_prompt_template="Your custom prompt template here",
        inference_config=bedrock.InferenceConfiguration(
            temperature=0,
            top_p=1,
            top_k=250,
            maximum_length=1,
            stop_sequences=["\n\nHuman:"]
        )

    ])
)
java
Agent agent = Agent.Builder.create(this, "Agent")
        .foundationModel(BedrockFoundationModel.AMAZON_NOVA_LITE_V1)
        .instruction("You are a helpful assistant.")
        .promptOverrideConfiguration(PromptOverrideConfiguration.fromSteps(List.of(PromptStepConfigBase.builder()
                .stepType(AgentStepType.PRE_PROCESSING)
                .stepEnabled(true)
                .customPromptTemplate("Your custom prompt template here")
                .inferenceConfig(InferenceConfiguration.builder()
                        .temperature(0)
                        .topP(1)
                        .topK(250)
                        .maximumLength(1)
                        .stopSequences(List.of("\n\nHuman:"))
                        .build())
                .build())))
        .build();
csharp
var agent = new Agent(this, "Agent", new AgentProps {
    FoundationModel = BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
    Instruction = "You are a helpful assistant.",
    PromptOverrideConfiguration = PromptOverrideConfiguration.FromSteps(new [] { new PromptStepConfigBase {
        StepType = AgentStepType.PRE_PROCESSING,
        StepEnabled = true,
        CustomPromptTemplate = "Your custom prompt template here",
        InferenceConfig = new InferenceConfiguration {
            Temperature = 0,
            TopP = 1,
            TopK = 250,
            MaximumLength = 1,
            StopSequences = new [] { @"

                Human:" }
        }
    } })
});
go
agent := bedrock.NewAgent(this, jsii.String("Agent"), &AgentProps{
	FoundationModel: bedrock.BedrockFoundationModel_AMAZON_NOVA_LITE_V1(),
	Instruction: jsii.String("You are a helpful assistant."),
	PromptOverrideConfiguration: bedrock.PromptOverrideConfiguration_FromSteps([]PromptStepConfigBase{
		&PromptStepConfigBase{
			StepType: bedrock.AgentStepType_PRE_PROCESSING,
			StepEnabled: jsii.Boolean(true),
			CustomPromptTemplate: jsii.String("Your custom prompt template here"),
			InferenceConfig: &InferenceConfiguration{
				Temperature: jsii.Number(0),
				TopP: jsii.Number(1),
				TopK: jsii.Number(250),
				MaximumLength: jsii.Number(1),
				StopSequences: []*string{
					jsii.String("\n\nHuman:"),
				},
			},
		},
	}),
})

Example with routing classifier and foundation model:

ts
const agent = new bedrock.Agent(this, 'Agent', {
  foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
  instruction: 'You are a helpful assistant.',
  promptOverrideConfiguration: bedrock.PromptOverrideConfiguration.fromSteps([
    {
      stepType: bedrock.AgentStepType.ROUTING_CLASSIFIER,
      stepEnabled: true,
      customPromptTemplate: 'Your routing template here',
      foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_V2
    } as bedrock.PromptRoutingClassifierConfigCustomParser
  ])
});
python
agent = bedrock.Agent(self, "Agent",
    foundation_model=bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
    instruction="You are a helpful assistant.",
    prompt_override_configuration=bedrock.PromptOverrideConfiguration.from_steps([
        step_type=bedrock.AgentStepType.ROUTING_CLASSIFIER,
        step_enabled=True,
        custom_prompt_template="Your routing template here",
        foundation_model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_V2

    ])
)
java
Agent agent = Agent.Builder.create(this, "Agent")
        .foundationModel(BedrockFoundationModel.AMAZON_NOVA_LITE_V1)
        .instruction("You are a helpful assistant.")
        .promptOverrideConfiguration(PromptOverrideConfiguration.fromSteps(List.of((PromptRoutingClassifierConfigCustomParser)PromptRoutingClassifierConfigCustomParser.builder()
                .stepType(AgentStepType.ROUTING_CLASSIFIER)
                .stepEnabled(true)
                .customPromptTemplate("Your routing template here")
                .foundationModel(BedrockFoundationModel.ANTHROPIC_CLAUDE_V2)
                .build())))
        .build();
csharp
var agent = new Agent(this, "Agent", new AgentProps {
    FoundationModel = BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
    Instruction = "You are a helpful assistant.",
    PromptOverrideConfiguration = PromptOverrideConfiguration.FromSteps(new [] { (PromptRoutingClassifierConfigCustomParser)new PromptRoutingClassifierConfigCustomParser {
        StepType = AgentStepType.ROUTING_CLASSIFIER,
        StepEnabled = true,
        CustomPromptTemplate = "Your routing template here",
        FoundationModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_V2
    } })
});
go
agent := bedrock.NewAgent(this, jsii.String("Agent"), &AgentProps{
	FoundationModel: bedrock.BedrockFoundationModel_AMAZON_NOVA_LITE_V1(),
	Instruction: jsii.String("You are a helpful assistant."),
	PromptOverrideConfiguration: bedrock.PromptOverrideConfiguration_FromSteps([]PromptStepConfigBase{
		&PromptRoutingClassifierConfigCustomParser{
			StepType: bedrock.AgentStepType_ROUTING_CLASSIFIER,
			StepEnabled: jsii.Boolean(true),
			CustomPromptTemplate: jsii.String("Your routing template here"),
			FoundationModel: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_V2(),
		}.(PromptRoutingClassifierConfigCustomParser),
	}),
})

Using a custom Lambda parser:

ts
const parserFunction = new lambda.Function(this, 'ParserFunction', {
  runtime: lambda.Runtime.PYTHON_3_10,
  handler: 'index.handler',
  code: lambda.Code.fromAsset('lambda'),
});

const agent = new bedrock.Agent(this, 'Agent', {
  foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
  instruction: 'You are a helpful assistant.',
  promptOverrideConfiguration: bedrock.PromptOverrideConfiguration.withCustomParser({
    parser: parserFunction,
    preProcessingStep: {
      stepType: bedrock.AgentStepType.PRE_PROCESSING,
      useCustomParser: true
    }
  })
});
python
parser_function = lambda_.Function(self, "ParserFunction",
    runtime=lambda_.Runtime.PYTHON_3_10,
    handler="index.handler",
    code=lambda_.Code.from_asset("lambda")
)

agent = bedrock.Agent(self, "Agent",
    foundation_model=bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
    instruction="You are a helpful assistant.",
    prompt_override_configuration=bedrock.PromptOverrideConfiguration.with_custom_parser(
        parser=parser_function,
        pre_processing_step=bedrock.PromptPreProcessingConfigCustomParser(
            step_type=bedrock.AgentStepType.PRE_PROCESSING,
            use_custom_parser=True
        )
    )
)
java
Function parserFunction = Function.Builder.create(this, "ParserFunction")
        .runtime(Runtime.PYTHON_3_10)
        .handler("index.handler")
        .code(Code.fromAsset("lambda"))
        .build();

Agent agent = Agent.Builder.create(this, "Agent")
        .foundationModel(BedrockFoundationModel.AMAZON_NOVA_LITE_V1)
        .instruction("You are a helpful assistant.")
        .promptOverrideConfiguration(PromptOverrideConfiguration.withCustomParser(CustomParserProps.builder()
                .parser(parserFunction)
                .preProcessingStep(PromptPreProcessingConfigCustomParser.builder()
                        .stepType(AgentStepType.PRE_PROCESSING)
                        .useCustomParser(true)
                        .build())
                .build()))
        .build();
csharp
var parserFunction = new Function(this, "ParserFunction", new FunctionProps {
    Runtime = Runtime.PYTHON_3_10,
    Handler = "index.handler",
    Code = Code.FromAsset("lambda")
});

var agent = new Agent(this, "Agent", new AgentProps {
    FoundationModel = BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
    Instruction = "You are a helpful assistant.",
    PromptOverrideConfiguration = PromptOverrideConfiguration.WithCustomParser(new CustomParserProps {
        Parser = parserFunction,
        PreProcessingStep = new PromptPreProcessingConfigCustomParser {
            StepType = AgentStepType.PRE_PROCESSING,
            UseCustomParser = true
        }
    })
});
go
parserFunction := lambda.NewFunction(this, jsii.String("ParserFunction"), &FunctionProps{
	Runtime: lambda.Runtime_PYTHON_3_10(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromAsset(jsii.String("lambda")),
})

agent := bedrock.NewAgent(this, jsii.String("Agent"), &AgentProps{
	FoundationModel: bedrock.BedrockFoundationModel_AMAZON_NOVA_LITE_V1(),
	Instruction: jsii.String("You are a helpful assistant."),
	PromptOverrideConfiguration: bedrock.PromptOverrideConfiguration_WithCustomParser(&CustomParserProps{
		Parser: parserFunction,
		PreProcessingStep: &PromptPreProcessingConfigCustomParser{
			StepType: bedrock.AgentStepType_PRE_PROCESSING,
			UseCustomParser: jsii.Boolean(true),
		},
	}),
})

Foundation models can only be specified for the ROUTING_CLASSIFIER step.

Memory Configuration ​

Agents can maintain context across multiple sessions and recall past interactions using memory. This feature is useful for creating a more coherent conversational experience.

Memory Configuration Properties ​

NameTypeRequiredDescription
maxRecentSessionsnumberNoMaximum number of recent session summaries to retain
memoryDurationDurationNoHow long to retain session summaries

Example:

ts
const agent = new bedrock.Agent(this, 'MyAgent', {
  agentName: 'MyAgent',
  instruction: 'Your instruction here',
  foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
  memory: Memory.sessionSummary({
    maxRecentSessions: 10, // Keep the last 10 session summaries
    memoryDuration: Duration.days(20), // Retain summaries for 20 days
  }),
});
python
agent = bedrock.Agent(self, "MyAgent",
    agent_name="MyAgent",
    instruction="Your instruction here",
    foundation_model=bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
    memory=Memory.session_summary(
        max_recent_sessions=10,  # Keep the last 10 session summaries
        memory_duration=Duration.days(20)
    )
)
java
Agent agent = Agent.Builder.create(this, "MyAgent")
        .agentName("MyAgent")
        .instruction("Your instruction here")
        .foundationModel(BedrockFoundationModel.AMAZON_NOVA_LITE_V1)
        .memory(Memory.sessionSummary(SessionSummaryMemoryProps.builder()
                .maxRecentSessions(10) // Keep the last 10 session summaries
                .memoryDuration(Duration.days(20))
                .build()))
        .build();
csharp
var agent = new Agent(this, "MyAgent", new AgentProps {
    AgentName = "MyAgent",
    Instruction = "Your instruction here",
    FoundationModel = BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
    Memory = Memory.SessionSummary(new SessionSummaryMemoryProps {
        MaxRecentSessions = 10,  // Keep the last 10 session summaries
        MemoryDuration = Duration.Days(20)
    })
});
go
agent := bedrock.NewAgent(this, jsii.String("MyAgent"), &AgentProps{
	AgentName: jsii.String("MyAgent"),
	Instruction: jsii.String("Your instruction here"),
	FoundationModel: bedrock.BedrockFoundationModel_AMAZON_NOVA_LITE_V1(),
	Memory: awsbedrockalpha.Memory_SessionSummary(&SessionSummaryMemoryProps{
		MaxRecentSessions: jsii.Number(10),
		 // Keep the last 10 session summaries
		MemoryDuration: awscdk.Duration_Days(jsii.Number(20)),
	}),
})

Agent Collaboration ​

Agent Collaboration enables multiple Bedrock Agents to work together on complex tasks. This feature allows agents to specialize in different areas and collaborate to provide more comprehensive responses to user queries.

Agent Collaboration Properties ​

NameTypeRequiredDescription
typeAgentCollaboratorTypeYesType of collaboration (SUPERVISOR or PEER)
collaboratorsAgentCollaborator[]YesList of agent collaborators

Agent Collaborator Properties ​

NameTypeRequiredDescription
agentAliasAgentAliasYesThe agent alias to collaborate with
collaborationInstructionstringYesInstructions for how to collaborate with this agent
collaboratorNamestringYesName of the collaborator
relayConversationHistorybooleanNoWhether to relay conversation history to the collaborator. Defaults to false

Example:

ts
// Create a specialized agent
const customerSupportAgent = new bedrock.Agent(this, 'CustomerSupportAgent', {
  instruction: 'You specialize in answering customer support questions.',
  foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
});

// Create an agent alias
const customerSupportAlias = new bedrock.AgentAlias(this, 'CustomerSupportAlias', {
  agent: customerSupportAgent,
  agentAliasName: 'production',
});

// Create a main agent that collaborates with the specialized agent
const mainAgent = new bedrock.Agent(this, 'MainAgent', {
  instruction: 'You route specialized questions to other agents.',
  foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
  agentCollaboration: {
    type: bedrock.AgentCollaboratorType.SUPERVISOR,
    collaborators: [
      new bedrock.AgentCollaborator({
        agentAlias: customerSupportAlias,
        collaborationInstruction: 'Route customer support questions to this agent.',
        collaboratorName: 'CustomerSupport',
        relayConversationHistory: true
      }),
    ],
  },
});
python
# Create a specialized agent
customer_support_agent = bedrock.Agent(self, "CustomerSupportAgent",
    instruction="You specialize in answering customer support questions.",
    foundation_model=bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1
)

# Create an agent alias
customer_support_alias = bedrock.AgentAlias(self, "CustomerSupportAlias",
    agent=customer_support_agent,
    agent_alias_name="production"
)

# Create a main agent that collaborates with the specialized agent
main_agent = bedrock.Agent(self, "MainAgent",
    instruction="You route specialized questions to other agents.",
    foundation_model=bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
    agent_collaboration={
        "type": bedrock.AgentCollaboratorType.SUPERVISOR,
        "collaborators": [
            bedrock.AgentCollaborator(
                agent_alias=customer_support_alias,
                collaboration_instruction="Route customer support questions to this agent.",
                collaborator_name="CustomerSupport",
                relay_conversation_history=True
            )
        ]
    }
)
java
// Create a specialized agent
Agent customerSupportAgent = Agent.Builder.create(this, "CustomerSupportAgent")
        .instruction("You specialize in answering customer support questions.")
        .foundationModel(BedrockFoundationModel.AMAZON_NOVA_LITE_V1)
        .build();

// Create an agent alias
AgentAlias customerSupportAlias = AgentAlias.Builder.create(this, "CustomerSupportAlias")
        .agent(customerSupportAgent)
        .agentAliasName("production")
        .build();

// Create a main agent that collaborates with the specialized agent
Agent mainAgent = Agent.Builder.create(this, "MainAgent")
        .instruction("You route specialized questions to other agents.")
        .foundationModel(BedrockFoundationModel.AMAZON_NOVA_LITE_V1)
        .agentCollaboration(Map.of(
                "type", AgentCollaboratorType.SUPERVISOR,
                "collaborators", List.of(
                    AgentCollaborator.Builder.create()
                            .agentAlias(customerSupportAlias)
                            .collaborationInstruction("Route customer support questions to this agent.")
                            .collaboratorName("CustomerSupport")
                            .relayConversationHistory(true)
                            .build())))
        .build();
csharp
// Create a specialized agent
var customerSupportAgent = new Agent(this, "CustomerSupportAgent", new AgentProps {
    Instruction = "You specialize in answering customer support questions.",
    FoundationModel = BedrockFoundationModel.AMAZON_NOVA_LITE_V1
});

// Create an agent alias
var customerSupportAlias = new AgentAlias(this, "CustomerSupportAlias", new AgentAliasProps {
    Agent = customerSupportAgent,
    AgentAliasName = "production"
});

// Create a main agent that collaborates with the specialized agent
var mainAgent = new Agent(this, "MainAgent", new AgentProps {
    Instruction = "You route specialized questions to other agents.",
    FoundationModel = BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
    AgentCollaboration = new Dictionary<string, object> {
        { "type", AgentCollaboratorType.SUPERVISOR },
        { "collaborators", new [] {
            new AgentCollaborator(new AgentCollaboratorProps {
                AgentAlias = customerSupportAlias,
                CollaborationInstruction = "Route customer support questions to this agent.",
                CollaboratorName = "CustomerSupport",
                RelayConversationHistory = true
            }) } }
    }
});
go
// Create a specialized agent
customerSupportAgent := bedrock.NewAgent(this, jsii.String("CustomerSupportAgent"), &AgentProps{
	Instruction: jsii.String("You specialize in answering customer support questions."),
	FoundationModel: bedrock.BedrockFoundationModel_AMAZON_NOVA_LITE_V1(),
})

// Create an agent alias
customerSupportAlias := bedrock.NewAgentAlias(this, jsii.String("CustomerSupportAlias"), &AgentAliasProps{
	Agent: customerSupportAgent,
	AgentAliasName: jsii.String("production"),
})

// Create a main agent that collaborates with the specialized agent
mainAgent := bedrock.NewAgent(this, jsii.String("MainAgent"), &AgentProps{
	Instruction: jsii.String("You route specialized questions to other agents."),
	FoundationModel: bedrock.BedrockFoundationModel_AMAZON_NOVA_LITE_V1(),
	AgentCollaboration: map[string]interface{}{
		"type": bedrock.AgentCollaboratorType_SUPERVISOR,
		"collaborators": []AgentCollaborator{
			bedrock.NewAgentCollaborator(&AgentCollaboratorProps{
				"agentAlias": customerSupportAlias,
				"collaborationInstruction": jsii.String("Route customer support questions to this agent."),
				"collaboratorName": jsii.String("CustomerSupport"),
				"relayConversationHistory": jsii.Boolean(true),
			}),
		},
	},
})

Custom Orchestration ​

Custom Orchestration allows you to override the default agent orchestration flow with your own Lambda function. This enables more control over how the agent processes user inputs and invokes action groups.

When you provide a customOrchestrationExecutor, the agent's orchestrationType is automatically set to CUSTOM_ORCHESTRATION. If no customOrchestrationExecutor is provided, the orchestrationType defaults to DEFAULT, using Amazon Bedrock's built-in orchestration.

Custom Orchestration Properties ​

NameTypeRequiredDescription
functionlambda.IFunctionYesThe Lambda function that implements the custom orchestration logic

Example:

ts
const orchestrationFunction = new lambda.Function(this, 'OrchestrationFunction', {
  runtime: lambda.Runtime.PYTHON_3_10,
  handler: 'index.handler',
  code: lambda.Code.fromAsset('lambda/orchestration'),
});

const agent = new bedrock.Agent(this, 'CustomOrchestrationAgent', {
  instruction: 'You are a helpful assistant with custom orchestration logic.',
  foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
  customOrchestrationExecutor: bedrock.CustomOrchestrationExecutor.fromLambda(orchestrationFunction),
});
python
orchestration_function = lambda_.Function(self, "OrchestrationFunction",
    runtime=lambda_.Runtime.PYTHON_3_10,
    handler="index.handler",
    code=lambda_.Code.from_asset("lambda/orchestration")
)

agent = bedrock.Agent(self, "CustomOrchestrationAgent",
    instruction="You are a helpful assistant with custom orchestration logic.",
    foundation_model=bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
    custom_orchestration_executor=bedrock.CustomOrchestrationExecutor.from_lambda(orchestration_function)
)
java
Function orchestrationFunction = Function.Builder.create(this, "OrchestrationFunction")
        .runtime(Runtime.PYTHON_3_10)
        .handler("index.handler")
        .code(Code.fromAsset("lambda/orchestration"))
        .build();

Agent agent = Agent.Builder.create(this, "CustomOrchestrationAgent")
        .instruction("You are a helpful assistant with custom orchestration logic.")
        .foundationModel(BedrockFoundationModel.AMAZON_NOVA_LITE_V1)
        .customOrchestrationExecutor(CustomOrchestrationExecutor.fromLambda(orchestrationFunction))
        .build();
csharp
var orchestrationFunction = new Function(this, "OrchestrationFunction", new FunctionProps {
    Runtime = Runtime.PYTHON_3_10,
    Handler = "index.handler",
    Code = Code.FromAsset("lambda/orchestration")
});

var agent = new Agent(this, "CustomOrchestrationAgent", new AgentProps {
    Instruction = "You are a helpful assistant with custom orchestration logic.",
    FoundationModel = BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
    CustomOrchestrationExecutor = CustomOrchestrationExecutor.FromLambda(orchestrationFunction)
});
go
orchestrationFunction := lambda.NewFunction(this, jsii.String("OrchestrationFunction"), &FunctionProps{
	Runtime: lambda.Runtime_PYTHON_3_10(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromAsset(jsii.String("lambda/orchestration")),
})

agent := bedrock.NewAgent(this, jsii.String("CustomOrchestrationAgent"), &AgentProps{
	Instruction: jsii.String("You are a helpful assistant with custom orchestration logic."),
	FoundationModel: bedrock.BedrockFoundationModel_AMAZON_NOVA_LITE_V1(),
	CustomOrchestrationExecutor: bedrock.CustomOrchestrationExecutor_FromLambda(orchestrationFunction),
})

Agent Alias ​

After you have sufficiently iterated on your working draft and are satisfied with the behavior of your agent, you can set it up for deployment and integration into your application by creating aliases.

To deploy your agent, you need to create an alias. During alias creation, Amazon Bedrock automatically creates a version of your agent. The alias points to this newly created version. You can point the alias to a previously created version if necessary. You then configure your application to make API calls to that alias.

By default, the Agent resource creates a test alias named 'AgentTestAlias' that points to the 'DRAFT' version. This test alias is accessible via the testAlias property of the agent. You can also create additional aliases for different environments using the AgentAlias construct.

Agent Alias Properties ​

NameTypeRequiredDescription
agentAgentYesThe agent to create an alias for
agentAliasNamestringNoThe name of the agent alias. Defaults to a name generated by CDK
descriptionstringNoA description of the agent alias. Defaults to no description
routingConfigurationAgentAliasRoutingConfigurationNoConfiguration for routing traffic between agent versions
agentVersionstringNoThe version of the agent to use. If not specified, a new version is created

When redeploying an agent with changes, you must ensure the agent version is updated to avoid deployment failures with "agent already exists" errors. The recommended way to handle this is to include the lastUpdated property in the agent's description, which automatically updates whenever the agent is modified. This ensures a new version is created on each deployment.

Example:

ts
const agent = new bedrock.Agent(this, 'Agent', {
  foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
  instruction: 'You are a helpful and friendly agent that answers questions about literature.',
});

const agentAlias = new bedrock.AgentAlias(this, 'myAlias', {
  agentAliasName: 'production',
  agent: agent,
  description: `Production version of my agent. Created at ${agent.lastUpdated}` // ensure the version update
});
python
agent = bedrock.Agent(self, "Agent",
    foundation_model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
    instruction="You are a helpful and friendly agent that answers questions about literature."
)

agent_alias = bedrock.AgentAlias(self, "myAlias",
    agent_alias_name="production",
    agent=agent,
    description=f"Production version of my agent. Created at {agent.lastUpdated}"
)
java
Agent agent = Agent.Builder.create(this, "Agent")
        .foundationModel(BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0)
        .instruction("You are a helpful and friendly agent that answers questions about literature.")
        .build();

AgentAlias agentAlias = AgentAlias.Builder.create(this, "myAlias")
        .agentAliasName("production")
        .agent(agent)
        .description(String.format("Production version of my agent. Created at %s", agent.getLastUpdated()))
        .build();
csharp
var agent = new Agent(this, "Agent", new AgentProps {
    FoundationModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
    Instruction = "You are a helpful and friendly agent that answers questions about literature."
});

var agentAlias = new AgentAlias(this, "myAlias", new AgentAliasProps {
    AgentAliasName = "production",
    Agent = agent,
    Description = $"Production version of my agent. Created at {agent.lastUpdated}"
});
go
agent := bedrock.NewAgent(this, jsii.String("Agent"), &AgentProps{
	FoundationModel: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_HAIKU_V1_0(),
	Instruction: jsii.String("You are a helpful and friendly agent that answers questions about literature."),
})

agentAlias := bedrock.NewAgentAlias(this, jsii.String("myAlias"), &AgentAliasProps{
	AgentAliasName: jsii.String("production"),
	Agent: agent,
	Description: fmt.Sprintf("Production version of my agent. Created at %v", agent.LastUpdated),
})

Guardrails ​

Amazon Bedrock's Guardrails feature enables you to implement robust governance and control mechanisms for your generative AI applications, ensuring alignment with your specific use cases and responsible AI policies. Guardrails empowers you to create multiple tailored policy configurations, each designed to address the unique requirements and constraints of different use cases. These policy configurations can then be seamlessly applied across multiple foundation models (FMs) and Agents, ensuring a consistent user experience and standardizing safety, security, and privacy controls throughout your generative AI ecosystem.

With Guardrails, you can define and enforce granular, customizable policies to precisely govern the behavior of your generative AI applications. You can configure the following policies in a guardrail to avoid undesirable and harmful content and remove sensitive information for privacy protection.

Content filters – Adjust filter strengths to block input prompts or model responses containing harmful content. Denied topics – Define a set of topics that are undesirable in the context of your application. These topics will be blocked if detected in user queries or model responses. Word filters – Configure filters to block undesirable words, phrases, and profanity. Such words can include offensive terms, competitor names etc. Sensitive information filters – Block or mask sensitive information such as personally identifiable information (PII) or custom regex in user inputs and model responses. You can create a Guardrail with a minimum blockedInputMessaging, blockedOutputsMessaging and default content filter policy.

Basic Guardrail Creation ​

TypeScript ​

ts
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
  guardrailName: 'my-BedrockGuardrails',
  description: 'Legal ethical guardrails.',
});

// add at least one policy for the guardrail
python
guardrail = bedrock.Guardrail(self, "bedrockGuardrails",
    guardrail_name="my-BedrockGuardrails",
    description="Legal ethical guardrails."
)
java
Guardrail guardrail = Guardrail.Builder.create(this, "bedrockGuardrails")
        .guardrailName("my-BedrockGuardrails")
        .description("Legal ethical guardrails.")
        .build();
csharp
var guardrail = new Guardrail(this, "bedrockGuardrails", new GuardrailProps {
    GuardrailName = "my-BedrockGuardrails",
    Description = "Legal ethical guardrails."
});
go
guardrail := bedrock.NewGuardrail(this, jsii.String("bedrockGuardrails"), &GuardrailProps{
	GuardrailName: jsii.String("my-BedrockGuardrails"),
	Description: jsii.String("Legal ethical guardrails."),
})

Guardrail Properties ​

PropertyTypeRequiredDescription
guardrailNamestringYesThe name of the guardrail
descriptionstringNoThe description of the guardrail
blockedInputMessagingstringNoThe message to return when the guardrail blocks a prompt. Default: "Sorry, your query violates our usage policy."
blockedOutputsMessagingstringNoThe message to return when the guardrail blocks a model response. Default: "Sorry, I am unable to answer your question because of our usage policy."
kmsKeyIKeyNoA custom KMS key to use for encrypting data. Default: Your data is encrypted by default with a key that AWS owns and manages for you.
crossRegionConfigGuardrailCrossRegionConfigPropertyNoThe cross-region configuration for the guardrail. This enables cross-region inference for enhanced language support and filtering capabilities. Default: No cross-region configuration
contentFiltersContentFilter[]NoThe content filters to apply to the guardrail
contentFiltersTierConfigTierConfigNoThe tier configuration to apply to content filters. Default: TierConfig.CLASSIC
deniedTopicsTopic[]NoUp to 30 denied topics to block user inputs or model responses associated with the topic
topicsTierConfigTierConfigNoThe tier configuration to apply to topic filters. Default: TierConfig.CLASSIC
wordFiltersstring[]NoThe word filters to apply to the guardrail
managedWordListFiltersManagedWordFilterType[]NoThe managed word filters to apply to the guardrail
piiFiltersPIIFilter[]NoThe PII filters to apply to the guardrail
regexFiltersRegexFilter[]NoThe regular expression (regex) filters to apply to the guardrail
contextualGroundingFiltersContextualGroundingFilter[]NoThe contextual grounding filters to apply to the guardrail

Filter Types ​

Content Filters ​

Content filters allow you to block input prompts or model responses containing harmful content. You can adjust the filter strength and configure separate actions for input and output.

Content Filter Configuration ​
ts
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
  guardrailName: 'my-BedrockGuardrails',
  // Configure tier for content filters (optional)
  contentFiltersTierConfig: bedrock.TierConfig.STANDARD,
});

guardrail.addContentFilter({
  type: bedrock.ContentFilterType.SEXUAL,
  inputStrength: bedrock.ContentFilterStrength.HIGH,
  outputStrength: bedrock.ContentFilterStrength.MEDIUM,
  // props below are optional
  inputAction: bedrock.GuardrailAction.BLOCK,
  inputEnabled: true,
  outputAction: bedrock.GuardrailAction.NONE,
  outputEnabled: true,
  inputModalities: [bedrock.ModalityType.TEXT, bedrock.ModalityType.IMAGE],
  outputModalities: [bedrock.ModalityType.TEXT],
});
python
guardrail = bedrock.Guardrail(self, "bedrockGuardrails",
    guardrail_name="my-BedrockGuardrails",
    # Configure tier for content filters (optional)
    content_filters_tier_config=bedrock.TierConfig.STANDARD
)

guardrail.add_content_filter(
    type=bedrock.ContentFilterType.SEXUAL,
    input_strength=bedrock.ContentFilterStrength.HIGH,
    output_strength=bedrock.ContentFilterStrength.MEDIUM,
    # props below are optional
    input_action=bedrock.GuardrailAction.BLOCK,
    input_enabled=True,
    output_action=bedrock.GuardrailAction.NONE,
    output_enabled=True,
    input_modalities=[bedrock.ModalityType.TEXT, bedrock.ModalityType.IMAGE],
    output_modalities=[bedrock.ModalityType.TEXT]
)
java
Guardrail guardrail = Guardrail.Builder.create(this, "bedrockGuardrails")
        .guardrailName("my-BedrockGuardrails")
        // Configure tier for content filters (optional)
        .contentFiltersTierConfig(TierConfig.STANDARD)
        .build();

guardrail.addContentFilter(ContentFilter.builder()
        .type(ContentFilterType.SEXUAL)
        .inputStrength(ContentFilterStrength.HIGH)
        .outputStrength(ContentFilterStrength.MEDIUM)
        // props below are optional
        .inputAction(GuardrailAction.BLOCK)
        .inputEnabled(true)
        .outputAction(GuardrailAction.NONE)
        .outputEnabled(true)
        .inputModalities(List.of(ModalityType.TEXT, ModalityType.IMAGE))
        .outputModalities(List.of(ModalityType.TEXT))
        .build());
csharp
var guardrail = new Guardrail(this, "bedrockGuardrails", new GuardrailProps {
    GuardrailName = "my-BedrockGuardrails",
    // Configure tier for content filters (optional)
    ContentFiltersTierConfig = TierConfig.STANDARD
});

guardrail.AddContentFilter(new ContentFilter {
    Type = ContentFilterType.SEXUAL,
    InputStrength = ContentFilterStrength.HIGH,
    OutputStrength = ContentFilterStrength.MEDIUM,
    // props below are optional
    InputAction = GuardrailAction.BLOCK,
    InputEnabled = true,
    OutputAction = GuardrailAction.NONE,
    OutputEnabled = true,
    InputModalities = new [] { ModalityType.TEXT, ModalityType.IMAGE },
    OutputModalities = new [] { ModalityType.TEXT }
});
go
guardrail := bedrock.NewGuardrail(this, jsii.String("bedrockGuardrails"), &GuardrailProps{
	GuardrailName: jsii.String("my-BedrockGuardrails"),
	// Configure tier for content filters (optional)
	ContentFiltersTierConfig: bedrock.TierConfig_STANDARD,
})

guardrail.AddContentFilter(&ContentFilter{
	Type: bedrock.ContentFilterType_SEXUAL,
	InputStrength: bedrock.ContentFilterStrength_HIGH,
	OutputStrength: bedrock.ContentFilterStrength_MEDIUM,
	// props below are optional
	InputAction: bedrock.GuardrailAction_BLOCK,
	InputEnabled: jsii.Boolean(true),
	OutputAction: bedrock.GuardrailAction_NONE,
	OutputEnabled: jsii.Boolean(true),
	InputModalities: []ModalityType{
		bedrock.ModalityType_TEXT,
		bedrock.ModalityType_IMAGE,
	},
	OutputModalities: []ModalityType{
		bedrock.ModalityType_TEXT,
	},
})

Available content filter types:

  • SEXUAL: Describes input prompts and model responses that indicates sexual interest, activity, or arousal
  • VIOLENCE: Describes input prompts and model responses that includes glorification of or threats to inflict physical pain
  • HATE: Describes input prompts and model responses that discriminate, criticize, insult, denounce, or dehumanize a person or group
  • INSULTS: Describes input prompts and model responses that includes demeaning, humiliating, mocking, insulting, or belittling language
  • MISCONDUCT: Describes input prompts and model responses that seeks or provides information about engaging in misconduct activity
  • PROMPT_ATTACK: Enable to detect and block user inputs attempting to override system instructions

Available content filter strengths:

  • NONE: No filtering
  • LOW: Light filtering
  • MEDIUM: Moderate filtering
  • HIGH: Strict filtering

Available guardrail actions:

  • BLOCK: Blocks the content from being processed
  • ANONYMIZE: Masks the content with an identifier tag
  • NONE: Takes no action

Warning: the ANONYMIZE action is not available in all configurations. Please refer to the documentation of each filter to see which ones support

Available modality types:

  • TEXT: Text modality for content filters
  • IMAGE: Image modality for content filters

Tier Configuration ​

Guardrails support tier configurations that determine the level of language support and robustness for content and topic filters. You can configure separate tier settings for content filters and topic filters.

Tier Configuration Options ​
ts
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
  guardrailName: 'my-BedrockGuardrails',
  // Configure tier for content filters
  contentFiltersTierConfig: bedrock.TierConfig.STANDARD,
  // Configure tier for topic filters
  topicsTierConfig: bedrock.TierConfig.CLASSIC,
});
python
guardrail = bedrock.Guardrail(self, "bedrockGuardrails",
    guardrail_name="my-BedrockGuardrails",
    # Configure tier for content filters
    content_filters_tier_config=bedrock.TierConfig.STANDARD,
    # Configure tier for topic filters
    topics_tier_config=bedrock.TierConfig.CLASSIC
)
java
Guardrail guardrail = Guardrail.Builder.create(this, "bedrockGuardrails")
        .guardrailName("my-BedrockGuardrails")
        // Configure tier for content filters
        .contentFiltersTierConfig(TierConfig.STANDARD)
        // Configure tier for topic filters
        .topicsTierConfig(TierConfig.CLASSIC)
        .build();
csharp
var guardrail = new Guardrail(this, "bedrockGuardrails", new GuardrailProps {
    GuardrailName = "my-BedrockGuardrails",
    // Configure tier for content filters
    ContentFiltersTierConfig = TierConfig.STANDARD,
    // Configure tier for topic filters
    TopicsTierConfig = TierConfig.CLASSIC
});
go
guardrail := bedrock.NewGuardrail(this, jsii.String("bedrockGuardrails"), &GuardrailProps{
	GuardrailName: jsii.String("my-BedrockGuardrails"),
	// Configure tier for content filters
	ContentFiltersTierConfig: bedrock.TierConfig_STANDARD,
	// Configure tier for topic filters
	TopicsTierConfig: bedrock.TierConfig_CLASSIC,
})

Available tier configurations:

  • CLASSIC: Provides established guardrails functionality supporting English, French, and Spanish languages
  • STANDARD: Provides a more robust solution than the CLASSIC tier and has more comprehensive language support. This tier requires that your guardrail use cross-Region inference

Note: The STANDARD tier provides enhanced language support and more comprehensive filtering capabilities, but requires cross-Region inference to be enabled for your guardrail.

Cross-Region Configuration ​

You can configure a system-defined guardrail profile to use with your guardrail. Guardrail profiles define the destination AWS Regions where guardrail inference requests can be automatically routed. Using guardrail profiles helps maintain guardrail performance and reliability when demand increases.

Cross-Region Configuration Properties ​
PropertyTypeRequiredDescription
guardrailProfileArnstringYesThe ARN of the system-defined guardrail profile that defines the destination AWS Regions where guardrail inference requests can be automatically routed
Cross-Region Configuration Example ​
ts
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
  guardrailName: 'my-BedrockGuardrails',
  description: 'Guardrail with cross-region configuration for enhanced language support',
  crossRegionConfig: {
    guardrailProfileArn: 'arn:aws:bedrock:us-east-1:123456789012:guardrail-profile/my-profile',
  },
  // Use STANDARD tier for enhanced capabilities
  contentFiltersTierConfig: bedrock.TierConfig.STANDARD,
  topicsTierConfig: bedrock.TierConfig.STANDARD,
});
python
guardrail = bedrock.Guardrail(self, "bedrockGuardrails",
    guardrail_name="my-BedrockGuardrails",
    description="Guardrail with cross-region configuration for enhanced language support",
    cross_region_config=bedrock.GuardrailCrossRegionConfigProperty(
        guardrail_profile_arn="arn:aws:bedrock:us-east-1:123456789012:guardrail-profile/my-profile"
    ),
    # Use STANDARD tier for enhanced capabilities
    content_filters_tier_config=bedrock.TierConfig.STANDARD,
    topics_tier_config=bedrock.TierConfig.STANDARD
)
java
Guardrail guardrail = Guardrail.Builder.create(this, "bedrockGuardrails")
        .guardrailName("my-BedrockGuardrails")
        .description("Guardrail with cross-region configuration for enhanced language support")
        .crossRegionConfig(GuardrailCrossRegionConfigProperty.builder()
                .guardrailProfileArn("arn:aws:bedrock:us-east-1:123456789012:guardrail-profile/my-profile")
                .build())
        // Use STANDARD tier for enhanced capabilities
        .contentFiltersTierConfig(TierConfig.STANDARD)
        .topicsTierConfig(TierConfig.STANDARD)
        .build();
csharp
var guardrail = new Guardrail(this, "bedrockGuardrails", new GuardrailProps {
    GuardrailName = "my-BedrockGuardrails",
    Description = "Guardrail with cross-region configuration for enhanced language support",
    CrossRegionConfig = new GuardrailCrossRegionConfigProperty {
        GuardrailProfileArn = "arn:aws:bedrock:us-east-1:123456789012:guardrail-profile/my-profile"
    },
    // Use STANDARD tier for enhanced capabilities
    ContentFiltersTierConfig = TierConfig.STANDARD,
    TopicsTierConfig = TierConfig.STANDARD
});
go
guardrail := bedrock.NewGuardrail(this, jsii.String("bedrockGuardrails"), &GuardrailProps{
	GuardrailName: jsii.String("my-BedrockGuardrails"),
	Description: jsii.String("Guardrail with cross-region configuration for enhanced language support"),
	CrossRegionConfig: &GuardrailCrossRegionConfigProperty{
		GuardrailProfileArn: jsii.String("arn:aws:bedrock:us-east-1:123456789012:guardrail-profile/my-profile"),
	},
	// Use STANDARD tier for enhanced capabilities
	ContentFiltersTierConfig: bedrock.TierConfig_STANDARD,
	TopicsTierConfig: bedrock.TierConfig_STANDARD,
})

Note: Cross-region configuration is required when using the STANDARD tier for content and topic filters. It helps maintain guardrail performance and reliability when demand increases by automatically routing inference requests to appropriate regions.

You will need to provide the necessary permissions for cross region: https://docs.aws.amazon.com/bedrock/latest/userguide/guardrail-profiles-permissions.html .

Denied Topics ​

Denied topics allow you to define a set of topics that are undesirable in the context of your application. These topics will be blocked if detected in user queries or model responses. You can configure separate actions for input and output.

Denied Topic Configuration ​
ts
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
  guardrailName: 'my-BedrockGuardrails',
  // Configure tier for topic filters (optional)
  topicsTierConfig: bedrock.TierConfig.STANDARD,
});

// Use a predefined topic
guardrail.addDeniedTopicFilter(bedrock.Topic.FINANCIAL_ADVICE);

// Create a custom topic with input/output actions
guardrail.addDeniedTopicFilter(
  bedrock.Topic.custom({
    name: 'Legal_Advice',
    definition: 'Offering guidance or suggestions on legal matters, legal actions, interpretation of laws, or legal rights and responsibilities.',
    examples: [
      'Can I sue someone for this?',
      'What are my legal rights in this situation?',
      'Is this action against the law?',
      'What should I do to file a legal complaint?',
      'Can you explain this law to me?',
    ],
    // props below are optional
    inputAction: bedrock.GuardrailAction.BLOCK,
    inputEnabled: true,
    outputAction: bedrock.GuardrailAction.NONE,
    outputEnabled: true,
  })
);
python
guardrail = bedrock.Guardrail(self, "bedrockGuardrails",
    guardrail_name="my-BedrockGuardrails",
    # Configure tier for topic filters (optional)
    topics_tier_config=bedrock.TierConfig.STANDARD
)

# Use a predefined topic
guardrail.add_denied_topic_filter(bedrock.Topic.FINANCIAL_ADVICE)

# Create a custom topic with input/output actions
guardrail.add_denied_topic_filter(
    bedrock.Topic.custom(
        name="Legal_Advice",
        definition="Offering guidance or suggestions on legal matters, legal actions, interpretation of laws, or legal rights and responsibilities.",
        examples=["Can I sue someone for this?", "What are my legal rights in this situation?", "Is this action against the law?", "What should I do to file a legal complaint?", "Can you explain this law to me?"
        ],
        # props below are optional
        input_action=bedrock.GuardrailAction.BLOCK,
        input_enabled=True,
        output_action=bedrock.GuardrailAction.NONE,
        output_enabled=True
    ))
java
Guardrail guardrail = Guardrail.Builder.create(this, "bedrockGuardrails")
        .guardrailName("my-BedrockGuardrails")
        // Configure tier for topic filters (optional)
        .topicsTierConfig(TierConfig.STANDARD)
        .build();

// Use a predefined topic
guardrail.addDeniedTopicFilter(Topic.FINANCIAL_ADVICE);

// Create a custom topic with input/output actions
guardrail.addDeniedTopicFilter(Topic.custom(CustomTopicProps.builder()
        .name("Legal_Advice")
        .definition("Offering guidance or suggestions on legal matters, legal actions, interpretation of laws, or legal rights and responsibilities.")
        .examples(List.of("Can I sue someone for this?", "What are my legal rights in this situation?", "Is this action against the law?", "What should I do to file a legal complaint?", "Can you explain this law to me?"))
        // props below are optional
        .inputAction(GuardrailAction.BLOCK)
        .inputEnabled(true)
        .outputAction(GuardrailAction.NONE)
        .outputEnabled(true)
        .build()));
csharp
var guardrail = new Guardrail(this, "bedrockGuardrails", new GuardrailProps {
    GuardrailName = "my-BedrockGuardrails",
    // Configure tier for topic filters (optional)
    TopicsTierConfig = TierConfig.STANDARD
});

// Use a predefined topic
guardrail.AddDeniedTopicFilter(Topic.FINANCIAL_ADVICE);

// Create a custom topic with input/output actions
guardrail.AddDeniedTopicFilter(Topic.Custom(new CustomTopicProps {
    Name = "Legal_Advice",
    Definition = "Offering guidance or suggestions on legal matters, legal actions, interpretation of laws, or legal rights and responsibilities.",
    Examples = new [] { "Can I sue someone for this?", "What are my legal rights in this situation?", "Is this action against the law?", "What should I do to file a legal complaint?", "Can you explain this law to me?" },
    // props below are optional
    InputAction = GuardrailAction.BLOCK,
    InputEnabled = true,
    OutputAction = GuardrailAction.NONE,
    OutputEnabled = true
}));
go
guardrail := bedrock.NewGuardrail(this, jsii.String("bedrockGuardrails"), &GuardrailProps{
	GuardrailName: jsii.String("my-BedrockGuardrails"),
	// Configure tier for topic filters (optional)
	TopicsTierConfig: bedrock.TierConfig_STANDARD,
})

// Use a predefined topic
guardrail.AddDeniedTopicFilter(bedrock.Topic_FINANCIAL_ADVICE())

// Create a custom topic with input/output actions
guardrail.AddDeniedTopicFilter(bedrock.Topic_Custom(&CustomTopicProps{
	Name: jsii.String("Legal_Advice"),
	Definition: jsii.String("Offering guidance or suggestions on legal matters, legal actions, interpretation of laws, or legal rights and responsibilities."),
	Examples: []*string{
		jsii.String("Can I sue someone for this?"),
		jsii.String("What are my legal rights in this situation?"),
		jsii.String("Is this action against the law?"),
		jsii.String("What should I do to file a legal complaint?"),
		jsii.String("Can you explain this law to me?"),
	},
	// props below are optional
	InputAction: bedrock.GuardrailAction_BLOCK,
	InputEnabled: jsii.Boolean(true),
	OutputAction: bedrock.GuardrailAction_NONE,
	OutputEnabled: jsii.Boolean(true),
}))

Word Filters ​

Word filters allow you to block specific words, phrases, or profanity in user inputs and model responses. You can configure separate actions for input and output.

Word Filter Configuration ​
ts
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
  guardrailName: 'my-BedrockGuardrails',
});

// Add managed word list with input/output actions
guardrail.addManagedWordListFilter({
  type: bedrock.ManagedWordFilterType.PROFANITY,
  inputAction: bedrock.GuardrailAction.BLOCK,
  inputEnabled: true,
  outputAction: bedrock.GuardrailAction.NONE,
  outputEnabled: true,
});

// Add individual words
guardrail.addWordFilter({text: 'drugs'});
guardrail.addWordFilter({text: 'competitor'});

// Add words from a file
guardrail.addWordFilterFromFile('./scripts/wordsPolicy.csv');
python
guardrail = bedrock.Guardrail(self, "bedrockGuardrails",
    guardrail_name="my-BedrockGuardrails"
)

# Add managed word list with input/output actions
guardrail.add_managed_word_list_filter(
    type=bedrock.ManagedWordFilterType.PROFANITY,
    input_action=bedrock.GuardrailAction.BLOCK,
    input_enabled=True,
    output_action=bedrock.GuardrailAction.NONE,
    output_enabled=True
)

# Add individual words
guardrail.add_word_filter(text="drugs")
guardrail.add_word_filter(text="competitor")

# Add words from a file
guardrail.add_word_filter_from_file("./scripts/wordsPolicy.csv")
java
Guardrail guardrail = Guardrail.Builder.create(this, "bedrockGuardrails")
        .guardrailName("my-BedrockGuardrails")
        .build();

// Add managed word list with input/output actions
guardrail.addManagedWordListFilter(ManagedWordFilter.builder()
        .type(ManagedWordFilterType.PROFANITY)
        .inputAction(GuardrailAction.BLOCK)
        .inputEnabled(true)
        .outputAction(GuardrailAction.NONE)
        .outputEnabled(true)
        .build());

// Add individual words
guardrail.addWordFilter(WordFilter.builder().text("drugs").build());
guardrail.addWordFilter(WordFilter.builder().text("competitor").build());

// Add words from a file
guardrail.addWordFilterFromFile("./scripts/wordsPolicy.csv");
csharp
var guardrail = new Guardrail(this, "bedrockGuardrails", new GuardrailProps {
    GuardrailName = "my-BedrockGuardrails"
});

// Add managed word list with input/output actions
guardrail.AddManagedWordListFilter(new ManagedWordFilter {
    Type = ManagedWordFilterType.PROFANITY,
    InputAction = GuardrailAction.BLOCK,
    InputEnabled = true,
    OutputAction = GuardrailAction.NONE,
    OutputEnabled = true
});

// Add individual words
guardrail.AddWordFilter(new WordFilter { Text = "drugs" });
guardrail.AddWordFilter(new WordFilter { Text = "competitor" });

// Add words from a file
guardrail.AddWordFilterFromFile("./scripts/wordsPolicy.csv");
go
guardrail := bedrock.NewGuardrail(this, jsii.String("bedrockGuardrails"), &GuardrailProps{
	GuardrailName: jsii.String("my-BedrockGuardrails"),
})

// Add managed word list with input/output actions
guardrail.AddManagedWordListFilter(&ManagedWordFilter{
	Type: bedrock.ManagedWordFilterType_PROFANITY,
	InputAction: bedrock.GuardrailAction_BLOCK,
	InputEnabled: jsii.Boolean(true),
	OutputAction: bedrock.GuardrailAction_NONE,
	OutputEnabled: jsii.Boolean(true),
})

// Add individual words
guardrail.AddWordFilter(&WordFilter{
	Text: jsii.String("drugs"),
})
guardrail.AddWordFilter(&WordFilter{
	Text: jsii.String("competitor"),
})

// Add words from a file
guardrail.AddWordFilterFromFile(jsii.String("./scripts/wordsPolicy.csv"))

PII Filters ​

PII filters allow you to detect and handle personally identifiable information in user inputs and model responses. You can configure separate actions for input and output.

The PII types are organized into enum-like classes for better type safety and transpilation compatibility:

  • GeneralPIIType: General PII types like addresses, emails, names, phone numbers
  • FinancePIIType: Financial information like credit card numbers, PINs, SWIFT codes
  • InformationTechnologyPIIType: IT-related data like URLs, IP addresses, AWS keys
  • USASpecificPIIType: US-specific identifiers like SSNs, passport numbers
  • CanadaSpecificPIIType: Canada-specific identifiers like health numbers, SINs
  • UKSpecificPIIType: UK-specific identifiers like NHS numbers, NI numbers
PII Filter Configuration ​
ts
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
  guardrailName: 'my-BedrockGuardrails',
});

// Add PII filter for addresses with input/output actions
guardrail.addPIIFilter({
  type: bedrock.GeneralPIIType.ADDRESS,
  action: bedrock.GuardrailAction.BLOCK,
  // below props are optional
  inputAction: bedrock.GuardrailAction.BLOCK,
  inputEnabled: true,
  outputAction: bedrock.GuardrailAction.ANONYMIZE,
  outputEnabled: true,
});

// Add PII filter for credit card numbers with input/output actions
guardrail.addPIIFilter({
  type: bedrock.FinancePIIType.CREDIT_DEBIT_CARD_NUMBER,
  action: bedrock.GuardrailAction.BLOCK,
  // below props are optional
  inputAction: bedrock.GuardrailAction.BLOCK,
  inputEnabled: true,
  outputAction: bedrock.GuardrailAction.ANONYMIZE,
  outputEnabled: true,
});

// Add PII filter for email addresses
guardrail.addPIIFilter({
  type: bedrock.GeneralPIIType.EMAIL,
  action: bedrock.GuardrailAction.ANONYMIZE,
});

// Add PII filter for US Social Security Numbers
guardrail.addPIIFilter({
  type: bedrock.USASpecificPIIType.US_SOCIAL_SECURITY_NUMBER,
  action: bedrock.GuardrailAction.BLOCK,
});

// Add PII filter for IP addresses
guardrail.addPIIFilter({
  type: bedrock.InformationTechnologyPIIType.IP_ADDRESS,
  action: bedrock.GuardrailAction.ANONYMIZE,
});
python
guardrail = bedrock.Guardrail(self, "bedrockGuardrails",
    guardrail_name="my-BedrockGuardrails"
)

# Add PII filter for addresses with input/output actions
guardrail.add_pii_filter(
    type=bedrock.GeneralPIIType.ADDRESS,
    action=bedrock.GuardrailAction.BLOCK,
    # below props are optional
    input_action=bedrock.GuardrailAction.BLOCK,
    input_enabled=True,
    output_action=bedrock.GuardrailAction.ANONYMIZE,
    output_enabled=True
)

# Add PII filter for credit card numbers with input/output actions
guardrail.add_pii_filter(
    type=bedrock.FinancePIIType.CREDIT_DEBIT_CARD_NUMBER,
    action=bedrock.GuardrailAction.BLOCK,
    # below props are optional
    input_action=bedrock.GuardrailAction.BLOCK,
    input_enabled=True,
    output_action=bedrock.GuardrailAction.ANONYMIZE,
    output_enabled=True
)

# Add PII filter for email addresses
guardrail.add_pii_filter(
    type=bedrock.GeneralPIIType.EMAIL,
    action=bedrock.GuardrailAction.ANONYMIZE
)

# Add PII filter for US Social Security Numbers
guardrail.add_pii_filter(
    type=bedrock.USASpecificPIIType.US_SOCIAL_SECURITY_NUMBER,
    action=bedrock.GuardrailAction.BLOCK
)

# Add PII filter for IP addresses
guardrail.add_pii_filter(
    type=bedrock.InformationTechnologyPIIType.IP_ADDRESS,
    action=bedrock.GuardrailAction.ANONYMIZE
)
java
Guardrail guardrail = Guardrail.Builder.create(this, "bedrockGuardrails")
        .guardrailName("my-BedrockGuardrails")
        .build();

// Add PII filter for addresses with input/output actions
guardrail.addPIIFilter(PIIFilter.builder()
        .type(GeneralPIIType.ADDRESS)
        .action(GuardrailAction.BLOCK)
        // below props are optional
        .inputAction(GuardrailAction.BLOCK)
        .inputEnabled(true)
        .outputAction(GuardrailAction.ANONYMIZE)
        .outputEnabled(true)
        .build());

// Add PII filter for credit card numbers with input/output actions
guardrail.addPIIFilter(PIIFilter.builder()
        .type(FinancePIIType.CREDIT_DEBIT_CARD_NUMBER)
        .action(GuardrailAction.BLOCK)
        // below props are optional
        .inputAction(GuardrailAction.BLOCK)
        .inputEnabled(true)
        .outputAction(GuardrailAction.ANONYMIZE)
        .outputEnabled(true)
        .build());

// Add PII filter for email addresses
guardrail.addPIIFilter(PIIFilter.builder()
        .type(GeneralPIIType.EMAIL)
        .action(GuardrailAction.ANONYMIZE)
        .build());

// Add PII filter for US Social Security Numbers
guardrail.addPIIFilter(PIIFilter.builder()
        .type(USASpecificPIIType.US_SOCIAL_SECURITY_NUMBER)
        .action(GuardrailAction.BLOCK)
        .build());

// Add PII filter for IP addresses
guardrail.addPIIFilter(PIIFilter.builder()
        .type(InformationTechnologyPIIType.IP_ADDRESS)
        .action(GuardrailAction.ANONYMIZE)
        .build());
csharp
var guardrail = new Guardrail(this, "bedrockGuardrails", new GuardrailProps {
    GuardrailName = "my-BedrockGuardrails"
});

// Add PII filter for addresses with input/output actions
guardrail.AddPIIFilter(new PIIFilter {
    Type = GeneralPIIType.ADDRESS,
    Action = GuardrailAction.BLOCK,
    // below props are optional
    InputAction = GuardrailAction.BLOCK,
    InputEnabled = true,
    OutputAction = GuardrailAction.ANONYMIZE,
    OutputEnabled = true
});

// Add PII filter for credit card numbers with input/output actions
guardrail.AddPIIFilter(new PIIFilter {
    Type = FinancePIIType.CREDIT_DEBIT_CARD_NUMBER,
    Action = GuardrailAction.BLOCK,
    // below props are optional
    InputAction = GuardrailAction.BLOCK,
    InputEnabled = true,
    OutputAction = GuardrailAction.ANONYMIZE,
    OutputEnabled = true
});

// Add PII filter for email addresses
guardrail.AddPIIFilter(new PIIFilter {
    Type = GeneralPIIType.EMAIL,
    Action = GuardrailAction.ANONYMIZE
});

// Add PII filter for US Social Security Numbers
guardrail.AddPIIFilter(new PIIFilter {
    Type = USASpecificPIIType.US_SOCIAL_SECURITY_NUMBER,
    Action = GuardrailAction.BLOCK
});

// Add PII filter for IP addresses
guardrail.AddPIIFilter(new PIIFilter {
    Type = InformationTechnologyPIIType.IP_ADDRESS,
    Action = GuardrailAction.ANONYMIZE
});
go
guardrail := bedrock.NewGuardrail(this, jsii.String("bedrockGuardrails"), &GuardrailProps{
	GuardrailName: jsii.String("my-BedrockGuardrails"),
})

// Add PII filter for addresses with input/output actions
guardrail.AddPIIFilter(&PIIFilter{
	Type: bedrock.GeneralPIIType_ADDRESS(),
	Action: bedrock.GuardrailAction_BLOCK,
	// below props are optional
	InputAction: bedrock.GuardrailAction_BLOCK,
	InputEnabled: jsii.Boolean(true),
	OutputAction: bedrock.GuardrailAction_ANONYMIZE,
	OutputEnabled: jsii.Boolean(true),
})

// Add PII filter for credit card numbers with input/output actions
guardrail.AddPIIFilter(&PIIFilter{
	Type: bedrock.FinancePIIType_CREDIT_DEBIT_CARD_NUMBER(),
	Action: bedrock.GuardrailAction_BLOCK,
	// below props are optional
	InputAction: bedrock.GuardrailAction_BLOCK,
	InputEnabled: jsii.Boolean(true),
	OutputAction: bedrock.GuardrailAction_ANONYMIZE,
	OutputEnabled: jsii.Boolean(true),
})

// Add PII filter for email addresses
guardrail.AddPIIFilter(&PIIFilter{
	Type: bedrock.GeneralPIIType_EMAIL(),
	Action: bedrock.GuardrailAction_ANONYMIZE,
})

// Add PII filter for US Social Security Numbers
guardrail.AddPIIFilter(&PIIFilter{
	Type: bedrock.USASpecificPIIType_US_SOCIAL_SECURITY_NUMBER(),
	Action: bedrock.GuardrailAction_BLOCK,
})

// Add PII filter for IP addresses
guardrail.AddPIIFilter(&PIIFilter{
	Type: bedrock.InformationTechnologyPIIType_IP_ADDRESS(),
	Action: bedrock.GuardrailAction_ANONYMIZE,
})
Available PII Types ​

GeneralPIIType:

  • ADDRESS: Physical addresses
  • AGE: Individual's age
  • DRIVER_ID: Driver's license numbers
  • EMAIL: Email addresses
  • LICENSE_PLATE: Vehicle license plates
  • NAME: Individual names
  • PASSWORD: Passwords
  • PHONE: Phone numbers
  • USERNAME: User account names
  • VEHICLE_IDENTIFICATION_NUMBER: Vehicle VINs

FinancePIIType:

  • CREDIT_DEBIT_CARD_CVV: Card verification codes
  • CREDIT_DEBIT_CARD_EXPIRY: Card expiration dates
  • CREDIT_DEBIT_CARD_NUMBER: Credit/debit card numbers
  • PIN: Personal identification numbers
  • SWIFT_CODE: Bank SWIFT codes
  • INTERNATIONAL_BANK_ACCOUNT_NUMBER: IBAN numbers

InformationTechnologyPIIType:

  • URL: Web addresses
  • IP_ADDRESS: IPv4 addresses
  • MAC_ADDRESS: Network interface MAC addresses
  • AWS_ACCESS_KEY: AWS access key IDs
  • AWS_SECRET_KEY: AWS secret access keys

USASpecificPIIType:

  • US_BANK_ACCOUNT_NUMBER: US bank account numbers
  • US_BANK_ROUTING_NUMBER: US bank routing numbers
  • US_INDIVIDUAL_TAX_IDENTIFICATION_NUMBER: US ITINs
  • US_PASSPORT_NUMBER: US passport numbers
  • US_SOCIAL_SECURITY_NUMBER: US Social Security Numbers

CanadaSpecificPIIType:

  • CA_HEALTH_NUMBER: Canadian Health Service Numbers
  • CA_SOCIAL_INSURANCE_NUMBER: Canadian Social Insurance Numbers

UKSpecificPIIType:

  • UK_NATIONAL_HEALTH_SERVICE_NUMBER: UK NHS numbers
  • UK_NATIONAL_INSURANCE_NUMBER: UK National Insurance numbers
  • UK_UNIQUE_TAXPAYER_REFERENCE_NUMBER: UK UTR numbers

Regex Filters ​

Regex filters allow you to detect and handle custom patterns in user inputs and model responses. You can configure separate actions for input and output.

Regex Filter Configuration ​
ts
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
  guardrailName: 'my-BedrockGuardrails',
});
// Add regex filter with input/output actions
guardrail.addRegexFilter({
  name: 'TestRegexFilter',
  pattern: 'test-pattern',
  action: bedrock.GuardrailAction.ANONYMIZE,
  // below props are optional
  description: 'This is a test regex filter',
  inputAction: bedrock.GuardrailAction.BLOCK,
  inputEnabled: true,
  outputAction: bedrock.GuardrailAction.ANONYMIZE,
  outputEnabled: true,
});
python
guardrail = bedrock.Guardrail(self, "bedrockGuardrails",
    guardrail_name="my-BedrockGuardrails"
)
# Add regex filter with input/output actions
guardrail.add_regex_filter(
    name="TestRegexFilter",
    pattern="test-pattern",
    action=bedrock.GuardrailAction.ANONYMIZE,
    # below props are optional
    description="This is a test regex filter",
    input_action=bedrock.GuardrailAction.BLOCK,
    input_enabled=True,
    output_action=bedrock.GuardrailAction.ANONYMIZE,
    output_enabled=True
)
java
Guardrail guardrail = Guardrail.Builder.create(this, "bedrockGuardrails")
        .guardrailName("my-BedrockGuardrails")
        .build();
// Add regex filter with input/output actions
guardrail.addRegexFilter(RegexFilter.builder()
        .name("TestRegexFilter")
        .pattern("test-pattern")
        .action(GuardrailAction.ANONYMIZE)
        // below props are optional
        .description("This is a test regex filter")
        .inputAction(GuardrailAction.BLOCK)
        .inputEnabled(true)
        .outputAction(GuardrailAction.ANONYMIZE)
        .outputEnabled(true)
        .build());
csharp
var guardrail = new Guardrail(this, "bedrockGuardrails", new GuardrailProps {
    GuardrailName = "my-BedrockGuardrails"
});
// Add regex filter with input/output actions
guardrail.AddRegexFilter(new RegexFilter {
    Name = "TestRegexFilter",
    Pattern = "test-pattern",
    Action = GuardrailAction.ANONYMIZE,
    // below props are optional
    Description = "This is a test regex filter",
    InputAction = GuardrailAction.BLOCK,
    InputEnabled = true,
    OutputAction = GuardrailAction.ANONYMIZE,
    OutputEnabled = true
});
go
guardrail := bedrock.NewGuardrail(this, jsii.String("bedrockGuardrails"), &GuardrailProps{
	GuardrailName: jsii.String("my-BedrockGuardrails"),
})
// Add regex filter with input/output actions
guardrail.AddRegexFilter(&RegexFilter{
	Name: jsii.String("TestRegexFilter"),
	Pattern: jsii.String("test-pattern"),
	Action: bedrock.GuardrailAction_ANONYMIZE,
	// below props are optional
	Description: jsii.String("This is a test regex filter"),
	InputAction: bedrock.GuardrailAction_BLOCK,
	InputEnabled: jsii.Boolean(true),
	OutputAction: bedrock.GuardrailAction_ANONYMIZE,
	OutputEnabled: jsii.Boolean(true),
})

Contextual Grounding Filters ​

Contextual grounding filters allow you to ensure that model responses are factually correct and relevant to the user's query. You can configure the action and enable/disable the filter.

Contextual Grounding Filter Configuration ​
ts
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
  guardrailName: 'my-BedrockGuardrails',
});
// Add contextual grounding filter with action and enabled flag
guardrail.addContextualGroundingFilter({
  type: bedrock.ContextualGroundingFilterType.GROUNDING,
  threshold: 0.8,
  // the properties below are optional
  action: bedrock.GuardrailAction.BLOCK,
  enabled: true,
});
python
guardrail = bedrock.Guardrail(self, "bedrockGuardrails",
    guardrail_name="my-BedrockGuardrails"
)
# Add contextual grounding filter with action and enabled flag
guardrail.add_contextual_grounding_filter(
    type=bedrock.ContextualGroundingFilterType.GROUNDING,
    threshold=0.8,
    # the properties below are optional
    action=bedrock.GuardrailAction.BLOCK,
    enabled=True
)
java
Guardrail guardrail = Guardrail.Builder.create(this, "bedrockGuardrails")
        .guardrailName("my-BedrockGuardrails")
        .build();
// Add contextual grounding filter with action and enabled flag
guardrail.addContextualGroundingFilter(ContextualGroundingFilter.builder()
        .type(ContextualGroundingFilterType.GROUNDING)
        .threshold(0.8)
        // the properties below are optional
        .action(GuardrailAction.BLOCK)
        .enabled(true)
        .build());
csharp
var guardrail = new Guardrail(this, "bedrockGuardrails", new GuardrailProps {
    GuardrailName = "my-BedrockGuardrails"
});
// Add contextual grounding filter with action and enabled flag
guardrail.AddContextualGroundingFilter(new ContextualGroundingFilter {
    Type = ContextualGroundingFilterType.GROUNDING,
    Threshold = 0.8,
    // the properties below are optional
    Action = GuardrailAction.BLOCK,
    Enabled = true
});
go
guardrail := bedrock.NewGuardrail(this, jsii.String("bedrockGuardrails"), &GuardrailProps{
	GuardrailName: jsii.String("my-BedrockGuardrails"),
})
// Add contextual grounding filter with action and enabled flag
guardrail.AddContextualGroundingFilter(&ContextualGroundingFilter{
	Type: bedrock.ContextualGroundingFilterType_GROUNDING,
	Threshold: jsii.Number(0.8),
	// the properties below are optional
	Action: bedrock.GuardrailAction_BLOCK,
	Enabled: jsii.Boolean(true),
})

Guardrail Methods ​

MethodDescription
addContentFilter()Adds a content filter to the guardrail
addDeniedTopicFilter()Adds a denied topic filter to the guardrail
addWordFilter()Adds a word filter to the guardrail
addManagedWordListFilter()Adds a managed word list filter to the guardrail
addWordFilterFromFile()Adds word filters from a file to the guardrail
addPIIFilter()Adds a PII filter to the guardrail
addRegexFilter()Adds a regex filter to the guardrail
addContextualGroundingFilter()Adds a contextual grounding filter to the guardrail
createVersion()Creates a new version of the guardrail

Guardrail Permissions ​

Guardrails provide methods to grant permissions to other resources that need to interact with the guardrail.

Permission Methods ​

MethodDescriptionParameters
grant(grantee, ...actions)Grants the given principal identity permissions to perform actions on this guardrailgrantee: The principal to grant permissions to<br>actions: The actions to grant (e.g., bedrock:GetGuardrail, bedrock:ListGuardrails)
grantApply(grantee)Grants the given identity permissions to apply the guardrailgrantee: The principal to grant permissions to

Permission Examples ​

ts
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
  guardrailName: 'my-BedrockGuardrails',
});

const lambdaFunction = new lambda.Function(this, 'testLambda', {
  runtime: lambda.Runtime.PYTHON_3_12,
  handler: 'index.handler',
  code: lambda.Code.fromAsset(path.join(__dirname, '../lambda/my-code')),
});

// Grant specific permissions to a Lambda function
guardrail.grant(lambdaFunction, 'bedrock:GetGuardrail', 'bedrock:ListGuardrails');

// Grant permissions to apply the guardrail
guardrail.grantApply(lambdaFunction);
python
guardrail = bedrock.Guardrail(self, "bedrockGuardrails",
    guardrail_name="my-BedrockGuardrails"
)

lambda_function = lambda_.Function(self, "testLambda",
    runtime=lambda_.Runtime.PYTHON_3_12,
    handler="index.handler",
    code=lambda_.Code.from_asset(path.join(__dirname, "../lambda/my-code"))
)

# Grant specific permissions to a Lambda function
guardrail.grant(lambda_function, "bedrock:GetGuardrail", "bedrock:ListGuardrails")

# Grant permissions to apply the guardrail
guardrail.grant_apply(lambda_function)
java
Guardrail guardrail = Guardrail.Builder.create(this, "bedrockGuardrails")
        .guardrailName("my-BedrockGuardrails")
        .build();

Function lambdaFunction = Function.Builder.create(this, "testLambda")
        .runtime(Runtime.PYTHON_3_12)
        .handler("index.handler")
        .code(Code.fromAsset(join(__dirname, "../lambda/my-code")))
        .build();

// Grant specific permissions to a Lambda function
guardrail.grant(lambdaFunction, "bedrock:GetGuardrail", "bedrock:ListGuardrails");

// Grant permissions to apply the guardrail
guardrail.grantApply(lambdaFunction);
csharp
var guardrail = new Guardrail(this, "bedrockGuardrails", new GuardrailProps {
    GuardrailName = "my-BedrockGuardrails"
});

var lambdaFunction = new Function(this, "testLambda", new FunctionProps {
    Runtime = Runtime.PYTHON_3_12,
    Handler = "index.handler",
    Code = Code.FromAsset(Join(__dirname, "../lambda/my-code"))
});

// Grant specific permissions to a Lambda function
guardrail.Grant(lambdaFunction, "bedrock:GetGuardrail", "bedrock:ListGuardrails");

// Grant permissions to apply the guardrail
guardrail.GrantApply(lambdaFunction);
go
guardrail := bedrock.NewGuardrail(this, jsii.String("bedrockGuardrails"), &GuardrailProps{
	GuardrailName: jsii.String("my-BedrockGuardrails"),
})

lambdaFunction := lambda.NewFunction(this, jsii.String("testLambda"), &FunctionProps{
	Runtime: lambda.Runtime_PYTHON_3_12(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromAsset(path.join(__dirname, jsii.String("../lambda/my-code"))),
})

// Grant specific permissions to a Lambda function
guardrail.Grant(lambdaFunction, jsii.String("bedrock:GetGuardrail"), jsii.String("bedrock:ListGuardrails"))

// Grant permissions to apply the guardrail
guardrail.GrantApply(lambdaFunction)

Guardrail Metrics ​

Amazon Bedrock provides metrics for your guardrails, allowing you to monitor their effectiveness and usage. These metrics are available in CloudWatch and can be used to create dashboards and alarms.

Metrics Examples ​

ts
import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch';

const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
  guardrailName: 'my-BedrockGuardrails',
});
// Get a specific metric for this guardrail
const invocationsMetric = guardrail.metricInvocations({
  statistic: 'Sum',
  period: Duration.minutes(5),
});

// Create a CloudWatch alarm for high invocation latency
new cloudwatch.Alarm(this, 'HighLatencyAlarm', {
  metric: guardrail.metricInvocationLatency(),
  threshold: 1000, // 1 second
  evaluationPeriods: 3,
});

// Get metrics for all guardrails
const allInvocationsMetric = bedrock.Guardrail.metricAllInvocations();
python
import aws_cdk.aws_cloudwatch as cloudwatch


guardrail = bedrock.Guardrail(self, "bedrockGuardrails",
    guardrail_name="my-BedrockGuardrails"
)
# Get a specific metric for this guardrail
invocations_metric = guardrail.metric_invocations(
    statistic="Sum",
    period=Duration.minutes(5)
)

# Create a CloudWatch alarm for high invocation latency
cloudwatch.Alarm(self, "HighLatencyAlarm",
    metric=guardrail.metric_invocation_latency(),
    threshold=1000,  # 1 second
    evaluation_periods=3
)

# Get metrics for all guardrails
all_invocations_metric = bedrock.Guardrail.metric_all_invocations()
java
import software.amazon.awscdk.services.cloudwatch.*;


Guardrail guardrail = Guardrail.Builder.create(this, "bedrockGuardrails")
        .guardrailName("my-BedrockGuardrails")
        .build();
// Get a specific metric for this guardrail
Metric invocationsMetric = guardrail.metricInvocations(MetricOptions.builder()
        .statistic("Sum")
        .period(Duration.minutes(5))
        .build());

// Create a CloudWatch alarm for high invocation latency
// Create a CloudWatch alarm for high invocation latency
Alarm.Builder.create(this, "HighLatencyAlarm")
        .metric(guardrail.metricInvocationLatency())
        .threshold(1000) // 1 second
        .evaluationPeriods(3)
        .build();

// Get metrics for all guardrails
Metric allInvocationsMetric = Guardrail.metricAllInvocations();
csharp
using Amazon.CDK.AWS.CloudWatch;


var guardrail = new Guardrail(this, "bedrockGuardrails", new GuardrailProps {
    GuardrailName = "my-BedrockGuardrails"
});
// Get a specific metric for this guardrail
var invocationsMetric = guardrail.MetricInvocations(new MetricOptions {
    Statistic = "Sum",
    Period = Duration.Minutes(5)
});

// Create a CloudWatch alarm for high invocation latency
// Create a CloudWatch alarm for high invocation latency
new Alarm(this, "HighLatencyAlarm", new AlarmProps {
    Metric = guardrail.MetricInvocationLatency(),
    Threshold = 1000,  // 1 second
    EvaluationPeriods = 3
});

// Get metrics for all guardrails
var allInvocationsMetric = Guardrail.MetricAllInvocations();
go
import cloudwatch "github.com/aws/aws-cdk-go/awscdk"


guardrail := bedrock.NewGuardrail(this, jsii.String("bedrockGuardrails"), &GuardrailProps{
	GuardrailName: jsii.String("my-BedrockGuardrails"),
})
// Get a specific metric for this guardrail
invocationsMetric := guardrail.MetricInvocations(&MetricOptions{
	Statistic: jsii.String("Sum"),
	Period: awscdk.Duration_Minutes(jsii.Number(5)),
})

// Create a CloudWatch alarm for high invocation latency
// Create a CloudWatch alarm for high invocation latency
cloudwatch.NewAlarm(this, jsii.String("HighLatencyAlarm"), &AlarmProps{
	Metric: guardrail.MetricInvocationLatency(),
	Threshold: jsii.Number(1000),
	 // 1 second
	EvaluationPeriods: jsii.Number(3),
})

// Get metrics for all guardrails
allInvocationsMetric := bedrock.Guardrail_MetricAllInvocations()

Importing Guardrails ​

You can import existing guardrails using the fromGuardrailAttributes or fromCfnGuardrail methods.

Import Configuration ​

ts
declare const stack: Stack;
const cmk = new kms.Key(this, 'cmk', {});
// Import an existing guardrail by ARN
const importedGuardrail = bedrock.Guardrail.fromGuardrailAttributes(stack, 'TestGuardrail', {
  guardrailArn: 'arn:aws:bedrock:us-east-1:123456789012:guardrail/oygh3o8g7rtl',
  guardrailVersion: '1', //optional
  kmsKey: cmk, //optional
});
python
# stack: Stack

cmk = kms.Key(self, "cmk")
# Import an existing guardrail by ARN
imported_guardrail = bedrock.Guardrail.from_guardrail_attributes(stack, "TestGuardrail",
    guardrail_arn="arn:aws:bedrock:us-east-1:123456789012:guardrail/oygh3o8g7rtl",
    guardrail_version="1",  # optional
    kms_key=cmk
)
java
Stack stack;

Key cmk = Key.Builder.create(this, "cmk").build();
// Import an existing guardrail by ARN
IGuardrail importedGuardrail = Guardrail.fromGuardrailAttributes(stack, "TestGuardrail", GuardrailAttributes.builder()
        .guardrailArn("arn:aws:bedrock:us-east-1:123456789012:guardrail/oygh3o8g7rtl")
        .guardrailVersion("1") //optional
        .kmsKey(cmk)
        .build());
csharp
Stack stack;

var cmk = new Key(this, "cmk", new KeyProps { });
// Import an existing guardrail by ARN
var importedGuardrail = Guardrail.FromGuardrailAttributes(stack, "TestGuardrail", new GuardrailAttributes {
    GuardrailArn = "arn:aws:bedrock:us-east-1:123456789012:guardrail/oygh3o8g7rtl",
    GuardrailVersion = "1",  //optional
    KmsKey = cmk
});
go
var stack Stack

cmk := kms.NewKey(this, jsii.String("cmk"), &KeyProps{
})
// Import an existing guardrail by ARN
importedGuardrail := bedrock.Guardrail_FromGuardrailAttributes(stack, jsii.String("TestGuardrail"), &GuardrailAttributes{
	GuardrailArn: jsii.String("arn:aws:bedrock:us-east-1:123456789012:guardrail/oygh3o8g7rtl"),
	GuardrailVersion: jsii.String("1"),
	 //optional
	KmsKey: cmk,
})
ts
import * as bedrockl1 from 'aws-cdk-lib/aws-bedrock';
// Import a guardrail created through the L1 CDK CfnGuardrail construct
const l1guardrail = new bedrockl1.CfnGuardrail(this, 'MyCfnGuardrail', {
  blockedInputMessaging: 'blockedInputMessaging',
  blockedOutputsMessaging: 'blockedOutputsMessaging',
  name: 'namemycfnguardrails',
  wordPolicyConfig: {
    wordsConfig: [
      {
        text: 'drugs',
      },
    ],
  },
});

const importedGuardrail = bedrock.Guardrail.fromCfnGuardrail(l1guardrail);
python
import aws_cdk.aws_bedrock as bedrockl1

# Import a guardrail created through the L1 CDK CfnGuardrail construct
l1guardrail = bedrockl1.CfnGuardrail(self, "MyCfnGuardrail",
    blocked_input_messaging="blockedInputMessaging",
    blocked_outputs_messaging="blockedOutputsMessaging",
    name="namemycfnguardrails",
    word_policy_config=bedrockl1.CfnGuardrail.WordPolicyConfigProperty(
        words_config=[bedrockl1.CfnGuardrail.WordConfigProperty(
            text="drugs"
        )
        ]
    )
)

imported_guardrail = bedrock.Guardrail.from_cfn_guardrail(l1guardrail)
java
import software.amazon.awscdk.services.bedrock.*;

// Import a guardrail created through the L1 CDK CfnGuardrail construct
CfnGuardrail l1guardrail = CfnGuardrail.Builder.create(this, "MyCfnGuardrail")
        .blockedInputMessaging("blockedInputMessaging")
        .blockedOutputsMessaging("blockedOutputsMessaging")
        .name("namemycfnguardrails")
        .wordPolicyConfig(WordPolicyConfigProperty.builder()
                .wordsConfig(List.of(WordConfigProperty.builder()
                        .text("drugs")
                        .build()))
                .build())
        .build();

IGuardrail importedGuardrail = Guardrail.fromCfnGuardrail(l1guardrail);
csharp
using Amazon.CDK.AWS.Bedrock;

// Import a guardrail created through the L1 CDK CfnGuardrail construct
var l1guardrail = new CfnGuardrail(this, "MyCfnGuardrail", new CfnGuardrailProps {
    BlockedInputMessaging = "blockedInputMessaging",
    BlockedOutputsMessaging = "blockedOutputsMessaging",
    Name = "namemycfnguardrails",
    WordPolicyConfig = new WordPolicyConfigProperty {
        WordsConfig = new [] { new WordConfigProperty {
            Text = "drugs"
        } }
    }
});

var importedGuardrail = Guardrail.FromCfnGuardrail(l1guardrail);
go
import bedrockl1 "github.com/aws/aws-cdk-go/awscdk"

// Import a guardrail created through the L1 CDK CfnGuardrail construct
l1guardrail := bedrockl1.NewCfnGuardrail(this, jsii.String("MyCfnGuardrail"), &CfnGuardrailProps{
	BlockedInputMessaging: jsii.String("blockedInputMessaging"),
	BlockedOutputsMessaging: jsii.String("blockedOutputsMessaging"),
	Name: jsii.String("namemycfnguardrails"),
	WordPolicyConfig: &WordPolicyConfigProperty{
		WordsConfig: []interface{}{
			&WordConfigProperty{
				Text: jsii.String("drugs"),
			},
		},
	},
})

importedGuardrail := bedrock.Guardrail_FromCfnGuardrail(l1guardrail)

Guardrail Versioning ​

Guardrails support versioning, allowing you to track changes and maintain multiple versions of your guardrail configurations.

Version Configuration ​

ts
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
  guardrailName: 'my-BedrockGuardrails',
});
// Create a new version of the guardrail
guardrail.createVersion('testversion');
python
guardrail = bedrock.Guardrail(self, "bedrockGuardrails",
    guardrail_name="my-BedrockGuardrails"
)
# Create a new version of the guardrail
guardrail.create_version("testversion")
java
Guardrail guardrail = Guardrail.Builder.create(this, "bedrockGuardrails")
        .guardrailName("my-BedrockGuardrails")
        .build();
// Create a new version of the guardrail
guardrail.createVersion("testversion");
csharp
var guardrail = new Guardrail(this, "bedrockGuardrails", new GuardrailProps {
    GuardrailName = "my-BedrockGuardrails"
});
// Create a new version of the guardrail
guardrail.CreateVersion("testversion");
go
guardrail := bedrock.NewGuardrail(this, jsii.String("bedrockGuardrails"), &GuardrailProps{
	GuardrailName: jsii.String("my-BedrockGuardrails"),
})
// Create a new version of the guardrail
guardrail.CreateVersion(jsii.String("testversion"))

Prompts ​

Amazon Bedrock provides the ability to create and save prompts using Prompt management so that you can save time by applying the same prompt to different workflows. You can include variables in the prompt so that you can adjust the prompt for different use case.

The Prompt resource allows you to create a new prompt.

Prompt Variants ​

Prompt variants in the context of Amazon Bedrock refer to alternative configurations of a prompt, including its message or the model and inference configurations used. Prompt variants are the building blocks of prompts - you must create at least one prompt variant to create a prompt. Prompt variants allow you to create different versions of a prompt, test them, and save the variant that works best for your use case.

There are three types of prompt variants:

  • Basic Text Prompt: Simple text-based prompts for straightforward interactions
  • Chat variant: Conversational prompts that support system messages, user/assistant message history, and tools
  • Agent variant: Prompts designed to work with Bedrock Agents

Basic Text Prompt ​

Text prompts are the simplest form of prompts, consisting of plain text instructions with optional variables. They are ideal for straightforward tasks like summarization, content generation, or question answering where you need a direct text-based interaction with the model.

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,
});
python
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
)
java
Key cmk = Key.Builder.create(this, "cmk").build();
BedrockFoundationModel claudeModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0;

IPromptVariant variant1 = PromptVariant.text(TextPromptVariantProps.builder()
        .variantName("variant1")
        .model(claudeModel)
        .promptVariables(List.of("topic"))
        .promptText("This is my first text prompt. Please summarize our conversation on: {{topic}}.")
        .inferenceConfiguration(PromptInferenceConfiguration.text(PromptInferenceConfigurationProps.builder()
                .temperature(1)
                .topP(0.999)
                .maxTokens(2000)
                .build()))
        .build());

Prompt prompt1 = Prompt.Builder.create(this, "prompt1")
        .promptName("prompt1")
        .description("my first prompt")
        .defaultVariant(variant1)
        .variants(List.of(variant1))
        .kmsKey(cmk)
        .build();
csharp
var cmk = new Key(this, "cmk", new KeyProps { });
var claudeModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0;

var variant1 = PromptVariant.Text(new TextPromptVariantProps {
    VariantName = "variant1",
    Model = claudeModel,
    PromptVariables = new [] { "topic" },
    PromptText = "This is my first text prompt. Please summarize our conversation on: {{topic}}.",
    InferenceConfiguration = PromptInferenceConfiguration.Text(new PromptInferenceConfigurationProps {
        Temperature = 1,
        TopP = 0.999,
        MaxTokens = 2000
    })
});

var prompt1 = new Prompt(this, "prompt1", new PromptProps {
    PromptName = "prompt1",
    Description = "my first prompt",
    DefaultVariant = variant1,
    Variants = new [] { variant1 },
    KmsKey = cmk
});
go
cmk := kms.NewKey(this, jsii.String("cmk"), &KeyProps{
})
claudeModel := bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_SONNET_V1_0()

variant1 := bedrock.PromptVariant_Text(&TextPromptVariantProps{
	VariantName: jsii.String("variant1"),
	Model: claudeModel,
	PromptVariables: []*string{
		jsii.String("topic"),
	},
	PromptText: jsii.String("This is my first text prompt. Please summarize our conversation on: {{topic}}."),
	InferenceConfiguration: bedrock.PromptInferenceConfiguration_Text(&PromptInferenceConfigurationProps{
		Temperature: jsii.Number(1),
		TopP: jsii.Number(0.999),
		MaxTokens: jsii.Number(2000),
	}),
})

prompt1 := bedrock.NewPrompt(this, jsii.String("prompt1"), &PromptProps{
	PromptName: jsii.String("prompt1"),
	Description: jsii.String("my first prompt"),
	DefaultVariant: variant1,
	Variants: []IPromptVariant{
		variant1,
	},
	KmsKey: cmk,
})

Chat Prompt ​

Use this template type when the model supports the Converse API or the Anthropic Claude Messages API. This allows you to include a System prompt and previous User messages and Assistant messages for context.

ts
const cmk = new kms.Key(this, 'cmk', {});

const variantChat = bedrock.PromptVariant.chat({
  variantName: 'variant1',
  model: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
  messages: [
    bedrock.ChatMessage.user('From now on, you speak Japanese!'),
    bedrock.ChatMessage.assistant('Konnichiwa!'),
    bedrock.ChatMessage.user('From now on, you speak {{language}}!'),
  ],
  system: 'You are a helpful assistant that only speaks the language you`re told.',
  promptVariables: ['language'],
  toolConfiguration: {
    toolChoice: bedrock.ToolChoice.AUTO,
    tools: [
      bedrock.Tool.function({
        name: 'top_song',
        description: 'Get the most popular song played on a radio station.',
        inputSchema: {
          type: 'object',
          properties: {
            sign: {
              type: 'string',
              description: 'The call sign for the radio station for which you want the most popular song. Example calls signs are WZPZ and WKR.',
            },
          },
          required: ['sign'],
        },
      }),
    ],
  },
});

new bedrock.Prompt(this, 'prompt1', {
  promptName: 'prompt-chat',
  description: 'my first chat prompt',
  defaultVariant: variantChat,
  variants: [variantChat],
  kmsKey: cmk,
});
python
cmk = kms.Key(self, "cmk")

variant_chat = bedrock.PromptVariant.chat(
    variant_name="variant1",
    model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
    messages=[
        bedrock.ChatMessage.user("From now on, you speak Japanese!"),
        bedrock.ChatMessage.assistant("Konnichiwa!"),
        bedrock.ChatMessage.user("From now on, you speak {{language}}!")
    ],
    system="You are a helpful assistant that only speaks the language you`re told.",
    prompt_variables=["language"],
    tool_configuration=bedrock.ToolConfiguration(
        tool_choice=bedrock.ToolChoice.AUTO,
        tools=[
            bedrock.Tool.function(
                name="top_song",
                description="Get the most popular song played on a radio station.",
                input_schema={
                    "type": "object",
                    "properties": {
                        "sign": {
                            "type": "string",
                            "description": "The call sign for the radio station for which you want the most popular song. Example calls signs are WZPZ and WKR."
                        }
                    },
                    "required": ["sign"]
                }
            )
        ]
    )
)

bedrock.Prompt(self, "prompt1",
    prompt_name="prompt-chat",
    description="my first chat prompt",
    default_variant=variant_chat,
    variants=[variant_chat],
    kms_key=cmk
)
java
Key cmk = Key.Builder.create(this, "cmk").build();

IPromptVariant variantChat = PromptVariant.chat(ChatPromptVariantProps.builder()
        .variantName("variant1")
        .model(BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0)
        .messages(List.of(ChatMessage.user("From now on, you speak Japanese!"), ChatMessage.assistant("Konnichiwa!"), ChatMessage.user("From now on, you speak {{language}}!")))
        .system("You are a helpful assistant that only speaks the language you`re told.")
        .promptVariables(List.of("language"))
        .toolConfiguration(ToolConfiguration.builder()
                .toolChoice(ToolChoice.AUTO)
                .tools(List.of(Tool.function(FunctionToolProps.builder()
                        .name("top_song")
                        .description("Get the most popular song played on a radio station.")
                        .inputSchema(Map.of(
                                "type", "object",
                                "properties", Map.of(
                                        "sign", Map.of(
                                                "type", "string",
                                                "description", "The call sign for the radio station for which you want the most popular song. Example calls signs are WZPZ and WKR.")),
                                "required", List.of("sign")))
                        .build())))
                .build())
        .build());

Prompt.Builder.create(this, "prompt1")
        .promptName("prompt-chat")
        .description("my first chat prompt")
        .defaultVariant(variantChat)
        .variants(List.of(variantChat))
        .kmsKey(cmk)
        .build();
csharp
var cmk = new Key(this, "cmk", new KeyProps { });

var variantChat = PromptVariant.Chat(new ChatPromptVariantProps {
    VariantName = "variant1",
    Model = BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
    Messages = new [] { ChatMessage.User("From now on, you speak Japanese!"), ChatMessage.Assistant("Konnichiwa!"), ChatMessage.User("From now on, you speak {{language}}!") },
    System = "You are a helpful assistant that only speaks the language you`re told.",
    PromptVariables = new [] { "language" },
    ToolConfiguration = new ToolConfiguration {
        ToolChoice = ToolChoice.AUTO,
        Tools = new [] { Tool.Function(new FunctionToolProps {
            Name = "top_song",
            Description = "Get the most popular song played on a radio station.",
            InputSchema = new Dictionary<string, object> {
                { "type", "object" },
                { "properties", new Struct {
                    Sign = new Struct {
                        Type = "string",
                        Description = "The call sign for the radio station for which you want the most popular song. Example calls signs are WZPZ and WKR."
                    }
                } },
                { "required", new [] { "sign" } }
            }
        }) }
    }
});

new Prompt(this, "prompt1", new PromptProps {
    PromptName = "prompt-chat",
    Description = "my first chat prompt",
    DefaultVariant = variantChat,
    Variants = new [] { variantChat },
    KmsKey = cmk
});
go
cmk := kms.NewKey(this, jsii.String("cmk"), &KeyProps{
})

variantChat := bedrock.PromptVariant_Chat(&ChatPromptVariantProps{
	VariantName: jsii.String("variant1"),
	Model: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_3_5_SONNET_V1_0(),
	Messages: []ChatMessage{
		bedrock.ChatMessage_User(jsii.String("From now on, you speak Japanese!")),
		bedrock.ChatMessage_Assistant(jsii.String("Konnichiwa!")),
		bedrock.ChatMessage_*User(jsii.String("From now on, you speak {{language}}!")),
	},
	System: jsii.String("You are a helpful assistant that only speaks the language you`re told."),
	PromptVariables: []*string{
		jsii.String("language"),
	},
	ToolConfiguration: &ToolConfiguration{
		ToolChoice: bedrock.ToolChoice_AUTO(),
		Tools: []Tool{
			bedrock.Tool_Function(&FunctionToolProps{
				Name: jsii.String("top_song"),
				Description: jsii.String("Get the most popular song played on a radio station."),
				InputSchema: map[string]interface{}{
					"type": jsii.String("object"),
					"properties": map[string]map[string]*string{
						"sign": map[string]*string{
							"type": jsii.String("string"),
							"description": jsii.String("The call sign for the radio station for which you want the most popular song. Example calls signs are WZPZ and WKR."),
						},
					},
					"required": []*string{
						jsii.String("sign"),
					},
				},
			}),
		},
	},
})

bedrock.NewPrompt(this, jsii.String("prompt1"), &PromptProps{
	PromptName: jsii.String("prompt-chat"),
	Description: jsii.String("my first chat prompt"),
	DefaultVariant: variantChat,
	Variants: []IPromptVariant{
		variantChat,
	},
	KmsKey: cmk,
})

Agent Prompt ​

Agent prompts are designed to work with Bedrock Agents, allowing you to create prompts that can be used by agents to perform specific tasks. Agent prompts use text prompts as their foundation and can reference agent aliases and include custom instructions for how the agent should behave.

ts
const cmk = new kms.Key(this, 'cmk', {});

// Assuming you have an existing agent and alias
const agent = bedrock.Agent.fromAgentAttributes(this, 'ImportedAgent', {
  agentArn: 'arn:aws:bedrock:region:account:agent/agent-id',
  roleArn: 'arn:aws:iam::account:role/agent-role',
});

const agentAlias = bedrock.AgentAlias.fromAttributes(this, 'ImportedAlias', {
  aliasId: 'alias-id',
  aliasName: 'my-alias',
  agentVersion: '1',
  agent: agent,
});

const agentVariant = bedrock.PromptVariant.agent({
  variantName: 'agent-variant',
  model: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
  agentAlias: agentAlias,
  promptText: 'Use the agent to help with: {{task}}. Please be thorough and provide detailed explanations.',
  promptVariables: ['task'],
});

new bedrock.Prompt(this, 'agentPrompt', {
  promptName: 'agent-prompt',
  description: 'Prompt for agent interactions',
  defaultVariant: agentVariant,
  variants: [agentVariant],
  kmsKey: cmk,
});
python
cmk = kms.Key(self, "cmk")

# Assuming you have an existing agent and alias
agent = bedrock.Agent.from_agent_attributes(self, "ImportedAgent",
    agent_arn="arn:aws:bedrock:region:account:agent/agent-id",
    role_arn="arn:aws:iam::account:role/agent-role"
)

agent_alias = bedrock.AgentAlias.from_attributes(self, "ImportedAlias",
    alias_id="alias-id",
    alias_name="my-alias",
    agent_version="1",
    agent=agent
)

agent_variant = bedrock.PromptVariant.agent(
    variant_name="agent-variant",
    model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
    agent_alias=agent_alias,
    prompt_text="Use the agent to help with: {{task}}. Please be thorough and provide detailed explanations.",
    prompt_variables=["task"]
)

bedrock.Prompt(self, "agentPrompt",
    prompt_name="agent-prompt",
    description="Prompt for agent interactions",
    default_variant=agent_variant,
    variants=[agent_variant],
    kms_key=cmk
)
java
Key cmk = Key.Builder.create(this, "cmk").build();

// Assuming you have an existing agent and alias
IAgent agent = Agent.fromAgentAttributes(this, "ImportedAgent", AgentAttributes.builder()
        .agentArn("arn:aws:bedrock:region:account:agent/agent-id")
        .roleArn("arn:aws:iam::account:role/agent-role")
        .build());

IAgentAlias agentAlias = AgentAlias.fromAttributes(this, "ImportedAlias", AgentAliasAttributes.builder()
        .aliasId("alias-id")
        .aliasName("my-alias")
        .agentVersion("1")
        .agent(agent)
        .build());

IPromptVariant agentVariant = PromptVariant.agent(AgentPromptVariantProps.builder()
        .variantName("agent-variant")
        .model(BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0)
        .agentAlias(agentAlias)
        .promptText("Use the agent to help with: {{task}}. Please be thorough and provide detailed explanations.")
        .promptVariables(List.of("task"))
        .build());

Prompt.Builder.create(this, "agentPrompt")
        .promptName("agent-prompt")
        .description("Prompt for agent interactions")
        .defaultVariant(agentVariant)
        .variants(List.of(agentVariant))
        .kmsKey(cmk)
        .build();
csharp
var cmk = new Key(this, "cmk", new KeyProps { });

// Assuming you have an existing agent and alias
var agent = Agent.FromAgentAttributes(this, "ImportedAgent", new AgentAttributes {
    AgentArn = "arn:aws:bedrock:region:account:agent/agent-id",
    RoleArn = "arn:aws:iam::account:role/agent-role"
});

var agentAlias = AgentAlias.FromAttributes(this, "ImportedAlias", new AgentAliasAttributes {
    AliasId = "alias-id",
    AliasName = "my-alias",
    AgentVersion = "1",
    Agent = agent
});

var agentVariant = PromptVariant.Agent(new AgentPromptVariantProps {
    VariantName = "agent-variant",
    Model = BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
    AgentAlias = agentAlias,
    PromptText = "Use the agent to help with: {{task}}. Please be thorough and provide detailed explanations.",
    PromptVariables = new [] { "task" }
});

new Prompt(this, "agentPrompt", new PromptProps {
    PromptName = "agent-prompt",
    Description = "Prompt for agent interactions",
    DefaultVariant = agentVariant,
    Variants = new [] { agentVariant },
    KmsKey = cmk
});
go
cmk := kms.NewKey(this, jsii.String("cmk"), &KeyProps{
})

// Assuming you have an existing agent and alias
agent := bedrock.Agent_FromAgentAttributes(this, jsii.String("ImportedAgent"), &AgentAttributes{
	AgentArn: jsii.String("arn:aws:bedrock:region:account:agent/agent-id"),
	RoleArn: jsii.String("arn:aws:iam::account:role/agent-role"),
})

agentAlias := bedrock.AgentAlias_FromAttributes(this, jsii.String("ImportedAlias"), &AgentAliasAttributes{
	AliasId: jsii.String("alias-id"),
	AliasName: jsii.String("my-alias"),
	AgentVersion: jsii.String("1"),
	Agent: agent,
})

agentVariant := bedrock.PromptVariant_Agent(&AgentPromptVariantProps{
	VariantName: jsii.String("agent-variant"),
	Model: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_3_5_SONNET_V1_0(),
	AgentAlias: agentAlias,
	PromptText: jsii.String("Use the agent to help with: {{task}}. Please be thorough and provide detailed explanations."),
	PromptVariables: []*string{
		jsii.String("task"),
	},
})

bedrock.NewPrompt(this, jsii.String("agentPrompt"), &PromptProps{
	PromptName: jsii.String("agent-prompt"),
	Description: jsii.String("Prompt for agent interactions"),
	DefaultVariant: agentVariant,
	Variants: []IPromptVariant{
		agentVariant,
	},
	KmsKey: cmk,
})

Prompt Properties ​

PropertyTypeRequiredDescription
promptNamestringYesThe name of the prompt
descriptionstringNoA description of the prompt
defaultVariantPromptVariantYesThe default variant to use for the prompt
variantsPromptVariant[]NoAdditional variants for the prompt
kmsKeykms.IKeyNoThe KMS key to use for encrypting the prompt. Defaults to AWS managed key
tagsRecord<string, string>NoTags to apply to the prompt

Prompt Version ​

A prompt version is a snapshot of a prompt at a specific point in time that you create when you are satisfied with a set of configurations. Versions allow you to deploy your prompt and easily switch between different configurations for your prompt and update your application with the most appropriate version for your use-case.

You can create a Prompt version by using the PromptVersion class or by using the .createVersion(..) on a Prompt object. It is recommended to use the .createVersion(..) method. It uses a hash based mechanism to update the version whenever a certain configuration property changes.

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,
});

const promptVersion = new bedrock.PromptVersion(this, 'MyPromptVersion', {
  prompt: prompt1,
  description: 'my first version',
});
//or alternatively:
// const promptVersion = prompt1.createVersion('my first version');
const versionString = promptVersion.version;
python
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
)

prompt_version = bedrock.PromptVersion(self, "MyPromptVersion",
    prompt=prompt1,
    description="my first version"
)
# or alternatively:
# const promptVersion = prompt1.createVersion('my first version');
version_string = prompt_version.version
java
Key cmk = Key.Builder.create(this, "cmk").build();
BedrockFoundationModel claudeModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0;

IPromptVariant variant1 = PromptVariant.text(TextPromptVariantProps.builder()
        .variantName("variant1")
        .model(claudeModel)
        .promptVariables(List.of("topic"))
        .promptText("This is my first text prompt. Please summarize our conversation on: {{topic}}.")
        .inferenceConfiguration(PromptInferenceConfiguration.text(PromptInferenceConfigurationProps.builder()
                .temperature(1)
                .topP(0.999)
                .maxTokens(2000)
                .build()))
        .build());

Prompt prompt1 = Prompt.Builder.create(this, "prompt1")
        .promptName("prompt1")
        .description("my first prompt")
        .defaultVariant(variant1)
        .variants(List.of(variant1))
        .kmsKey(cmk)
        .build();

PromptVersion promptVersion = PromptVersion.Builder.create(this, "MyPromptVersion")
        .prompt(prompt1)
        .description("my first version")
        .build();
//or alternatively:
// const promptVersion = prompt1.createVersion('my first version');
String versionString = promptVersion.getVersion();
csharp
var cmk = new Key(this, "cmk", new KeyProps { });
var claudeModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0;

var variant1 = PromptVariant.Text(new TextPromptVariantProps {
    VariantName = "variant1",
    Model = claudeModel,
    PromptVariables = new [] { "topic" },
    PromptText = "This is my first text prompt. Please summarize our conversation on: {{topic}}.",
    InferenceConfiguration = PromptInferenceConfiguration.Text(new PromptInferenceConfigurationProps {
        Temperature = 1,
        TopP = 0.999,
        MaxTokens = 2000
    })
});

var prompt1 = new Prompt(this, "prompt1", new PromptProps {
    PromptName = "prompt1",
    Description = "my first prompt",
    DefaultVariant = variant1,
    Variants = new [] { variant1 },
    KmsKey = cmk
});

var promptVersion = new PromptVersion(this, "MyPromptVersion", new PromptVersionProps {
    Prompt = prompt1,
    Description = "my first version"
});
//or alternatively:
// const promptVersion = prompt1.createVersion('my first version');
var versionString = promptVersion.Version;
go
cmk := kms.NewKey(this, jsii.String("cmk"), &KeyProps{
})
claudeModel := bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_SONNET_V1_0()

variant1 := bedrock.PromptVariant_Text(&TextPromptVariantProps{
	VariantName: jsii.String("variant1"),
	Model: claudeModel,
	PromptVariables: []*string{
		jsii.String("topic"),
	},
	PromptText: jsii.String("This is my first text prompt. Please summarize our conversation on: {{topic}}."),
	InferenceConfiguration: bedrock.PromptInferenceConfiguration_Text(&PromptInferenceConfigurationProps{
		Temperature: jsii.Number(1),
		TopP: jsii.Number(0.999),
		MaxTokens: jsii.Number(2000),
	}),
})

prompt1 := bedrock.NewPrompt(this, jsii.String("prompt1"), &PromptProps{
	PromptName: jsii.String("prompt1"),
	Description: jsii.String("my first prompt"),
	DefaultVariant: variant1,
	Variants: []IPromptVariant{
		variant1,
	},
	KmsKey: cmk,
})

promptVersion := bedrock.NewPromptVersion(this, jsii.String("MyPromptVersion"), &PromptVersionProps{
	Prompt: prompt1,
	Description: jsii.String("my first version"),
})
//or alternatively:
// const promptVersion = prompt1.createVersion('my first version');
versionString := promptVersion.Version

Import Methods ​

You can use the fromPromptAttributes method to import an existing Bedrock Prompt into your CDK application.

ts
// Import an existing prompt by ARN
const importedPrompt = bedrock.Prompt.fromPromptAttributes(this, 'ImportedPrompt', {
  promptArn: 'arn:aws:bedrock:region:account:prompt/prompt-id',
  kmsKey: kms.Key.fromKeyArn(this, 'ImportedKey', 'arn:aws:kms:region:account:key/key-id'), // optional
  promptVersion: '1', // optional, defaults to 'DRAFT'
});
python
# Import an existing prompt by ARN
imported_prompt = bedrock.Prompt.from_prompt_attributes(self, "ImportedPrompt",
    prompt_arn="arn:aws:bedrock:region:account:prompt/prompt-id",
    kms_key=kms.Key.from_key_arn(self, "ImportedKey", "arn:aws:kms:region:account:key/key-id"),  # optional
    prompt_version="1"
)
java
// Import an existing prompt by ARN
IPrompt importedPrompt = Prompt.fromPromptAttributes(this, "ImportedPrompt", PromptAttributes.builder()
        .promptArn("arn:aws:bedrock:region:account:prompt/prompt-id")
        .kmsKey(Key.fromKeyArn(this, "ImportedKey", "arn:aws:kms:region:account:key/key-id")) // optional
        .promptVersion("1")
        .build());
csharp
// Import an existing prompt by ARN
var importedPrompt = Prompt.FromPromptAttributes(this, "ImportedPrompt", new PromptAttributes {
    PromptArn = "arn:aws:bedrock:region:account:prompt/prompt-id",
    KmsKey = Key.FromKeyArn(this, "ImportedKey", "arn:aws:kms:region:account:key/key-id"),  // optional
    PromptVersion = "1"
});
go
// Import an existing prompt by ARN
importedPrompt := bedrock.Prompt_FromPromptAttributes(this, jsii.String("ImportedPrompt"), &PromptAttributes{
	PromptArn: jsii.String("arn:aws:bedrock:region:account:prompt/prompt-id"),
	KmsKey: kms.Key_FromKeyArn(this, jsii.String("ImportedKey"), jsii.String("arn:aws:kms:region:account:key/key-id")),
	 // optional
	PromptVersion: jsii.String("1"),
})

Inference Profiles ​

Amazon Bedrock Inference Profiles provide a way to manage and optimize inference configurations for your foundation models. They allow you to define reusable configurations that can be applied across different prompts and agents.

Using Inference Profiles ​

Inference profiles can be used with prompts and agents to maintain consistent inference configurations across your application.

With Agents ​

ts
// Create a cross-region inference profile
const crossRegionProfile = bedrock.CrossRegionInferenceProfile.fromConfig({
  geoRegion: bedrock.CrossRegionInferenceProfileRegion.US,
  model: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
});

// Use the cross-region profile with an agent
const agent = new bedrock.Agent(this, 'Agent', {
  foundationModel: crossRegionProfile,
  instruction: 'You are a helpful and friendly agent that answers questions about agriculture.',
});
python
# Create a cross-region inference profile
cross_region_profile = bedrock.CrossRegionInferenceProfile.from_config(
    geo_region=bedrock.CrossRegionInferenceProfileRegion.US,
    model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0
)

# Use the cross-region profile with an agent
agent = bedrock.Agent(self, "Agent",
    foundation_model=cross_region_profile,
    instruction="You are a helpful and friendly agent that answers questions about agriculture."
)
java
// Create a cross-region inference profile
CrossRegionInferenceProfile crossRegionProfile = CrossRegionInferenceProfile.fromConfig(CrossRegionInferenceProfileProps.builder()
        .geoRegion(CrossRegionInferenceProfileRegion.US)
        .model(BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0)
        .build());

// Use the cross-region profile with an agent
Agent agent = Agent.Builder.create(this, "Agent")
        .foundationModel(crossRegionProfile)
        .instruction("You are a helpful and friendly agent that answers questions about agriculture.")
        .build();
csharp
// Create a cross-region inference profile
var crossRegionProfile = CrossRegionInferenceProfile.FromConfig(new CrossRegionInferenceProfileProps {
    GeoRegion = CrossRegionInferenceProfileRegion.US,
    Model = BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0
});

// Use the cross-region profile with an agent
var agent = new Agent(this, "Agent", new AgentProps {
    FoundationModel = crossRegionProfile,
    Instruction = "You are a helpful and friendly agent that answers questions about agriculture."
});
go
// Create a cross-region inference profile
crossRegionProfile := bedrock.CrossRegionInferenceProfile_FromConfig(&CrossRegionInferenceProfileProps{
	GeoRegion: bedrock.CrossRegionInferenceProfileRegion_US,
	Model: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_3_5_SONNET_V1_0(),
})

// Use the cross-region profile with an agent
agent := bedrock.NewAgent(this, jsii.String("Agent"), &AgentProps{
	FoundationModel: crossRegionProfile,
	Instruction: jsii.String("You are a helpful and friendly agent that answers questions about agriculture."),
})

With Prompts ​

ts
// Create a prompt router for intelligent model selection
const promptRouter = bedrock.PromptRouter.fromDefaultId(
  bedrock.DefaultPromptRouterIdentifier.ANTHROPIC_CLAUDE_V1,
  'us-east-1'
);

// Use the prompt router with a prompt variant
const variant = bedrock.PromptVariant.text({
  variantName: 'variant1',
  promptText: 'What is the capital of France?',
  model: promptRouter,
});

new bedrock.Prompt(this, 'Prompt', {
  promptName: 'prompt-router-test',
  variants: [variant],
});
python
# Create a prompt router for intelligent model selection
prompt_router = bedrock.PromptRouter.from_default_id(bedrock.DefaultPromptRouterIdentifier.ANTHROPIC_CLAUDE_V1, "us-east-1")

# Use the prompt router with a prompt variant
variant = bedrock.PromptVariant.text(
    variant_name="variant1",
    prompt_text="What is the capital of France?",
    model=prompt_router
)

bedrock.Prompt(self, "Prompt",
    prompt_name="prompt-router-test",
    variants=[variant]
)
java
// Create a prompt router for intelligent model selection
PromptRouter promptRouter = PromptRouter.fromDefaultId(DefaultPromptRouterIdentifier.ANTHROPIC_CLAUDE_V1, "us-east-1");

// Use the prompt router with a prompt variant
IPromptVariant variant = PromptVariant.text(TextPromptVariantProps.builder()
        .variantName("variant1")
        .promptText("What is the capital of France?")
        .model(promptRouter)
        .build());

Prompt.Builder.create(this, "Prompt")
        .promptName("prompt-router-test")
        .variants(List.of(variant))
        .build();
csharp
// Create a prompt router for intelligent model selection
var promptRouter = PromptRouter.FromDefaultId(DefaultPromptRouterIdentifier.ANTHROPIC_CLAUDE_V1, "us-east-1");

// Use the prompt router with a prompt variant
var variant = PromptVariant.Text(new TextPromptVariantProps {
    VariantName = "variant1",
    PromptText = "What is the capital of France?",
    Model = promptRouter
});

new Prompt(this, "Prompt", new PromptProps {
    PromptName = "prompt-router-test",
    Variants = new [] { variant }
});
go
// Create a prompt router for intelligent model selection
promptRouter := bedrock.PromptRouter_FromDefaultId(bedrock.DefaultPromptRouterIdentifier_ANTHROPIC_CLAUDE_V1(), jsii.String("us-east-1"))

// Use the prompt router with a prompt variant
variant := bedrock.PromptVariant_Text(&TextPromptVariantProps{
	VariantName: jsii.String("variant1"),
	PromptText: jsii.String("What is the capital of France?"),
	Model: promptRouter,
})

bedrock.NewPrompt(this, jsii.String("Prompt"), &PromptProps{
	PromptName: jsii.String("prompt-router-test"),
	Variants: []IPromptVariant{
		variant,
	},
})

Types of Inference Profiles ​

Amazon Bedrock offers two types of inference profiles:

Application Inference Profiles ​

Application inference profiles are user-defined profiles that help you track costs and model usage. They can be created for a single region or for multiple regions using a cross-region inference profile.

Single Region Application Profile ​
ts
// Create an application inference profile for one Region
const appProfile = new bedrock.ApplicationInferenceProfile(this, 'MyApplicationProfile', {
  applicationInferenceProfileName: 'claude-3-sonnet-v1',
  modelSource: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0,
  description: 'Application profile for cost tracking',
  tags: {
    Environment: 'Production',
  },
});
python
# Create an application inference profile for one Region
app_profile = bedrock.ApplicationInferenceProfile(self, "MyApplicationProfile",
    application_inference_profile_name="claude-3-sonnet-v1",
    model_source=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0,
    description="Application profile for cost tracking",
    tags={
        "Environment": "Production"
    }
)
java
// Create an application inference profile for one Region
ApplicationInferenceProfile appProfile = ApplicationInferenceProfile.Builder.create(this, "MyApplicationProfile")
        .applicationInferenceProfileName("claude-3-sonnet-v1")
        .modelSource(BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0)
        .description("Application profile for cost tracking")
        .tags(Map.of(
                "Environment", "Production"))
        .build();
csharp
// Create an application inference profile for one Region
var appProfile = new ApplicationInferenceProfile(this, "MyApplicationProfile", new ApplicationInferenceProfileProps {
    ApplicationInferenceProfileName = "claude-3-sonnet-v1",
    ModelSource = BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0,
    Description = "Application profile for cost tracking",
    Tags = new Dictionary<string, string> {
        { "Environment", "Production" }
    }
});
go
// Create an application inference profile for one Region
appProfile := bedrock.NewApplicationInferenceProfile(this, jsii.String("MyApplicationProfile"), &ApplicationInferenceProfileProps{
	ApplicationInferenceProfileName: jsii.String("claude-3-sonnet-v1"),
	ModelSource: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_SONNET_V1_0(),
	Description: jsii.String("Application profile for cost tracking"),
	Tags: map[string]*string{
		"Environment": jsii.String("Production"),
	},
})
Multi-Region Application Profile ​
ts
// Create a cross-region inference profile
const crossRegionProfile = bedrock.CrossRegionInferenceProfile.fromConfig({
  geoRegion: bedrock.CrossRegionInferenceProfileRegion.US,
  model: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V2_0,
});

// Create an application inference profile across regions
const appProfile = new bedrock.ApplicationInferenceProfile(this, 'MyMultiRegionProfile', {
  applicationInferenceProfileName: 'claude-35-sonnet-v2-multi-region',
  modelSource: crossRegionProfile,
  description: 'Multi-region application profile for cost tracking',
});
python
# Create a cross-region inference profile
cross_region_profile = bedrock.CrossRegionInferenceProfile.from_config(
    geo_region=bedrock.CrossRegionInferenceProfileRegion.US,
    model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V2_0
)

# Create an application inference profile across regions
app_profile = bedrock.ApplicationInferenceProfile(self, "MyMultiRegionProfile",
    application_inference_profile_name="claude-35-sonnet-v2-multi-region",
    model_source=cross_region_profile,
    description="Multi-region application profile for cost tracking"
)
java
// Create a cross-region inference profile
CrossRegionInferenceProfile crossRegionProfile = CrossRegionInferenceProfile.fromConfig(CrossRegionInferenceProfileProps.builder()
        .geoRegion(CrossRegionInferenceProfileRegion.US)
        .model(BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V2_0)
        .build());

// Create an application inference profile across regions
ApplicationInferenceProfile appProfile = ApplicationInferenceProfile.Builder.create(this, "MyMultiRegionProfile")
        .applicationInferenceProfileName("claude-35-sonnet-v2-multi-region")
        .modelSource(crossRegionProfile)
        .description("Multi-region application profile for cost tracking")
        .build();
csharp
// Create a cross-region inference profile
var crossRegionProfile = CrossRegionInferenceProfile.FromConfig(new CrossRegionInferenceProfileProps {
    GeoRegion = CrossRegionInferenceProfileRegion.US,
    Model = BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V2_0
});

// Create an application inference profile across regions
var appProfile = new ApplicationInferenceProfile(this, "MyMultiRegionProfile", new ApplicationInferenceProfileProps {
    ApplicationInferenceProfileName = "claude-35-sonnet-v2-multi-region",
    ModelSource = crossRegionProfile,
    Description = "Multi-region application profile for cost tracking"
});
go
// Create a cross-region inference profile
crossRegionProfile := bedrock.CrossRegionInferenceProfile_FromConfig(&CrossRegionInferenceProfileProps{
	GeoRegion: bedrock.CrossRegionInferenceProfileRegion_US,
	Model: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_3_5_SONNET_V2_0(),
})

// Create an application inference profile across regions
appProfile := bedrock.NewApplicationInferenceProfile(this, jsii.String("MyMultiRegionProfile"), &ApplicationInferenceProfileProps{
	ApplicationInferenceProfileName: jsii.String("claude-35-sonnet-v2-multi-region"),
	ModelSource: crossRegionProfile,
	Description: jsii.String("Multi-region application profile for cost tracking"),
})

System Defined Inference Profiles ​

Cross-region inference enables you to seamlessly manage unplanned traffic bursts by utilizing compute across different AWS Regions. With cross-region inference, you can distribute traffic across multiple AWS Regions, enabling higher throughput and enhanced resilience during periods of peak demands.

Before using a CrossRegionInferenceProfile, ensure that you have access to the models and regions defined in the inference profiles. For instance, if you use the system defined inference profile "us.anthropic.claude-3-5-sonnet-20241022-v2:0", inference requests will be routed to US East (Virginia) us-east-1, US East (Ohio) us-east-2 and US West (Oregon) us-west-2. Thus, you need to have model access enabled in those regions for the model anthropic.claude-3-5-sonnet-20241022-v2:0.

System Defined Profile Configuration ​
ts
const crossRegionProfile = bedrock.CrossRegionInferenceProfile.fromConfig({
  geoRegion: bedrock.CrossRegionInferenceProfileRegion.US,
  model: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V2_0,
});
python
cross_region_profile = bedrock.CrossRegionInferenceProfile.from_config(
    geo_region=bedrock.CrossRegionInferenceProfileRegion.US,
    model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V2_0
)
java
CrossRegionInferenceProfile crossRegionProfile = CrossRegionInferenceProfile.fromConfig(CrossRegionInferenceProfileProps.builder()
        .geoRegion(CrossRegionInferenceProfileRegion.US)
        .model(BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V2_0)
        .build());
csharp
var crossRegionProfile = CrossRegionInferenceProfile.FromConfig(new CrossRegionInferenceProfileProps {
    GeoRegion = CrossRegionInferenceProfileRegion.US,
    Model = BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V2_0
});
go
crossRegionProfile := bedrock.CrossRegionInferenceProfile_FromConfig(&CrossRegionInferenceProfileProps{
	GeoRegion: bedrock.CrossRegionInferenceProfileRegion_US,
	Model: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_3_5_SONNET_V2_0(),
})

Prompt Routers ​

Amazon Bedrock intelligent prompt routing provides a single serverless endpoint for efficiently routing requests between different foundational models within the same model family. It can help you optimize for response quality and cost. They offer a comprehensive solution for managing multiple AI models through a single serverless endpoint, simplifying the process for you. Intelligent prompt routing predicts the performance of each model for each request, and dynamically routes each request to the model that it predicts is most likely to give the desired response at the lowest cost.

Default and Custom Prompt Routers ​

ts
// Use a default prompt router
const variant = bedrock.PromptVariant.text({
  variantName: 'variant1',
  promptText: 'What is the capital of France?',
  model: bedrock.PromptRouter.fromDefaultId(
    bedrock.DefaultPromptRouterIdentifier.ANTHROPIC_CLAUDE_V1,
    'us-east-1'
  ),
});

new bedrock.Prompt(this, 'Prompt', {
  promptName: 'prompt-router-test',
  variants: [variant],
});
python
# Use a default prompt router
variant = bedrock.PromptVariant.text(
    variant_name="variant1",
    prompt_text="What is the capital of France?",
    model=bedrock.PromptRouter.from_default_id(bedrock.DefaultPromptRouterIdentifier.ANTHROPIC_CLAUDE_V1, "us-east-1")
)

bedrock.Prompt(self, "Prompt",
    prompt_name="prompt-router-test",
    variants=[variant]
)
java
// Use a default prompt router
IPromptVariant variant = PromptVariant.text(TextPromptVariantProps.builder()
        .variantName("variant1")
        .promptText("What is the capital of France?")
        .model(PromptRouter.fromDefaultId(DefaultPromptRouterIdentifier.ANTHROPIC_CLAUDE_V1, "us-east-1"))
        .build());

Prompt.Builder.create(this, "Prompt")
        .promptName("prompt-router-test")
        .variants(List.of(variant))
        .build();
csharp
// Use a default prompt router
var variant = PromptVariant.Text(new TextPromptVariantProps {
    VariantName = "variant1",
    PromptText = "What is the capital of France?",
    Model = PromptRouter.FromDefaultId(DefaultPromptRouterIdentifier.ANTHROPIC_CLAUDE_V1, "us-east-1")
});

new Prompt(this, "Prompt", new PromptProps {
    PromptName = "prompt-router-test",
    Variants = new [] { variant }
});
go
// Use a default prompt router
variant := bedrock.PromptVariant_Text(&TextPromptVariantProps{
	VariantName: jsii.String("variant1"),
	PromptText: jsii.String("What is the capital of France?"),
	Model: bedrock.PromptRouter_FromDefaultId(bedrock.DefaultPromptRouterIdentifier_ANTHROPIC_CLAUDE_V1(), jsii.String("us-east-1")),
})

bedrock.NewPrompt(this, jsii.String("Prompt"), &PromptProps{
	PromptName: jsii.String("prompt-router-test"),
	Variants: []IPromptVariant{
		variant,
	},
})

Inference Profile Permissions ​

Use the grantProfileUsage method to grant appropriate permissions to resources that need to use the inference profile.

Granting Profile Usage Permissions ​

ts
// Create an application inference profile
const profile = new bedrock.ApplicationInferenceProfile(this, 'MyProfile', {
  applicationInferenceProfileName: 'my-profile',
  modelSource: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_4_5_V1_0,
});

// Create a Lambda function
const lambdaFunction = new lambda.Function(this, 'MyFunction', {
  runtime: lambda.Runtime.PYTHON_3_11,
  handler: 'index.handler',
  code: lambda.Code.fromInline('def handler(event, context): return "Hello"'),
});

// Grant the Lambda function permission to use the inference profile
profile.grantProfileUsage(lambdaFunction);

// Use a system defined inference profile
const crossRegionProfile = bedrock.CrossRegionInferenceProfile.fromConfig({
  geoRegion: bedrock.CrossRegionInferenceProfileRegion.US,
  model: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_4_5_V1_0,
});

// Grant permissions to use the cross-region inference profile
crossRegionProfile.grantProfileUsage(lambdaFunction);
python
# Create an application inference profile
profile = bedrock.ApplicationInferenceProfile(self, "MyProfile",
    application_inference_profile_name="my-profile",
    model_source=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_4_5_V1_0
)

# Create a Lambda function
lambda_function = lambda_.Function(self, "MyFunction",
    runtime=lambda_.Runtime.PYTHON_3_11,
    handler="index.handler",
    code=lambda_.Code.from_inline("def handler(event, context): return \"Hello\"")
)

# Grant the Lambda function permission to use the inference profile
profile.grant_profile_usage(lambda_function)

# Use a system defined inference profile
cross_region_profile = bedrock.CrossRegionInferenceProfile.from_config(
    geo_region=bedrock.CrossRegionInferenceProfileRegion.US,
    model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_4_5_V1_0
)

# Grant permissions to use the cross-region inference profile
cross_region_profile.grant_profile_usage(lambda_function)
java
// Create an application inference profile
ApplicationInferenceProfile profile = ApplicationInferenceProfile.Builder.create(this, "MyProfile")
        .applicationInferenceProfileName("my-profile")
        .modelSource(BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_4_5_V1_0)
        .build();

// Create a Lambda function
Function lambdaFunction = Function.Builder.create(this, "MyFunction")
        .runtime(Runtime.PYTHON_3_11)
        .handler("index.handler")
        .code(Code.fromInline("def handler(event, context): return \"Hello\""))
        .build();

// Grant the Lambda function permission to use the inference profile
profile.grantProfileUsage(lambdaFunction);

// Use a system defined inference profile
CrossRegionInferenceProfile crossRegionProfile = CrossRegionInferenceProfile.fromConfig(CrossRegionInferenceProfileProps.builder()
        .geoRegion(CrossRegionInferenceProfileRegion.US)
        .model(BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_4_5_V1_0)
        .build());

// Grant permissions to use the cross-region inference profile
crossRegionProfile.grantProfileUsage(lambdaFunction);
csharp
// Create an application inference profile
var profile = new ApplicationInferenceProfile(this, "MyProfile", new ApplicationInferenceProfileProps {
    ApplicationInferenceProfileName = "my-profile",
    ModelSource = BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_4_5_V1_0
});

// Create a Lambda function
var lambdaFunction = new Function(this, "MyFunction", new FunctionProps {
    Runtime = Runtime.PYTHON_3_11,
    Handler = "index.handler",
    Code = Code.FromInline("def handler(event, context): return \"Hello\"")
});

// Grant the Lambda function permission to use the inference profile
profile.GrantProfileUsage(lambdaFunction);

// Use a system defined inference profile
var crossRegionProfile = CrossRegionInferenceProfile.FromConfig(new CrossRegionInferenceProfileProps {
    GeoRegion = CrossRegionInferenceProfileRegion.US,
    Model = BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_4_5_V1_0
});

// Grant permissions to use the cross-region inference profile
crossRegionProfile.GrantProfileUsage(lambdaFunction);
go
// Create an application inference profile
profile := bedrock.NewApplicationInferenceProfile(this, jsii.String("MyProfile"), &ApplicationInferenceProfileProps{
	ApplicationInferenceProfileName: jsii.String("my-profile"),
	ModelSource: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_SONNET_4_5_V1_0(),
})

// Create a Lambda function
lambdaFunction := lambda.NewFunction(this, jsii.String("MyFunction"), &FunctionProps{
	Runtime: lambda.Runtime_PYTHON_3_11(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromInline(jsii.String("def handler(event, context): return \"Hello\"")),
})

// Grant the Lambda function permission to use the inference profile
profile.GrantProfileUsage(lambdaFunction)

// Use a system defined inference profile
crossRegionProfile := bedrock.CrossRegionInferenceProfile_FromConfig(&CrossRegionInferenceProfileProps{
	GeoRegion: bedrock.CrossRegionInferenceProfileRegion_US,
	Model: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_SONNET_4_5_V1_0(),
})

// Grant permissions to use the cross-region inference profile
crossRegionProfile.GrantProfileUsage(lambdaFunction)

The grantProfileUsage method adds the necessary IAM permissions to the resource, allowing it to use the inference profile. This includes permissions to call bedrock:GetInferenceProfile and bedrock:ListInferenceProfiles actions on the inference profile resource.

Inference Profiles Import Methods ​

You can import existing application inference profiles using the following methods:

ts
// Import an inference profile through attributes
const importedProfile = bedrock.ApplicationInferenceProfile.fromApplicationInferenceProfileAttributes(
  this,
  'ImportedProfile',
  {
    inferenceProfileArn: 'arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/my-profile-id',
    inferenceProfileIdentifier: 'my-profile-id',
  }
);
python
# Import an inference profile through attributes
imported_profile = bedrock.ApplicationInferenceProfile.from_application_inference_profile_attributes(self, "ImportedProfile",
    inference_profile_arn="arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/my-profile-id",
    inference_profile_identifier="my-profile-id"
)
java
// Import an inference profile through attributes
IInferenceProfile importedProfile = ApplicationInferenceProfile.fromApplicationInferenceProfileAttributes(this, "ImportedProfile", ApplicationInferenceProfileAttributes.builder()
        .inferenceProfileArn("arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/my-profile-id")
        .inferenceProfileIdentifier("my-profile-id")
        .build());
csharp
// Import an inference profile through attributes
var importedProfile = ApplicationInferenceProfile.FromApplicationInferenceProfileAttributes(this, "ImportedProfile", new ApplicationInferenceProfileAttributes {
    InferenceProfileArn = "arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/my-profile-id",
    InferenceProfileIdentifier = "my-profile-id"
});
go
// Import an inference profile through attributes
importedProfile := bedrock.ApplicationInferenceProfile_FromApplicationInferenceProfileAttributes(this, jsii.String("ImportedProfile"), &ApplicationInferenceProfileAttributes{
	InferenceProfileArn: jsii.String("arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/my-profile-id"),
	InferenceProfileIdentifier: jsii.String("my-profile-id"),
})

You can also import an application inference profile from an existing L1 CloudFormation construct:

ts
// Create or reference an existing L1 CfnApplicationInferenceProfile
const cfnProfile = new aws_bedrock_cfn.CfnApplicationInferenceProfile(this, 'CfnProfile', {
  inferenceProfileName: 'my-cfn-profile',
  modelSource: {
    copyFrom: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0.invokableArn,
  },
  description: 'Profile created via L1 construct',
});

// Import the L1 construct as an L2 ApplicationInferenceProfile
const importedFromCfn = bedrock.ApplicationInferenceProfile.fromCfnApplicationInferenceProfile(cfnProfile);

// Grant permissions to use the imported profile
const lambdaFunction = new lambda.Function(this, 'MyFunction', {
  runtime: lambda.Runtime.PYTHON_3_11,
  handler: 'index.handler',
  code: lambda.Code.fromInline('def handler(event, context): return "Hello"'),
});

importedFromCfn.grantProfileUsage(lambdaFunction);
python
# Create or reference an existing L1 CfnApplicationInferenceProfile
cfn_profile = aws_bedrock_cfn.CfnApplicationInferenceProfile(self, "CfnProfile",
    inference_profile_name="my-cfn-profile",
    model_source=aws_bedrock_cfn.CfnApplicationInferenceProfile.InferenceProfileModelSourceProperty(
        copy_from=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0.invokable_arn
    ),
    description="Profile created via L1 construct"
)

# Import the L1 construct as an L2 ApplicationInferenceProfile
imported_from_cfn = bedrock.ApplicationInferenceProfile.from_cfn_application_inference_profile(cfn_profile)

# Grant permissions to use the imported profile
lambda_function = lambda_.Function(self, "MyFunction",
    runtime=lambda_.Runtime.PYTHON_3_11,
    handler="index.handler",
    code=lambda_.Code.from_inline("def handler(event, context): return \"Hello\"")
)

imported_from_cfn.grant_profile_usage(lambda_function)
java
// Create or reference an existing L1 CfnApplicationInferenceProfile
CfnApplicationInferenceProfile cfnProfile = CfnApplicationInferenceProfile.Builder.create(this, "CfnProfile")
        .inferenceProfileName("my-cfn-profile")
        .modelSource(InferenceProfileModelSourceProperty.builder()
                .copyFrom(BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0.getInvokableArn())
                .build())
        .description("Profile created via L1 construct")
        .build();

// Import the L1 construct as an L2 ApplicationInferenceProfile
IInferenceProfile importedFromCfn = ApplicationInferenceProfile.fromCfnApplicationInferenceProfile(cfnProfile);

// Grant permissions to use the imported profile
Function lambdaFunction = Function.Builder.create(this, "MyFunction")
        .runtime(Runtime.PYTHON_3_11)
        .handler("index.handler")
        .code(Code.fromInline("def handler(event, context): return \"Hello\""))
        .build();

importedFromCfn.grantProfileUsage(lambdaFunction);
csharp
// Create or reference an existing L1 CfnApplicationInferenceProfile
var cfnProfile = new CfnApplicationInferenceProfile(this, "CfnProfile", new CfnApplicationInferenceProfileProps {
    InferenceProfileName = "my-cfn-profile",
    ModelSource = new InferenceProfileModelSourceProperty {
        CopyFrom = BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0.InvokableArn
    },
    Description = "Profile created via L1 construct"
});

// Import the L1 construct as an L2 ApplicationInferenceProfile
var importedFromCfn = ApplicationInferenceProfile.FromCfnApplicationInferenceProfile(cfnProfile);

// Grant permissions to use the imported profile
var lambdaFunction = new Function(this, "MyFunction", new FunctionProps {
    Runtime = Runtime.PYTHON_3_11,
    Handler = "index.handler",
    Code = Code.FromInline("def handler(event, context): return \"Hello\"")
});

importedFromCfn.GrantProfileUsage(lambdaFunction);
go
// Create or reference an existing L1 CfnApplicationInferenceProfile
cfnProfile := awscdk.Aws_bedrock.NewCfnApplicationInferenceProfile(this, jsii.String("CfnProfile"), &CfnApplicationInferenceProfileProps{
	InferenceProfileName: jsii.String("my-cfn-profile"),
	ModelSource: &InferenceProfileModelSourceProperty{
		CopyFrom: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_3_5_SONNET_V1_0().InvokableArn,
	},
	Description: jsii.String("Profile created via L1 construct"),
})

// Import the L1 construct as an L2 ApplicationInferenceProfile
importedFromCfn := bedrock.ApplicationInferenceProfile_FromCfnApplicationInferenceProfile(cfnProfile)

// Grant permissions to use the imported profile
lambdaFunction := lambda.NewFunction(this, jsii.String("MyFunction"), &FunctionProps{
	Runtime: lambda.Runtime_PYTHON_3_11(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromInline(jsii.String("def handler(event, context): return \"Hello\"")),
})

importedFromCfn.GrantProfileUsage(lambdaFunction)

Types ​

NameKindSummary
AgentAliasBaseConstruct (L2)Abstract base class for an Agent.
AgentBaseConstruct (L2)Abstract base class for an Agent.
GuardrailBaseConstruct (L2)Abstract base class for a Guardrail.
InferenceProfileBaseConstruct (L2)Abstract base class for an Inference Profile.
PromptBaseConstruct (L2)Abstract base class for a Prompt.
AgentConstruct (L1)Class to create (or import) an Agent with CDK.
AgentAliasConstruct (L1)Class to create an Agent Alias with CDK.
ApplicationInferenceProfileConstruct (L1)Class to create an Application Inference Profile with CDK.
GuardrailConstruct (L1)Class to create a Guardrail with CDK.
PromptConstruct (L1)Class to create (or import) a Prompt with CDK.
PromptVersionConstruct (L1)Class to create a Prompt Version with CDK.
ActionGroupExecutorClassDefines how fulfillment of the action group is handled after the necessary information has been elicited from the user.
AgentActionGroupClass**************************************************************************** DEF - Action Group Class ***************************************************************************.
AgentActionGroupPropsStruct**************************************************************************** PROPS - Action Group Class ***************************************************************************.
AgentAliasAttributesStructAttributes needed to create an import.
AgentAliasPropsStructProperties for creating a CDK-Managed Agent Alias.
AgentAttributesStructAttributes for specifying an imported Bedrock Agent.
AgentCollaborationClassClass to manage agent collaboration configuration.
AgentCollaborationConfigStructConfiguration for agent collaboration settings.
AgentCollaboratorClass**************************************************************************** Agent Collaborator Class ***************************************************************************.
AgentCollaboratorPropsStruct**************************************************************************** PROPS - Agent Collaborator Class ***************************************************************************.
AgentCollaboratorTypeEnumEnum for collaborator's relay conversation history types.
AgentGenAiResourcePropsStructProperties for creating an agent GenAI resource configuration.
AgentPromptVariantPropsStructProperties for creating an agent prompt variant.
AgentPropsStructProperties for creating a CDK managed Bedrock Agent.
AgentStepTypeEnumThe step in the agent sequence that this prompt configuration applies to.
ApiSchemaClassRepresents the concept of an API Schema for a Bedrock Agent Action Group.
ApplicationInferenceProfileAttributesStructAttributes for specifying an imported Application Inference Profile.
ApplicationInferenceProfilePropsStructProperties for creating an Application Inference Profile.
AssetApiSchemaClassAPI Schema from a local asset.
BedrockFoundationModelClassBedrock models.
BedrockFoundationModelPropsStructProperties for configuring a Bedrock Foundation Model.
CanadaSpecificPIITypeClassTypes of PII specific to Canada.
ChatMessageClassRepresents a message in a chat conversation.
ChatMessageRoleEnumThe role of a message in a chat conversation.
ChatPromptVariantPropsStructProperties for creating a chat prompt variant.
ChatTemplateConfigurationPropsStructProperties for creating a chat template configuration.
CommonPromptVariantPropsStructCommon properties for all prompt variants.
ContentFilterStructInterface to declare a content filter.
ContentFilterStrengthEnumThe strength of the content filter.
ContentFilterTypeEnumThe type of harmful category usable in a content filter.
ContextualGroundingFilterStructInterface to define a Contextual Grounding Filter.
ContextualGroundingFilterTypeEnumThe type of contextual grounding filter.
CrossRegionInferenceProfileClassCross-region inference enables you to seamlessly manage unplanned traffic bursts by utilizing compute across different AWS Regions.
CrossRegionInferenceProfilePropsStructProperties for creating a Cross-Region Inference Profile.
CrossRegionInferenceProfileRegionEnumGeographic regions supported for cross-region inference profiles.
CustomControlEnumThe type of custom control for the action group executor.
CustomOrchestrationExecutorClassContains details about the Lambda function containing the orchestration logic carried out upon invoking the custom orchestration.
CustomParserPropsStructProperties for configuring a custom Lambda parser for prompt overrides.
CustomTopicPropsStructInterface for creating a custom Topic.
DefaultPromptRouterIdentifierClassRepresents identifiers for default prompt routers in Bedrock.
FinancePIITypeClassTypes of PII in the domain of Finance.
FunctionClassRepresents a function in a function schema.
FunctionParameterClassRepresents a function parameter in a function schema.
FunctionParameterPropsStructProperties for a function parameter.
FunctionPropsStructProperties for a function in a function schema.
FunctionSchemaClassRepresents a function schema for a Bedrock Agent Action Group.
FunctionSchemaPropsStructProperties for a function schema.
FunctionToolPropsStructProperties for creating a function tool.
GeneralPIITypeClassTypes of PII that are general, and not domain-specific.
GuardrailActionEnumGuardrail action when a sensitive entity is detected.
GuardrailAttributesStruct**************************************************************************** ATTRS FOR IMPORTED CONSTRUCT ***************************************************************************.
GuardrailCrossRegionConfigPropertyStructGuardrailCrossRegionConfigProperty.
GuardrailPropsStructProperties for creating a Guardrail.
IAgentInterfaceRepresents an Agent, either created with CDK or imported.
IAgentAliasInterfaceRepresents an Agent Alias, either created with CDK or imported.
IBedrockInvokableInterfaceRepresents an Amazon Bedrock abstraction on which you can run the Invoke API.
IGuardrailInterfaceRepresents a Guardrail, either created with CDK or imported.
IInferenceProfileInterfaceRepresents an Inference Profile, either created with CDK or imported.
InferenceConfigurationStructLLM inference configuration.
InferenceProfileTypeEnumThese are the values used by the API when using aws bedrock get-inference-profile --inference-profile-identifier XXXXXXX.
InformationTechnologyPIITypeClassTypes of PII in the domain of IT (Information Technology).
InlineApiSchemaClassClass to define an API Schema from an inline string.
IPromptInterfaceRepresents a Prompt, either created with CDK or imported.
IPromptRouterInterfaceRepresents a Prompt Router, which provides intelligent routing between different models.
IPromptVariantInterfaceInterface representing a prompt variant configuration.
ManagedWordFilterStructInterface for managed word list filters.
ManagedWordFilterTypeEnumManaged word list filter types supported by Amazon Bedrock.
MemoryClassMemory class for managing Bedrock Agent memory configurations.
ModalityTypeEnumThe type of modality that can be used in content filters.
OrchestrationTypeEnumEnum for orchestration types available for agents.
ParameterTypeEnumEnum for parameter types in function schemas.
ParentActionGroupSignatureClassAWS Defined signatures for enabling certain capabilities in your agent.
PIIFilterStructInterface to define a PII Filter.
PIITypeClassAbstract base class for all PII types.
PromptAttributesStructAttributes for specifying an imported Bedrock Prompt.
PromptGenAiResourceClassAbstract base class for prompt GenAI resource configurations.
PromptInferenceConfigurationClassAbstract base class for prompt inference configurations.
PromptInferenceConfigurationPropsStructProperties for creating a prompt inference configuration.
PromptKnowledgeBaseResponseGenerationConfigCustomParserStructConfiguration for the knowledge base response generation step.
PromptMemorySummarizationConfigCustomParserStructConfiguration for the memory summarization step.
PromptOrchestrationConfigCustomParserStructConfiguration for the orchestration step.
PromptOverrideConfigurationClassConfiguration for overriding prompt templates and behaviors in different parts of an agent's sequence.
PromptPostProcessingConfigCustomParserStructConfiguration for the post-processing step.
PromptPreProcessingConfigCustomParserStructConfiguration for the pre-processing step.
PromptPropsStructProperties for creating a CDK managed Bedrock Prompt.
PromptRouterClassAmazon Bedrock intelligent prompt routing provides a single serverless endpoint for efficiently routing requests between different foundational models within the same model family.
PromptRouterPropsStructProperties for configuring a Prompt Router.
PromptRoutingClassifierConfigCustomParserStructConfiguration for the routing classifier step.
PromptStepConfigBaseStructBase configuration interface for all prompt step types.
PromptTemplateConfigurationClassAbstract base class for prompt template configurations.
PromptTemplateTypeEnumThe type of prompt template.
PromptVariantClassFactory class for creating prompt variants.
PromptVersionPropsStructProperties for creating a CDK managed Bedrock Prompt Version.
RegexFilterStructA Regular expression (regex) filter for sensitive information.
RequireConfirmationEnumEnum for require confirmation state in function schemas.
S3ApiSchemaClassClass to define an API Schema from an S3 object.
SessionSummaryMemoryPropsStructProperties for SessionSummaryConfiguration.
TextPromptVariantPropsStructProperties for creating a text prompt variant.
TextTemplateConfigurationPropsStructProperties for creating a text template configuration.
TierConfigEnum**************************************************************************** TIER CONFIG ***************************************************************************.
ToolClassAbstract base class for tools that can be used by the model.
ToolChoiceClassDefines how the model should choose which tool to use.
ToolConfigurationStructConfiguration for tools available to the model.
TopicClassRepresents predefined topics that can be used to filter content.
UKSpecificPIITypeClassTypes of PII specific to the United Kingdom (UK).
USASpecificPIITypeClassTypes of PII specific to the USA.
VectorTypeEnumThe data type for the vectors when using a model to convert text into vector embeddings.
WordFilterStructInterface to define a Word Filter.