Inferensys

Prompt

Regression Test Flakiness Analysis Prompt

A practical prompt playbook for using the Regression Test Flakiness Analysis Prompt to diagnose non-deterministic failures in AI evaluation pipelines.
AI evaluator reviewing output quality on laptop, comparison metrics visible, casual evaluation session.
PROMPT PLAYBOOK

When to Use This Prompt

Diagnose why the same LLM evaluation test case produces inconsistent pass/fail results across runs, even when the prompt and model version haven't changed.

This prompt is built for infrastructure and QA teams who run the same LLM evaluation suite repeatedly and get inconsistent pass/fail results. The core job-to-be-done is differential diagnosis: you have multiple run logs for the same test cases, you know the prompt and model version are identical, yet results flip between passes and failures. The prompt analyzes these run logs and attributes flakiness to a specific root cause—temperature sensitivity, model non-determinism, ambiguous evaluation criteria, or input instability—rather than leaving you to guess.

Use this prompt when you can provide at least two complete run logs for the same test case, including the input, the model output, the evaluation rubric applied, and the resulting score or pass/fail judgment. The prompt requires structured evidence: run IDs, timestamps, model configuration (especially temperature and seed settings), and the exact evaluation criteria used. It works best when flakiness is reproducible enough that you have multiple examples of the same test case flipping. Do not use this prompt for single-run test failures, for debugging prompt logic errors where the output is consistently wrong, or for cases where the model version or prompt text actually changed between runs—those are regression bugs, not flakiness.

The output is a structured root cause attribution with supporting evidence from your logs. Expect a classification into one of four categories: temperature sensitivity (the model samples different tokens at non-zero temperature), model non-determinism (the model produces different outputs even at temperature zero due to infrastructure-level variation), ambiguous evaluation criteria (the rubric or pass/fail rule is too vague to produce consistent judgments), or input instability (the test input itself contains dynamic elements like timestamps or random seeds). Each attribution includes the specific evidence from your run logs that supports the diagnosis and a recommended remediation—such as setting temperature to zero, tightening rubric language, or stabilizing test inputs. Before acting on the diagnosis, validate it by running the suggested remediation on a subset of flaky cases and confirming the flakiness rate drops. If the prompt cannot confidently attribute the flakiness to a single cause, it will tell you that too, which is a signal that you need more run logs or a deeper investigation outside the scope of automated analysis.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Regression Test Flakiness Analysis Prompt delivers value and where it introduces risk. Use these cards to decide whether this prompt fits your pipeline before investing in integration.

01

Good Fit: Repeated CI Runs with Inconsistent Results

Use when: you have 3+ runs of the same test suite against the same prompt version, and pass/fail status varies across runs. Guardrail: feed the prompt a structured log of per-case outcomes across runs, not raw trace files. The prompt needs outcome-level data to attribute flakiness to temperature, non-determinism, or evaluation ambiguity.

02

Bad Fit: Single-Run Failures or First-Time Errors

Avoid when: you only have one test run or are debugging a brand-new failure. This prompt requires repeated observations to distinguish flakiness from deterministic bugs. Guardrail: use a root-cause classification prompt for single-run failures first, then apply flakiness analysis only after confirming non-determinism across multiple runs.

03

Required Input: Structured Per-Case Outcome Matrix

What to watch: the prompt needs run-level pass/fail labels per test case, not raw model outputs or logs. Ambiguous input produces unreliable attributions. Guardrail: pre-process test results into a table with columns for test case ID, run number, and binary outcome before calling the prompt. Include temperature and model version metadata per run.

04

Operational Risk: Masking Systemic Evaluation Flaws

What to watch: the prompt may attribute flakiness to model non-determinism when the real cause is an ambiguous rubric or inconsistent LLM judge. Guardrail: run judge calibration checks before flakiness analysis. If the judge itself produces inconsistent scores on identical inputs, fix the evaluation pipeline first—flakiness attribution will be misleading otherwise.

05

Bad Fit: Tests with Known Environmental Variability

Avoid when: flakiness is caused by external factors such as network timeouts, retry storms, or infrastructure contention rather than model behavior. Guardrail: filter out infrastructure-related failures before analysis. The prompt should only receive failures attributable to model output variation, not CI environment instability.

06

Required Input: Evaluation Criteria Metadata

