# Evaluator

L2 construct · Deprecated

A custom evaluator for Amazon Bedrock AgentCore.

Custom evaluators enable you to define evaluation logic tailored to your specific
use cases. Supports two evaluation strategies:
- **LLM-as-a-Judge**: Uses a foundation model with custom instructions and a rating scale.
- **Code-based**: Uses a Lambda function for custom evaluation logic.

Custom evaluators are used with `OnlineEvaluationConfig` via `EvaluatorReference.custom()`.

Extends: [Construct](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.Construct.html) › [Resource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Resource.html) › [EvaluatorBase](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-agentcore-alpha.EvaluatorBase.html) › Evaluator
Implements: [IEvaluator](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-agentcore-alpha.IEvaluator.html), [IResource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResource.html), [IEnvironmentAware](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.interfaces.IEnvironmentAware.html), [IEvaluatorRef](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_bedrockagentcore.IEvaluatorRef.html), [IConstruct](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.IConstruct.html), IDependable

- CloudFormation: [`AWS::BedrockAgentCore::Evaluator`](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-bedrockagentcore-evaluator.html)
- L1 type: [`CfnEvaluator`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.CfnEvaluator.html)
- Source: [`lib/evaluation/custom-evaluator.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/@aws-cdk/aws-bedrock-agentcore-alpha/lib/evaluation/custom-evaluator.ts#L118)
- Type last changed: v2.278.0-alpha.0 · 21 Nov 2026

## Example

TypeScript:

```ts
// Create a custom LLM-as-a-Judge evaluator
const evaluator = new agentcore.Evaluator(this, 'MyEvaluator', {
  evaluatorName: 'my_custom_evaluator',
  level: agentcore.EvaluationLevel.SESSION,
  evaluatorConfig: agentcore.EvaluatorConfig.llmAsAJudge({
    instructions: 'Evaluate whether the agent response is helpful and accurate.',
    modelId: 'us.anthropic.claude-sonnet-4-6',
    ratingScale: agentcore.EvaluatorRatingScale.categorical([
      { label: 'Good', definition: 'The response is helpful and accurate.' },
      { label: 'Bad', definition: 'The response is not helpful or contains errors.' },
    ]),
  }),
});

// Use the custom evaluator in an online evaluation configuration
new agentcore.OnlineEvaluationConfig(this, 'MyEvaluation', {
  onlineEvaluationConfigName: 'my_evaluation',
  evaluators: [
    agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.HELPFULNESS),
    agentcore.EvaluatorReference.custom(evaluator),
  ],
  dataSource: agentcore.DataSourceConfig.fromCloudWatchLogs({
    logGroupNames: ['/aws/bedrock-agentcore/my-agent'],
    serviceNames: ['my-agent.default'],
  }),
});
```

Python:

```python
# Create a custom LLM-as-a-Judge evaluator
evaluator = agentcore.Evaluator(self, "MyEvaluator",
    evaluator_name="my_custom_evaluator",
    level=agentcore.EvaluationLevel.SESSION,
    evaluator_config=agentcore.EvaluatorConfig.llm_as_a_judge(
        instructions="Evaluate whether the agent response is helpful and accurate.",
        model_id="us.anthropic.claude-sonnet-4-6",
        rating_scale=agentcore.EvaluatorRatingScale.categorical([agentcore.CategoricalRatingOption(label="Good", definition="The response is helpful and accurate."), agentcore.CategoricalRatingOption(label="Bad", definition="The response is not helpful or contains errors.")
        ])
    )
)

# Use the custom evaluator in an online evaluation configuration
agentcore.OnlineEvaluationConfig(self, "MyEvaluation",
    online_evaluation_config_name="my_evaluation",
    evaluators=[
        agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.HELPFULNESS),
        agentcore.EvaluatorReference.custom(evaluator)
    ],
    data_source=agentcore.DataSourceConfig.from_cloud_watch_logs(
        log_group_names=["/aws/bedrock-agentcore/my-agent"],
        service_names=["my-agent.default"]
    )
)
```

Java:

```java
// Create a custom LLM-as-a-Judge evaluator
Evaluator evaluator = Evaluator.Builder.create(this, "MyEvaluator")
        .evaluatorName("my_custom_evaluator")
        .level(EvaluationLevel.SESSION)
        .evaluatorConfig(EvaluatorConfig.llmAsAJudge(LlmAsAJudgeOptions.builder()
                .instructions("Evaluate whether the agent response is helpful and accurate.")
                .modelId("us.anthropic.claude-sonnet-4-6")
                .ratingScale(EvaluatorRatingScale.categorical(List.of(CategoricalRatingOption.builder().label("Good").definition("The response is helpful and accurate.").build(), CategoricalRatingOption.builder().label("Bad").definition("The response is not helpful or contains errors.").build())))
                .build()))
        .build();

