Measuring and Evaluating Prompt Effectiveness with Claude: A Complete Guide

The anthropics/prompt-eng-interactive-tutorial repository provides three reproducible grading strategies—code-based, human, and model-based—to systematically measure Claude's output quality using AWS Bedrock or the Anthropic SDK.

Measuring and evaluating prompt effectiveness with Claude requires more than manual spot-checking; it demands automated, reproducible methodologies that can scale across CI pipelines and research workflows. The prompt-eng-interactive-tutorial repository from Anthropic delivers exactly that—a modular collection of Jupyter notebooks and Python utilities that demonstrate how to craft prompts and assess their performance using empirical evaluation techniques.

Understanding the Evaluation Framework in the Prompt Engineering Tutorial

The repository structures its evaluation logic into three distinct grading paradigms, each suited to different validation requirements and automation levels. These strategies are implemented in the empirical performance notebooks located in both the AmazonBedrock/boto3/ and AmazonBedrock/anthropic/ directories.

Code-Based Grading for Automated Validation

Code-based grading programmatically compares Claude’s response against a ground-truth label using deterministic string matching or regular expressions. This method is ideal for classification tasks—such as sentiment analysis or entity extraction—where outputs follow predictable patterns. In AmazonBedrock/boto3/10_3_Appendix_Empirical_Performance_Eval.ipynb, this approach uses Python assertions to validate that Claude’s completion matches expected values, enabling full automation in regression testing.

Human Grading for Nuanced Assessment

Human grading reserves a placeholder for manual review when automated parsing is insufficient. This strategy applies to open-ended generation tasks—such as creative writing or complex reasoning—where subjective judgment determines quality. The notebook implements this as a structured review step within the evaluation pipeline, allowing human annotators to score outputs against a rubric before finalizing metrics.

Model-Based Grading Using Self-Evaluation

Model-based grading leverages Claude itself to score its own outputs against a predefined rubric. This technique, also known as LLM-as-a-judge, is useful when ground-truth labels are unavailable but evaluation criteria are well-defined. The empirical performance notebook demonstrates this by sending Claude’s previous completion back to the model with a scoring prompt, requesting a numeric rating or binary assessment of quality.

Implementing Code-Based Evaluation with AWS Bedrock

The repository provides a concrete implementation of code-based grading using the AWS Bedrock runtime. The following snippet mirrors the logic found in AmazonBedrock/boto3/10_3_Appendix_Empirical_Performance_Eval.ipynb, configuring deterministic sampling to ensure reproducible results.

import json, re, boto3

MODEL_NAME = "anthropic.claude-3-haiku-20240307-v1:0"
AWS_REGION = "us-west-2"

bedrock = boto3.client("bedrock-runtime", region_name=AWS_REGION)

def invoke_claude(prompt: str) -> str:
    """Call Claude via Bedrock and return the raw text response."""
    body = {
        "prompt": prompt,
        "max_tokens_to_sample": 256,
        "temperature": 0.0,
        "top_p": 1,
    }
    response = bedrock.invoke_model(
        modelId=MODEL_NAME,
        body=json.dumps(body).encode(),
        contentType="application/json",
        accept="application/json",
    )
    result = json.loads(response["body"].read())
    return result["completion"]

def grade_sentiment(review: str, expected: str) -> bool:
    """Return True if Claude's sentiment matches `expected`."""
    prompt = f"""You are a sentiment analyst. Classify the sentiment of the following movie review as **Positive** or **Negative**.

Review:
\"\"\"{review}\"\"\" 

Answer with only the word Positive or Negative."""
    reply = invoke_claude(prompt)
    # Normalise Claude's answer

    match = re.search(r"(Positive|Negative)", reply, re.IGNORECASE)
    if not match:
        return False
    return match.group(1).lower() == expected.lower()

# Example usage

assert grade_sentiment(
    "I loved the cinematography and the plot twists were fantastic!", "Positive"
)
assert not grade_sentiment(
    "The movie was a total waste of time; the acting was terrible.", "Positive"
)

