Lesson 5 of 5 CI/CD and Testing for ML and AI

Testing Prompts and AI Models in CI/CD

This lesson explains AI testing frameworks that combine deterministic checks with scored evaluations, so prompt and model changes can be tested automatically despite variable outputs.

Learning outcomes

After completing this lesson, you will be able to:

  • Build a golden dataset.
  • Combine deterministic checks with scored evaluations.
  • Run prompt tests in the pipeline.

Golden datasets

Testing prompts and models starts with a golden dataset: representative inputs, including edge cases, each with an expected output, a reference answer or a scoring rubric. It is the fixed yardstick against which every candidate prompt or model is measured.

The golden dataset is versioned, so results can be compared over time; it grows as real failures from production are added, so the same mistake cannot return unnoticed; and it is kept separate from any data used for fine-tuning, because a model tested on its own training examples looks better than it is.

True or false

Golden datasets

Exam skills 3.3.9

Check how golden datasets for prompt testing are built and kept.

Log in to try this activity Interactive activities are free with an account.

Kinds of checks

Deterministic checks assert things that must always hold: output parses as JSON and matches a schema, required fields are present, classification labels are from the allowed set, responses stay under a length limit and contain no forbidden strings. Scored checks use metrics (exact match, ROUGE, semantic similarity) or LLM-as-a-judge rubrics for correctness, faithfulness and tone, with thresholds on the average and on failure rates. Safety tests run adversarial prompts for prompt injection, jailbreaks and data leakage, and check that guardrails intervene. Operational checks verify latency and token usage stay within budget.

The following diagram shows a response that broke a downstream JSON parser after a small prompt change, and the check that would have caught it.

How “Be friendly” broke the parser. After the prompt change, 6% of responses began with a sentence before the JSON, so the downstream parser failed although the extracted values were correct. A deterministic schema check on the 300-item golden dataset, plus an assertion that responses begin with {, would have failed the change in the pipeline; a judge-only evaluation would not.
The response text is illustrative.
Match the pairs

Prompt test checks

Exam skills 3.3.9

Match each prompt test with what it protects against.

Log in to try this activity Interactive activities are free with an account.

Running tests in the pipeline

A CodeBuild step or Step Functions workflow runs the golden dataset through the candidate, or starts a Bedrock evaluation job with the dataset and judge metrics, then compares results with the current version. The pipeline fails if scores drop beyond a tolerance, so regressions are caught before release. Low temperature and several runs per test reduce noise. The following table summarises the checks.

CheckExample assertion
FormatValid JSON matching the schema in 100% of cases
CorrectnessJudge correctness score >= 0.85 average
RegressionNo more than 2% drop vs. current version
SafetyAll injection prompts refused or blocked by guardrail
Cost and latencyAverage output tokens <= 300; p95 latency <= 4 s
Worked example

A prompt change that broke parsing

An engineer adds "Be friendly" to an extraction prompt. In production, 6% of responses now start with "Sure! Here is the JSON:", which breaks the downstream parser.

A deterministic schema check on a 300-item golden dataset in the pipeline would have failed the change immediately. The team adds the check, plus an assertion that responses begin with {, and uses a structured output or tool-use schema to constrain the format. A judge-only evaluation would not have caught this, because the extracted values were still correct.

Check yourself

Why include adversarial prompts in a prompt test set?

Show answer

To check resistance to injection and jailbreak attempts.

Exam Tips

Remember for the exam

  • Test prompts and models against a versioned golden dataset.
  • Combine deterministic checks (schema, labels, length) with judge scores.
  • Include adversarial prompts for injection and jailbreak resistance.
  • Fail the pipeline on regressions beyond a tolerance.
  • Add production failures to the golden dataset.