What to watch: without knowing which evaluation criteria were used per test case, the prompt cannot distinguish ambiguous criteria from genuine model non-determinism. Guardrail: include a mapping of test case to evaluation type (exact match, semantic equivalence, rubric score) so the prompt can attribute flakiness to criteria ambiguity when appropriate.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A copy-ready prompt for analyzing flaky test cases across repeated runs and attributing non-determinism to temperature, model behavior, or evaluation ambiguity.

This prompt template is designed to be pasted directly into your evaluation harness or LLM workbench. It expects a structured input containing repeated test run results, the evaluation criteria used, and the model configuration. Replace every square-bracket placeholder with your actual data before execution. The prompt instructs the model to identify which test cases are flaky, categorize the likely root cause, and recommend specific remediation steps—such as lowering temperature, rewriting evaluation rubrics, or adding explicit constraints.

text
You are a test reliability engineer analyzing non-deterministic failures in an AI evaluation pipeline.

You will receive a set of test cases that were executed multiple times against the same prompt and model. Some test cases passed inconsistently across runs. Your job is to identify which test cases are flaky, determine the most likely cause of flakiness, and recommend a concrete fix.

## INPUT

[TEST_RUN_DATA]

## EVALUATION CRITERIA USED

[EVALUATION_CRITERIA]

## MODEL CONFIGURATION

[MODEL_CONFIG]

## INSTRUCTIONS

1. Identify every test case where the pass/fail result changed across runs. These are the flaky cases.
2. For each flaky case, classify the root cause into exactly one of the following categories:
   - **TEMPERATURE_SENSITIVITY**: The output varies significantly with sampling, suggesting the prompt allows multiple valid but semantically different responses that the evaluator treats inconsistently.
   - **MODEL_NON_DETERMINISM**: The model produces different outputs even at temperature=0, indicating infrastructure-level non-determinism or model-side variability.
   - **AMBIGUOUS_EVALUATION_CRITERIA**: The evaluation rubric or pass/fail criteria are too vague, allowing the same output to be scored differently across runs.
   - **BORDERLINE_CASE**: The test case sits exactly on the decision boundary, where tiny output variations flip the result.
   - **CONTEXT_WINDOW_TRUNCATION**: Long inputs or outputs are truncated inconsistently, changing what the evaluator sees.
3. For each flaky case, provide:
   - The test case identifier
   - The root cause category
   - A one-sentence evidence statement quoting the specific output variation or scoring inconsistency
   - A concrete, actionable remediation recommendation
4. Produce a summary table with counts per root cause category.
5. Rank the flaky cases by severity, where severity is defined as:
   - **HIGH**: Flakiness occurs in more than 50% of runs
   - **MEDIUM**: Flakiness occurs in 20-50% of runs
   - **LOW**: Flakiness occurs in less than 20% of runs

## OUTPUT FORMAT

Return a JSON object with this exact schema:

{
  "total_test_cases": <integer>,
  "total_runs_per_case": <integer>,
  "flaky_cases": [
    {
      "test_case_id": "<string>",
      "pass_rate": <float between 0 and 1>,
      "root_cause": "TEMPERATURE_SENSITIVITY | MODEL_NON_DETERMINISM | AMBIGUOUS_EVALUATION_CRITERIA | BORDERLINE_CASE | CONTEXT_WINDOW_TRUNCATION",
      "evidence": "<one sentence quoting the variation>",
      "severity": "HIGH | MEDIUM | LOW",
      "recommendation": "<concrete, actionable fix>"
    }
  ],
  "summary_by_cause": {
    "TEMPERATURE_SENSITIVITY": <count>,
    "MODEL_NON_DETERMINISM": <count>,
    "AMBIGUOUS_EVALUATION_CRITERIA": <count>,
    "BORDERLINE_CASE": <count>,
    "CONTEXT_WINDOW_TRUNCATION": <count>
  },
  "overall_assessment": "<2-3 sentence summary of flakiness health and top priority fix>"
}

## CONSTRAINTS

- Do not invent test cases not present in the input.
- If a test case passed consistently, do not include it in flaky_cases.
- If you cannot determine the root cause with confidence, use AMBIGUOUS_EVALUATION_CRITERIA as the default and note the uncertainty.
- Recommendations must be specific: name the exact parameter to change, the rubric line to rewrite, or the infrastructure check to perform.