// Use the custom evaluator in an online evaluation configuration
// Use the custom evaluator in an online evaluation configuration
OnlineEvaluationConfig.Builder.create(this, "MyEvaluation")
        .onlineEvaluationConfigName("my_evaluation")
        .evaluators(List.of(EvaluatorReference.builtin(BuiltinEvaluator.HELPFULNESS), EvaluatorReference.custom(evaluator)))
        .dataSource(DataSourceConfig.fromCloudWatchLogs(CloudWatchLogsDataSourceConfig.builder()
                .logGroupNames(List.of("/aws/bedrock-agentcore/my-agent"))
                .serviceNames(List.of("my-agent.default"))
                .build()))
        .build();
```

C#:

```csharp
// Install: dotnet add package Amazon.CDK.AWS.Bedrock.Agentcore.Alpha
// Create a custom LLM-as-a-Judge evaluator
var evaluator = new Evaluator(this, "MyEvaluator", new EvaluatorProps {
    EvaluatorName = "my_custom_evaluator",
    Level = EvaluationLevel.SESSION,
    EvaluatorConfig = EvaluatorConfig.LlmAsAJudge(new LlmAsAJudgeOptions {
        Instructions = "Evaluate whether the agent response is helpful and accurate.",
        ModelId = "us.anthropic.claude-sonnet-4-6",
        RatingScale = EvaluatorRatingScale.Categorical(new [] { new CategoricalRatingOption { Label = "Good", Definition = "The response is helpful and accurate." }, new CategoricalRatingOption { Label = "Bad", Definition = "The response is not helpful or contains errors." } })
    })
});

// Use the custom evaluator in an online evaluation configuration
// Use the custom evaluator in an online evaluation configuration
new OnlineEvaluationConfig(this, "MyEvaluation", new OnlineEvaluationConfigProps {
    OnlineEvaluationConfigName = "my_evaluation",
    Evaluators = new [] { EvaluatorReference.Builtin(BuiltinEvaluator.HELPFULNESS), EvaluatorReference.Custom(evaluator) },
    DataSource = DataSourceConfig.FromCloudWatchLogs(new CloudWatchLogsDataSourceConfig {
        LogGroupNames = new [] { "/aws/bedrock-agentcore/my-agent" },
        ServiceNames = new [] { "my-agent.default" }
    })
});
```

Go:

```go
// Install: go get github.com/aws/aws-cdk-go/awsbedrockagentcorealpha/v2
// Create a custom LLM-as-a-Judge evaluator
evaluator := agentcore.NewEvaluator(this, jsii.String("MyEvaluator"), &EvaluatorProps{
	EvaluatorName: jsii.String("my_custom_evaluator"),
	Level: agentcore.EvaluationLevel_SESSION(),
	EvaluatorConfig: agentcore.EvaluatorConfig_LlmAsAJudge(&LlmAsAJudgeOptions{
		Instructions: jsii.String("Evaluate whether the agent response is helpful and accurate."),
		ModelId: jsii.String("us.anthropic.claude-sonnet-4-6"),
		RatingScale: agentcore.EvaluatorRatingScale_Categorical([]CategoricalRatingOption{
			&CategoricalRatingOption{
				Label: jsii.String("Good"),
				Definition: jsii.String("The response is helpful and accurate."),
			},
			&CategoricalRatingOption{
				Label: jsii.String("Bad"),
				Definition: jsii.String("The response is not helpful or contains errors."),
			},
		}),
	}),
})

