Create Evaluators
With an Evaluator, you can score one response at a time and get one or more named metrics, such as accuracy or politeness. Evaluation Criteria refer to these metric names. Use a built-in Evaluator when one fits your use case. Create your own Evaluator when you need your own rubric or your own code.
Use a built-in Evaluator
SageMaker AI provides built-in LLM judge Evaluators for the following metrics. In Evaluation Criteria, you refer to a built-in Evaluator by the identifier in the second column.
| Metric | Identifier in Evaluation Criteria | What it measures | Uses the reference answer |
|---|---|---|---|
| Correctness | Builtin.Correctness |
Whether the response is correct. If the dataset has a reference answer, the judge uses it. | When present |
| Completeness | Builtin.Completeness |
Whether the response answers every question in the prompt. | When present |
| Faithfulness | Builtin.Faithfulness |
Whether the response contains information that the prompt does not support. | No |
| Helpfulness | Builtin.Helpfulness |
Whether the response follows instructions, is coherent, and anticipates implicit needs. | No |
| Coherence | Builtin.Coherence |
Whether the response has logical gaps, inconsistencies, or contradictions. | No |
| Relevance | Builtin.Relevance |
Whether the response is relevant to the prompt. | No |
| Following instructions | Builtin.FollowingInstructions |
Whether the response respects the exact directions in the prompt. | No |
| Professional style and tone | Builtin.ProfessionalStyleAndTone |
Whether the style, formatting, and tone suit a professional setting. | No |
| Harmfulness | Builtin.Harmfulness |
Whether the response contains harmful content. | No |
| Stereotyping | Builtin.Stereotyping |
Whether the response contains stereotypes, positive or negative. | No |
| Refusal | Builtin.Refusal |
Whether the response declines to answer the prompt. | No |
Every built-in judge accepts data in any of the formats in Prepare an evaluation dataset. It fills its prompt as described in Write a judge prompt.
For more information about built-in judge metrics, see Submit a builtin metrics LLMAJ job.
Use a built-in code Evaluator
For common checks, SageMaker AI provides built-in Evaluators that run code, so you don't write a function. They come from the open source verl library.
| Built-in | Checks | Data it needs |
|---|---|---|
Builtin.prime_math |
Whether the final answer in the response matches the correct answer to a math problem | The math question as the prompt, and the correct answer as the reference answer, in any supported dataset format |
Builtin.prime_code |
Whether generated code passes the test cases of the problem | The coding problem as the prompt. The test cases go in metadata: the function name in fn_name, and the sample inputs and expected outputs. |
For examples of the data, see Built-in Scorers.
Create an LLM judge Evaluator
An LLM judge sends each sample to a judge model with a prompt template that you write, and the judge returns a value for each metric that you declare.
-
Write the judge prompt as a UTF-8 text file. Use the placeholders
{{prompt}},{{prediction}}, and{{ground_truth}}, written without spaces. The prompt must include{{prediction}}; otherwise, the judge never sees the response. SageMaker AI uses the text exactly as stored. -
Upload the prompt to an Amazon S3 bucket in the job Region.
-
Write the Evaluator document, as in the following example.
-
Import the document as hub content of type
JsonDoc. Wrap the Evaluator in an envelope with"SubType": "AWS/Evaluator"and the Evaluator JSON as a string inJsonContent, and use document schema version2.0.0. -
Create Evaluation Criteria that use the Evaluator, and set the thresholds that a model must meet. For more information, see Define Evaluation Criteria.
{ "SchemaVersion": "2.1.0", "EvaluatorType": "RewardPrompt", "Reference": "s3://amzn-s3-demo-bucket/judges/accuracy-judge.txt", "JudgeModels": [ { "InferenceProvider": "Bedrock", "ModelId": "anthropic.claude-haiku-4-5", "InferenceConfig": { "MaxOutputTokens": 1024, "Temperature": 0 } } ], "OutputMetrics": [ { "Name": "accuracy", "Type": "number", "Direction": "higher_is_better", "Description": "How accurately the answer matches the reference answer: 0, 0.5 or 1." } ], "TimeoutSeconds": 60 }
Run the following command to import the Evaluator document as hub content. The file accuracy-judge-envelope.json contains the envelope that wraps the Evaluator document:
aws sagemaker import-hub-content \ --hub-name my-hub \ --hub-content-name accuracy-judge \ --hub-content-type JsonDoc \ --document-schema-version 2.0.0 \ --hub-content-document file://accuracy-judge-envelope.json
Replace the bucket name, hub name, and file name with your own values.
Write a judge prompt
A judge prompt is a template. You write the rubric, and you place placeholders where the data of each sample should go. SageMaker AI fills in the placeholders as plain text for each sample, in every dataset format. Write each placeholder without spaces.
| Placeholder | Filled with | Present |
|---|---|---|
{{prompt}} |
The input that the model received: the system and user turns of the row, joined by newlines | Always |
{{prediction}} |
The final answer text of the model | Always. The prompt must include it. |
{{ground_truth}} |
The reference answer, as text. For where SageMaker AI reads it, see Choose a dataset format. | When the row has one. Otherwise empty. |
The prompt is used exactly as you store it. Follow these guidelines:
-
Tell the judge how to rate the response, and define each score or label that it can return. Clear definitions give more consistent scores.
-
Keep the prompt meaningful when
{{ground_truth}}is empty, or setRequiresGroundTruthtofalseso that the Evaluator is used only where a reference answer exists. -
Use a low temperature, such as 0, so that the same sample gets the same score. The default is 0.
-
Declare each value that the judge returns in
OutputMetrics. A metric is either anumber, with aDirectionthat says whether higher or lower is better, or acategoricallabel.
Evaluator document fields
| Field | Required | Description |
|---|---|---|
SchemaVersion |
Yes | Must be 2.1.0. |
EvaluatorType |
Yes | RewardPrompt for an LLM judge, or RewardFunction for a Lambda function. |
Reference |
Yes | For RewardPrompt, the Amazon S3 URI of the judge prompt. For RewardFunction, the ARN of the Lambda function. |
JudgeModels |
For RewardPrompt |
Exactly one judge model. InferenceProvider must be Bedrock. ModelId is a Amazon Bedrock model ID or inference profile. Not valid for RewardFunction. |
JudgeModels[].InferenceConfig |
No | MaxOutputTokens is the maximum number of tokens that the judge can generate, including its reasoning. If you omit it, the default of the model provider applies. A response that reaches the limit is not scored, so allow room for the reasoning. Temperature is 0 to 1 and defaults to 0. |
OutputMetrics |
For RewardPrompt |
1 to 10 metrics that the Evaluator emits for each sample. Each metric has a Name (letters, digits, and underscores, up to 128 characters, not starting with a digit), a Type of number or categorical, and optionally a Direction (higher_is_better or lower_is_better, for number metrics only), a Description of up to 1,024 characters, and RequiresGroundTruth. The name reasoning is reserved. |
TimeoutSeconds |
No | Maximum time in seconds for one judge call or one function invocation. 1 to 300. A judge call that times out leaves the sample unscored. |
BatchSize |
No | Maximum samples in one function invocation. 1 to 10, default 1. RewardFunction only. |
RequiresGroundTruth |
No | Whether the Evaluator needs a reference answer. Defaults to true. Each output metric can override it. |
Create an AWS Lambda function Evaluator
Use an AWS Lambda function when a programmatic check gives a reliable score, for example exact match, valid JSON, or code that passes its tests. You write the function in Python and deploy it. SageMaker AI calls it with a batch of samples that include the responses of the model, and the function returns a score for each one. Set EvaluatorType to RewardFunction, and set Reference to the function ARN. Use a version or an alias, so that the function can't change under an Evaluator that you pinned.
{ "SchemaVersion": "2.1.0", "EvaluatorType": "RewardFunction", "Reference": "arn:aws:lambda:us-west-2:111122223333:function:gsm8k-exact-match:3", "OutputMetrics": [ { "Name": "exact_match", "Type": "number", "Direction": "higher_is_better", "Description": "1 when the final answer equals the reference answer, otherwise 0." } ], "TimeoutSeconds": 10, "BatchSize": 10 }
Replace the Region, account ID, and function name with your own values. BatchSize is the maximum number of samples in one invocation, from 1 to 10. The default is 1.
After you create the function Evaluator, create Evaluation Criteria that use it. For more information, see Define Evaluation Criteria.
Function input
The function receives a list of samples. Each sample has the shape of your dataset format, with the response of the model added where that format expects it. Because each format puts the fields in a different place, read the fields from the location in the following table.
| Dataset format | Prompt | Model response | Reference answer |
|---|---|---|---|
| OpenAI chat | messages (system and user) |
The last assistant message |
reference_answer.text |
| Nova RLVR | messages |
The last assistant message |
reference_answer |
| Hugging Face prompt-completion | prompt |
completion. SageMaker AI replaces the value in the dataset with the response. |
reference_answer.text |
| Hugging Face preference | prompt |
completion |
reference_answer.text, taken from chosen. chosen and rejected are passed through. |
| verl | prompt |
response, which SageMaker AI also appends to prompt as the last assistant turn |
extra_info.reference_answer.text |
| SageMaker Evaluation | system and query |
model_response |
response and reference_answer.text |
Each sample also has an id. In the dataset formats, reference_answer.text holds the reference answer as text, and it is an empty string when the row has none. Other fields of the row, such as metadata, are passed through, so that you can carry test cases or other grading data. If a dataset already ends with an assistant turn in OpenAI chat format, the sample has two trailing assistant messages: the reference answer, and then the response.
Function output
The function returns one result for each sample, with the same id as the sample. Each result has an overall score in aggregate_reward_score, and optionally a list of component scores in metrics_list. Declare each metric name in OutputMetrics so that Evaluation Criteria can refer to it. The following example scores each response by exact match:
def lambda_handler(event, context): results = [] for sample in event: response = sample["model_response"].strip() reference = sample["reference_answer"]["text"].strip() score = 1.0 if response == reference else 0.0 results.append({ "id": sample["id"], "aggregate_reward_score": score, "metrics_list": [ {"name": "exact_match", "value": score, "type": "Metric"} ], }) return results
This example reads the fields of the SageMaker Evaluation format. For other formats, read the fields from the locations in the preceding table. A metric type is Reward or Metric. A metric can also have an optional label and explanation, which appear in the results.
The function can return the list directly, which is recommended. It can also wrap the list in an API Gateway-style response, {"statusCode": 200, "body": "<the list as a JSON string>"}. A status code other than 200 fails the samples in that invocation. SageMaker AI drops their metrics and counts them as failures, and the job continues.
Permissions and retries
The execution role of the job needs lambda:InvokeFunction on the function. If an invocation fails, SageMaker AI retries it with exponential backoff, up to three attempts for each batch. If the retries run out, SageMaker AI stops the job to avoid overloading the function.
Next steps
-
To create Evaluation Criteria that use your Evaluators and set the thresholds for their metrics, see Define Evaluation Criteria.