Adapting the template: Replace [TEST_RUN_DATA] with a structured array of test cases, each containing an identifier, the input, the output from each run, and the pass/fail result per run. [EVALUATION_CRITERIA] should contain the exact rubric, pass/fail rules, or scoring function used by your judge. [MODEL_CONFIG] must include the model name, temperature setting, top_p, and any seed or infrastructure details. If your test harness doesn't capture per-run outputs, you'll need to add output logging before this prompt becomes useful—without output-level evidence, root cause classification degrades to guesswork.

Validation and safety: The output JSON must be validated against the schema before ingestion into your CI/CD pipeline. If the model returns malformed JSON, retry with a stricter schema reminder or use a repair prompt from the Output Repair and Validation Prompts pillar. This analysis is diagnostic, not autonomous—remediation recommendations should be reviewed by a human before changing evaluation thresholds, model parameters, or test definitions. For production pipelines, store the flakiness report alongside your regression run artifacts so you can track whether flakiness is increasing over time.

IMPLEMENTATION TABLE

Prompt Variables

Every placeholder the Regression Test Flakiness Analysis Prompt expects, why it matters, and how to validate it before sending. Use this table to wire the prompt into your evaluation harness.

PlaceholderPurposeExampleValidation Notes

[TEST_RUN_LOG]

Raw test execution output from multiple runs of the same test suite, including pass/fail status, timestamps, and run IDs

Run 1: test_login.py::test_oauth_redirect FAILED (AssertionError) Run 2: test_login.py::test_oauth_redirect PASSED Run 3: test_login.py::test_oauth_redirect FAILED (TimeoutError)

Must contain at least 3 runs of the same test case. Parse check: verify run count per test case. Reject if fewer than 3 runs or if all runs have identical outcomes.

[TEST_SUITE_NAME]

Identifier for the test suite under analysis, used to scope the flakiness report and prevent cross-suite contamination

auth_integration_suite_v2

Must be a non-empty string. Validate against known suite registry if available. Null not allowed. Used for report labeling and traceability.

[MODEL_IDENTIFIER]

The model or endpoint that produced the test outputs, required to attribute flakiness to model non-determinism versus evaluation ambiguity

gpt-4o-2024-08-06

Must match a known model identifier from your deployment registry. Parse check: non-empty string. Used to correlate flakiness patterns with model version changes.

[TEMPERATURE_SETTING]

The temperature parameter used during test execution, critical for diagnosing temperature-sensitive flakiness

0.7

Must be a float between 0.0 and 2.0. Parse check: numeric range validation. Null allowed only if model does not support temperature. Compare against actual inference config.

[EVALUATION_CRITERIA]

The rubric, scoring function, or pass/fail rule applied to each test case, required to detect ambiguous evaluation as a flakiness source

Output must contain a valid JSON object with 'status' field equal to 'approved' and 'confidence' >= 0.8

Must be a non-empty string describing the evaluation contract. Schema check: verify criteria are deterministic where possible. Flag if criteria contain subjective language like 'reasonable' or 'good'.

[RUN_METADATA]

Optional per-run context such as seed values, latency, token counts, or infrastructure details that may correlate with flaky outcomes

{"run_1": {"seed": 42, "latency_ms": 1200}, "run_2": {"seed": 99, "latency_ms": 3400}}

Must be valid JSON if provided. Null allowed. Parse check: validate JSON structure. If seeds are present, verify they differ across runs to confirm non-determinism testing is intentional.

[FLAKINESS_THRESHOLD]

The minimum inconsistency rate required to flag a test as flaky, expressed as a float between 0.0 and 1.0

0.3

Must be a float between 0.0 and 1.0. Default 0.2 if not specified. Parse check: numeric range validation. Lower thresholds increase sensitivity; higher thresholds reduce false positives.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the flakiness analysis prompt into an evaluation pipeline or CI/CD workflow.

This prompt is designed to run as a post-execution analysis step in a regression testing pipeline, not as a real-time classifier. After your test runner produces a results file with repeated runs per test case, feed the aggregated results into this prompt to identify flaky tests and attribute the flakiness to temperature sensitivity, model non-determinism, or ambiguous evaluation criteria. The prompt expects structured input—typically a JSON array of test cases with their run histories—so your harness must collect and format that data before invocation.

