Lesson 3 of 3 Prompt Management and Governance

Regression Testing Prompts Before Release

This lesson describes how to build prompt quality assurance with Lambda, Step Functions and CloudWatch, running automated tests on every change and blocking releases that regress.

Learning outcomes

After completing this lesson, you will be able to:

  • Design property-based prompt tests.
  • Run tests with Lambda and Step Functions.
  • Gate releases on test results.

Designing prompt tests

Model outputs vary from run to run, so prompt tests cannot compare outputs with an exact expected text. Instead, each test case pairs an input with the properties the output must have. Structural checks confirm valid JSON, required fields, allowed labels and maximum length. Content checks confirm, for example, that the answer mentions the policy number, cites a source or refuses a request that is out of scope. Quality checks use an LLM judge's rating or semantic similarity to a reference answer.

The suite covers three kinds of input: typical inputs that represent everyday use; edge cases, such as empty, very long or foreign-language inputs and unusual formats; and adversarial inputs, such as prompt injection attempts. Each failure found in production is added as a new test case.

Select all that apply

Testable properties

Exam skills 1.6.4

Model outputs vary from run to run. Choose the properties that make good automated prompt tests.

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

Running tests with Lambda and Step Functions

A Lambda function runs one test case: it renders the prompt version with the test variables, invokes the model and verifies each expected property, returning pass or fail with details. Step Functions runs the whole suite with a Map state (or a Distributed Map for large suites) with controlled concurrency to stay within quotas, aggregates the results and compares them with the baseline version's results.

Results are published to CloudWatch as metrics per prompt version and test category, such as pass rate and average judge score. Dashboards show trends across versions, and alarms fire when a scheduled run against the production version drops, which catches regressions caused by model updates rather than prompt changes.

The following diagram shows the regression suite running as a gate.

Running a prompt regression suite with Step Functions. A Map state runs one Lambda function per test case with controlled concurrency; each renders the prompt, invokes the model and checks the expected properties. Results are aggregated and compared with the baseline, and the gate passes only if critical tests pass and no category drops beyond the agreed margin.
A Distributed Map state suits large suites.

Gating releases

In the release pipeline, the regression suite runs against the candidate prompt version. A gate passes only if every critical test passes, the overall pass rate is at least the baseline's, and no category drops by more than an agreed margin. Failing candidates are rejected with a report. The same suite runs when the underlying model changes, because a prompt tuned for one model may behave differently on another. The following table summarises the components.

ComponentRole
Test cases with expected propertiesDefine correct behaviour, including edge and adversarial cases
Lambda verifierRuns a case and checks structural, content and quality properties
Step Functions MapRuns the suite at scale with controlled concurrency
CloudWatch metrics and alarmsTrack pass rates per version; detect regressions
Pipeline gateBlocks versions that score below the baseline
Scenario questions

Pass or block the release?

Exam skills 1.6.4 · 5.1.4

Apply a release gate to candidate prompt versions.

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

A model upgrade breaks a prompt

A team switches a prompt to a newer model version. A week later, a downstream system reports that 5% of classifications use a label that does not exist.

A prompt regression suite with a structural check on allowed labels, run as a gate before the model switch and nightly against production with a CloudWatch alarm on pass rate, would have caught it. The fix adds the allowed labels as an enum in a tool schema, and the gate now blocks future regressions.

Check yourself

Why should prompt tests check properties rather than exact text?

Show answer

Model outputs vary in wording, so exact-match tests fail on correct answers. Properties such as format, required facts and refusals are stable.

Exam Tips

Remember for the exam

  • Test expected properties, not exact text.
  • Include edge cases and injection attempts in prompt test suites.
  • Lambda verifies cases; Step Functions Map runs suites; CloudWatch tracks pass rates.
  • Re-run the suite when the model changes, not only when the prompt changes.