// Use the custom evaluator in an online evaluation configuration
// Use the custom evaluator in an online evaluation configuration
agentcore.NewOnlineEvaluationConfig(this, jsii.String("MyEvaluation"), &OnlineEvaluationConfigProps{
	OnlineEvaluationConfigName: jsii.String("my_evaluation"),
	Evaluators: []EvaluatorReference{
		agentcore.EvaluatorReference_Builtin(agentcore.BuiltinEvaluator_HELPFULNESS()),
		agentcore.EvaluatorReference_Custom(evaluator),
	},
	DataSource: agentcore.DataSourceConfig_FromCloudWatchLogs(&CloudWatchLogsDataSourceConfig{
		LogGroupNames: []*string{
			jsii.String("/aws/bedrock-agentcore/my-agent"),
		},
		ServiceNames: []*string{
			jsii.String("my-agent.default"),
		},
	}),
})
```

## Initializer

TypeScript:

```ts
new Evaluator(scope: Construct, id: string, props: EvaluatorProps)
```

Python:

```python
Evaluator(scope: Construct, id: str, props: EvaluatorProps)
```

Java:

```java
new Evaluator(Construct scope, String id, EvaluatorProps props)
```

C#:

```csharp
new Evaluator(Construct scope, string id, EvaluatorProps props)
```

Go:

```go
NewEvaluator(Scope Construct, Id *string, Props EvaluatorProps)
```

## Construct Props

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

  **Default:** No description

- `evaluatorConfig`: [EvaluatorConfig](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-agentcore-alpha.EvaluatorConfig.html) (required) — The configuration that defines how the evaluator assesses agent performance.

  Use `EvaluatorConfig.llmAsAJudge()` for model-based evaluation or
  `EvaluatorConfig.codeBased()` for Lambda-based evaluation.

- `evaluatorName`: string (required) — The name of the evaluator.

  Must be unique within your account. Valid characters are a-z, A-Z, 0-9, _ (underscore).
  Must start with a letter and can be up to 48 characters long.

- `level`: [EvaluationLevel](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-agentcore-alpha.EvaluationLevel.html) (required) — The level at which the evaluator assesses agent performance.

  Determines what granularity of data the evaluator operates on:
  tool call, trace (single request-response), or session (full conversation).

- `tags`: { [key: string]: string } — Tags for the evaluator.

  **Default:** No tags

  A list of key:value pairs of tags to apply to this Evaluator resource.

## Properties

- `createdAt`: string — The timestamp when the evaluator was created.

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

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

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

- `evaluatorArn`: string — The ARN of the evaluator.

- `evaluatorId`: string — The unique identifier of the evaluator.

- `evaluatorName`: string — The name of the evaluator.

- `evaluatorRef`: [EvaluatorReference](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_bedrockagentcore.EvaluatorReference.html) — A reference to this Evaluator resource.

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

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

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

- `status`: string — The lifecycle status of the evaluator.

- `updatedAt`: string — The timestamp when the evaluator was last updated.

## Methods

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

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

  **Parameters**

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

- `applyRemovalPolicy(policy: RemovalPolicy): void` — Apply the given removal policy to this resource.

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

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

- `fromEvaluatorArn(scope: Construct, id: string, evaluatorArn: string): IEvaluator` (static) — Import an existing Evaluator by its ARN.

  **Parameters**

  - `scope` — - The construct scope.
  - `id` — - Construct identifier.
  - `evaluatorArn` — - The evaluator ARN to import.

  **Returns:** An IEvaluator reference

- `fromEvaluatorAttributes(scope: Construct, id: string, attrs: EvaluatorAttributes): IEvaluator` (static) — Import an existing Evaluator from its attributes.

  **Parameters**

  - `scope` — - The construct scope.
  - `id` — - Construct identifier.
  - `attrs` — - The evaluator attributes.

  **Returns:** An IEvaluator reference

- `fromEvaluatorId(scope: Construct, id: string, evaluatorId: string): IEvaluator` (static) — Import an existing Evaluator by its ID.

  **Parameters**

  - `scope` — - The construct scope.
  - `id` — - Construct identifier.
  - `evaluatorId` — - The evaluator ID to import.

  **Returns:** An IEvaluator reference

- `grant(grantee: IGrantable, ...actions: string[]): Grant` — Grants IAM actions to the IAM Principal.

  [disable-awslint:no-grants]

  **Parameters**

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

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

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

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

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

  **Parameters**

  - `x` — Any object.

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

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

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

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

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

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