Skip to main content
Ai promptsDevops promptsTestingClaude prompts

A Flaky Test Detection Prompt for Your CI Pipeline

Classify a failure as flaky or real from CI history with a flaky test detection prompt that emits a quarantine decision. Copy the output contract today.

PPromptsCart Team·June 17, 2026·Updated June 17, 2026·6 min read

A test goes red, you re-run it, it goes green, and you merge. That reflex is how flaky tests survive for months while quietly training the team to ignore the pipeline. A flaky test detection prompt breaks the reflex: feed it the failure history, and it tells you whether this is noise or a real regression hiding behind intermittent behavior.

The signal isn't in a single failed run. It's in the pattern. A test that fails one run in five with no code change is flaky. A test that started failing after a specific commit is a regression wearing a flake costume. The prompt reads history, classifies, and hands you a quarantine decision with a structured contract you can route to a tracker.

The write-ups that rank here are in-house tooling stories from large engineering orgs. Impressive, and useless if you don't have their infrastructure. None hand you a copyable prompt. That's the gap.

What you can hand the detector

A flaky test detection prompt is a reusable instruction that takes failure history plus a failing log and returns a classification with a quarantine decision. History is the input that makes it accurate. The contract makes the output actionable.

Useful inputs:

  • A pass/fail history table for one test across recent CI runs
  • The failing log alongside a known-good run of the same test
  • A suite where three tests fail intermittently and you can't tell which are real
  • A test that only fails when run in parallel with others
  • A failure that correlates with a specific runner or time of day

The job each shares: separate nondeterministic noise from a genuine break, then decide what to do about it. That decision is worth packaging.

Anatomy: history in, quarantine call out

The prompt frames the model as a test-reliability engineer, takes the history and log in variables, and locks the output to a classification plus a decision.

Variables
  {{failure_history}}  — recent pass/fail runs for this test
  {{failing_log}}      — the failure output
  {{recent_changes}}   — commits touching this test or its deps

Prompt
  Role: You are triaging test reliability for the CI pipeline.
  Task: Use {{failure_history}} to decide if this is flaky or
        a real regression. Rank likely root causes. Decide
        quarantine vs fix.

Output contract
  classification:  flaky | real_regression | inconclusive
  root_causes:     ranked hypotheses (timing race, shared state,
                   order dependency, resource limit)
  decision:        quarantine | fix_now | gather_more_data
  rationale:       tied to the history pattern

The inconclusive and gather_more_data options matter. A prompt forced to pick flaky-or-real on thin evidence guesses. Giving it an honest "not enough signal yet" exit produces better calls than false confidence.

History beats a single log

The single biggest accuracy lever is {{failure_history}}. One failing log tells the model almost nothing about determinism. A table showing this test failed 3 of the last 20 runs with no relevant code change is a near-certain flake signal. Feed the pattern, not just the snapshot.

Step-by-step: from red test to decision

1. Pull the failure history

Most CI systems expose per-test history or you can grep recent runs. A simple run/result table is enough.

2. Add the failing log and recent changes

{{failing_log}} gives the model the error shape; {{recent_changes}} lets it rule out a regression.

3. Run and read the classification

flaky, real_regression, or inconclusive. Trust inconclusive — it's the model declining to guess.

4. Act on the decision

quarantine means skip-and-track so it stops blocking. fix_now means the flake hides a real bug. gather_more_data means run it 20 more times first.

5. Track the quarantine

A quarantined test that's never tracked becomes a permanently dead test. Open an issue when you quarantine.

Patterns that keep classification honest

Demand the history pattern in the rationale. Force the model to tie its call to the actual pass/fail sequence. A rationale that references "3 failures in 20 runs, no code change" is checkable. One that says "this looks flaky" isn't.

Rank root causes, don't pick one. Flakiness usually has competing causes — a timing race and shared state can both be live. Ranked hypotheses point your investigation; a single guess sends you down one hole.

Quarantine is a decision, not a default. Make the model justify quarantine versus fix. Quarantining a test that hides a real concurrency bug ships the bug. The decision field forces that consideration.

Variables you'll set

VariableRequiredWhat it is
{{failure_history}}YesRecent pass/fail runs for the test
{{failing_log}}YesThe failure output to classify
{{recent_changes}}NoCommits touching the test or its dependencies

An opinion worth holding

Auto-retrying a failing test until it passes is the worst flaky-test "strategy" there is, and it's everywhere. It doesn't fix flakiness; it hides it and ships whatever real bug the flake was masking. Quarantine-and-track is the honest move: pull the unreliable test out of the blocking path, but open an issue so someone actually root-causes it. A retry loop with no tracking is just deciding to be wrong intermittently and never find out.

Getting started

  1. Copy the anatomy into your model of choice.
  2. Pull a pass/fail history for one suspected-flaky test.
  3. Add the failing log and any recent relevant commits.
  4. Check whether the classification matches your gut, then trust the evidence over the gut.
  5. Open a tracking issue every time you quarantine.
  6. Re-run the prompt after a fix to confirm the test stabilized.

To run this across the whole pipeline automatically, the Flaky Test Detection Harness Agent Pack surfaces nondeterministic failures from CI history, ranks root-cause hypotheses, and creates tracked fix issues in Jira.

Browse the testing prompt packs
Skip the setup

The Flaky Test Detection Harness Agent Pack does this end-to-end: it returns structured root-cause hypotheses ranked by likelihood plus a quarantine-versus-fix recommendation, then automatically creates and assigns tracked fix issues in Jira so nothing falls through. It's part of The Complete AI Prompts Bundle, a one-time lifetime license to the whole catalog plus every pack added later, worth it if flaky tests block more than one repo.

Get the Flaky Test Detection Harness Agent Pack

When a flake turns out to be a real failure, route it through the CI Failure Diagnosis Harness Agent Pack to get the file-specific fix. For more on packaging reusable prompts, read how to choose a reusable AI prompt pack and the companion CI failure diagnosis prompt from pipeline logs.

FAQ

Common questions

What is a flaky test detection prompt?
It's a reusable prompt that reads test-failure history and the failing log, then classifies a failure as flaky or a real regression and recommends quarantine or fix. The output contract keeps the decision structured — classification, root-cause hypothesis, and a quarantine call — so you can act on it without re-reading the logs.
Can a prompt tell a flaky test from a real failure?
From a single run, only weakly. Give it failure history — how often this test failed across recent runs without a code change — and the model classifies far more reliably. Claude reasons over a pass/fail history table well when it's the last thing in the prompt; restate the columns for GPT-4o.
What does the prompt recommend for a flaky test?
A quarantine-versus-fix call with rationale. Quarantine when the test blocks unrelated PRs and the root cause needs investigation; fix immediately when the flake hides a real timing bug. The prompt ranks root-cause hypotheses so you know where to look first.
Stop reading. Start shipping.

Get the prompt packs this guide is built on

Ready-to-paste prompts with documented variables and worked examples for ChatGPT, Claude, and Gemini. One-time payment, own it forever.