Wire the prompt into your CI/CD workflow as a conditional analysis job that triggers when the overall pass rate falls below a threshold or when individual test cases show inconsistent results across runs. Use a model with low temperature (0.0–0.1) for the analysis itself to maximize reproducibility of the flakiness diagnosis. Implement a validation layer that checks the output schema before accepting the analysis: each identified flaky test must include a test_id, flakiness_score (0.0–1.0), attributed_cause from the allowed enum (temperature_sensitivity, model_non_determinism, ambiguous_criteria, unknown), and evidence referencing specific run outcomes. Reject and retry outputs that don't conform to this schema, or that attribute flakiness without citing concrete run data.

Log every analysis invocation with the input run data, the raw model output, the validated result, and the model version used. This trace is essential for diagnosing when the flakiness analyzer itself becomes unreliable. For high-stakes pipelines where flaky tests could mask real regressions, route analyses with flakiness_score > 0.7 or attributed_cause: unknown to a human reviewer before accepting the diagnosis. Avoid running this prompt on single-run test results—it needs repeated runs to distinguish flakiness from consistent failure. If your test infrastructure can't support multiple runs per commit, consider running this analysis weekly against a dedicated flakiness detection suite that does.

IMPLEMENTATION TABLE

Expected Output Contract

Fields, types, and validation rules for the JSON response returned by the Regression Test Flakiness Analysis Prompt. Use this contract to parse, validate, and route the output in your evaluation pipeline.

Field or ElementType or FormatRequiredValidation Rule

flaky_tests

array of objects

Must be present and non-null. If no flaky tests are found, return an empty array.

flaky_tests[].test_id

string

Must match the [TEST_ID] format from the input run log. Non-empty. Regex: ^[A-Za-z0-9_-.]+$

flaky_tests[].flakiness_score

number

Float between 0.0 and 1.0 inclusive. 1.0 means failed on every non-deterministic run. Parse as float and clamp to range.

flaky_tests[].attribution

object

Must contain at least one key from the enum: temperature_sensitivity, model_non_determinism, ambiguous_evaluation_criteria, input_ordering_sensitivity, timeout_race_condition, unknown

flaky_tests[].attribution.primary_cause

string (enum)

Must be one of: temperature_sensitivity, model_non_determinism, ambiguous_evaluation_criteria, input_ordering_sensitivity, timeout_race_condition, unknown. Reject any other value.

flaky_tests[].attribution.confidence

number

Float between 0.0 and 1.0. Represents the model's confidence in the primary cause attribution. Values below 0.5 should trigger human review.

flaky_tests[].evidence

array of strings

At least one concrete observation from the run log supporting the attribution. Each string must be non-empty and under 500 characters. Null or empty array is a validation failure.

analysis_summary

string

A concise paragraph (max 500 characters) summarizing the flakiness findings. Must not be null or empty. If no flaky tests found, state that explicitly.

PRACTICAL GUARDRAILS

Common Failure Modes

Flakiness analysis prompts fail in predictable ways. Here are the most common failure modes and how to guard against them before they corrupt your regression pipeline.

01

Attributing Flakiness to the Wrong Source

What to watch: The prompt blames model non-determinism when the real cause is ambiguous evaluation criteria or temperature sensitivity. This misdirects the engineering team toward model-level fixes when the rubric or test harness is broken. Guardrail: Require the prompt to output a structured differential diagnosis with evidence for each possible cause before concluding. Include a mandatory alternative_explanations field in the output schema.

02

Overfitting to a Single Run Pair

What to watch: The prompt analyzes only two runs and declares flakiness based on a single divergence. True non-determinism requires multiple observations to separate signal from noise. Guardrail: Enforce a minimum of 5 runs per test case before classification. Add a confidence field that degrades when sample size is insufficient, and reject analyses with fewer than the minimum runs.

03

Confusing Format Drift with Semantic Failure

What to watch: The prompt flags outputs as flaky when they differ only in formatting, whitespace, or key ordering while preserving semantic equivalence. This inflates flakiness counts and wastes triage time. Guardrail: Add a pre-processing step that normalizes outputs before comparison, or include explicit instructions to distinguish format-only variance from meaningful output divergence in the analysis.

04

Missing the Evaluation Rubric Itself as the Flakiness Source

What to watch: The prompt analyzes test case flakiness but never questions whether the LLM judge or scoring rubric is the unstable component. An inconsistent judge produces flaky scores even when model outputs are stable. Guardrail: Include a cross-check step where the same output is scored multiple times by the judge. If judge scores vary, flag the rubric as a potential flakiness source before blaming the system under test.

05

Producing Unactionable Flakiness Reports

What to watch: The prompt generates vague conclusions like 'this test is flaky' without specifying what changed between runs, which assertion failed, or what remediation is needed. The report gets ignored. Guardrail: Require the output to include a per-case failure_signature that captures the exact divergence pattern, a remediation_hint field with concrete next steps, and a severity rating to prioritize fixes.

06

Ignoring Input Sensitivity as a Confounding Variable

What to watch: The prompt treats all test inputs as equally stable and misses that flakiness clusters around specific input patterns such as ambiguous phrasing, boundary values, or long contexts. Guardrail: Instruct the prompt to segment flakiness rates by input characteristics and report input-pattern clusters. Add a suspected_input_triggers field that identifies which input features correlate with non-deterministic behavior.

IMPLEMENTATION TABLE

Evaluation Rubric

Criteria for evaluating the quality of the flakiness analysis output before relying on it in your CI pipeline. Each row defines a pass standard, a failure signal, and a test method that can be automated or reviewed manually.

CriterionPass StandardFailure SignalTest Method

Flaky Test Identification

Output correctly identifies at least 90% of known flaky tests from the provided [TEST_RUN_HISTORY]

Misses known flaky tests or flags stable tests as flaky with >10% error rate

Compare output list against a pre-labeled golden set of flaky and stable tests

Root Cause Attribution

Each flaky test has exactly one primary root cause from the allowed enum: temperature_sensitivity, model_non_determinism, ambiguous_evaluation, or environmental

Root cause is missing, uses a value outside the allowed enum, or assigns multiple primary causes to a single test

Parse output and validate each root cause field against the allowed enum using a schema check

Evidence Grounding

Every root cause claim includes at least one specific reference to a [TEST_RUN_ID] and [FAILURE_PATTERN] from the input data

Root cause claims lack supporting evidence or cite run IDs not present in the input

Extract all referenced run IDs and verify each exists in the provided [TEST_RUN_HISTORY]

Confidence Score Validity

All confidence scores are floats between 0.0 and 1.0, with values above 0.7 only when supported by 3+ failure occurrences

Confidence scores outside 0.0-1.0 range, or high confidence assigned to single-occurrence failures

Parse all confidence values, check range, and cross-reference with failure count per test

Output Schema Compliance

Output is valid JSON matching the [OUTPUT_SCHEMA] with all required fields present and no extra top-level keys

JSON parse error, missing required fields such as flaky_tests or summary, or presence of undefined keys

Validate output against the JSON schema using a programmatic validator before any downstream consumption

Non-Determinism Explanation

For tests attributed to model_non_determinism, output explains the specific output variation observed across runs

Generic statements like 'model is non-deterministic' without describing what changed between runs

Check that every model_non_determinism entry has a non-empty output_variation field with concrete differences

Ambiguous Criteria Detection

For tests attributed to ambiguous_evaluation, output quotes the specific evaluation instruction or rubric clause causing ambiguity

Vague claims of ambiguity without pinpointing the exact evaluation text responsible

Verify that ambiguous_evaluation entries contain a non-empty ambiguous_criteria_excerpt field sourced from the evaluation prompt

Actionable Recommendation

Each flaky test includes a recommendation from the allowed set: adjust_temperature, pin_seed, rewrite_evaluation, quarantine_test, or escalate_to_human

Recommendation is missing, generic, or suggests an action outside the allowed set

Parse recommendations and validate against the allowed action enum; flag any test missing a recommendation

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with a single model and a small set of repeated test runs (5-10). Focus on detecting obvious flakiness patterns without heavy infrastructure. Replace [MODEL_NAME] with your target model and [TEST_SUITE_PATH] with a local file path. Run the analysis as a one-shot script rather than a scheduled job.

Watch for

  • Small sample sizes producing false negatives (flaky tests look stable by chance)
  • No baseline comparison—you won't know if flakiness is new or pre-existing
  • Missing temperature and seed logging makes root cause attribution unreliable
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.