Setting temperature to 0.0 eliminates randomness, ensuring that identical prompts produce identical completions across evaluation runs. The grade_sentiment function demonstrates how to extract structured labels from unstructured text using regular expressions, a pattern that generalizes to any classification task when measuring and evaluating prompt effectiveness with Claude.

Configuration Files for Reproducible Prompt Evaluation

The repository maintains strict reproducibility through pinned dependencies and infrastructure-as-code. When deploying the evaluation pipeline, reference these specific files to ensure consistent behavior across environments:

  • AmazonBedrock/boto3/10_3_Appendix_Empirical_Performance_Eval.ipynb – The primary notebook demonstrating code-based, human, and model-based grading using the AWS Bedrock boto3 client.

  • AmazonBedrock/anthropic/10_3_Appendix_Empirical_Performance_Evaluations.ipynb – An alternative implementation using the native Anthropic SDK instead of Bedrock, providing identical evaluation logic with different authentication patterns.

  • AmazonBedrock/utils/hints.py – Lightweight utility containing reusable hint strings that illustrate how subtle prompt modifications affect evaluation metrics.

  • AmazonBedrock/cloudformation/workshop-v1-final-cfn.yml – CloudFormation template provisioning IAM roles, Bedrock endpoint access, and secure Lambda invocation layers required for the evaluation environment.

  • AmazonBedrock/requirements.txt – Pinned Python dependencies specifying the exact boto3 version used in the notebooks, ensuring dependency stability across CI pipelines.

Summary

  • The prompt-eng-interactive-tutorial repository provides a modular framework for measuring and evaluating prompt effectiveness with Claude through three distinct strategies: code-based, human, and model-based grading.

  • Code-based evaluation enables full automation for classification tasks by programmatically comparing Claude's outputs against ground-truth labels using deterministic sampling (temperature=0.0).

  • Model-based grading leverages Claude as an evaluator for subjective or open-ended tasks where predefined labels are unavailable, implementing the LLM-as-a-judge pattern.

  • The repository maintains reproducibility through pinned dependencies in requirements.txt, explicit model versioning (anthropic.claude-3-haiku-20240307-v1:0), and infrastructure-as-code templates for consistent deployment across environments.

Frequently Asked Questions

What are the three methods for measuring prompt effectiveness with Claude?

The repository implements code-based grading, which uses string matching or regular expressions to verify outputs against expected labels; human grading, which reserves placeholders for manual review of subjective content; and model-based grading, which prompts Claude to evaluate its own outputs against a rubric. Each method suits different task types, from deterministic classification to open-ended generation.

How do I ensure reproducible results when evaluating Claude prompts?

Set the temperature parameter to 0.0 in your API calls, as demonstrated in AmazonBedrock/boto3/10_3_Appendix_Empirical_Performance_Eval.ipynb. This eliminates randomness in sampling. Additionally, pin your dependencies using the provided requirements.txt and specify exact model versions such as anthropic.claude-3-haiku-20240307-v1:0 to maintain consistent behavior across evaluation runs.

Can I use the Anthropic SDK instead of AWS Bedrock for evaluation?

Yes. While the boto3 implementation targets AWS Bedrock, the repository provides an equivalent notebook at AmazonBedrock/anthropic/10_3_Appendix_Empirical_Performance_Evaluations.ipynb that uses the native Anthropic SDK. Both implementations share identical evaluation logic and grading strategies, differing only in authentication and client initialization patterns.

What is model-based grading and when should I use it?

Model-based grading—also known as LLM-as-a-judge—involves sending Claude's output back to the model along with a scoring rubric to receive a quantitative or qualitative assessment. Use this method when ground-truth labels are unavailable or for subjective tasks like creative writing and complex reasoning where human judgment would otherwise be required. This approach is implemented in the empirical performance notebook as a scalable alternative to manual review.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →