Inferensys

Prompt

Retry and Recovery Scenario Generation Prompt

A practical prompt playbook for using Retry and Recovery Scenario Generation Prompt in production AI workflows.
Developer doing prompt engineering on laptop, prompt variations visible on screen, casual coding session.
PROMPT PLAYBOOK

When to Use This Prompt

Identify the right conditions for converting retry policies and recovery mechanisms into executable Gherkin scenarios.

This prompt is designed for reliability engineers, QA leads, and platform engineers who need to translate defined failure modes and recovery mechanisms into automation-ready acceptance criteria. The core job-to-be-done is taking a known transient failure (like a network timeout, a 503 response, or a throttling event) and a documented recovery strategy (such as exponential backoff, a circuit breaker, or a fallback response) and producing a set of Gherkin scenarios that can be directly executed by a test framework. You should use this prompt when you have a concrete failure mode, a clear recovery mechanism, and a need for verifiable, behavior-driven specifications that can gate a release or validate an SLO.

The ideal input for this prompt is a structured description of the failure, the recovery policy parameters, and the system's expected behavior. For example, you might provide: 'The payment service returns a 503 error. The client retries up to 3 times with exponential backoff starting at 1 second. After 3 failures, the circuit breaker opens for 30 seconds and a cached fallback response is returned.' The prompt will then generate scenarios covering the happy retry path, the exhaustion of retries, the circuit breaker's half-open state, and the fallback response. It will also include boundary conditions like retry budget exhaustion exactly at the limit and recovery signal clarity after the breaker resets. The output is not just a list of scenarios; it includes tags for test automation, example data tables, and explicit assertions for timeout boundaries and state transitions.

Do not use this prompt for general error message testing, performance tuning, or user-facing copy review. Those workflows require different inputs and produce different outputs. This prompt is also not a substitute for a full chaos engineering plan; it focuses on the deterministic behavior of a single component's recovery logic, not on emergent system-wide failures. Before using this prompt, ensure you have a written retry policy, backoff configuration, or circuit breaker specification. If you are still exploring what the recovery behavior should be, start with the 'Error Handling Behavior Specification Prompt' or the 'Ambiguous Requirement Clarification Prompt' to define the policy first. Once the policy is stable, return here to generate the executable scenarios that will validate it in your CI/CD pipeline.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Retry and Recovery Scenario Generation Prompt delivers value and where it introduces risk. Use these cards to decide if this prompt fits your current workflow and system maturity.

01

Good Fit: Distributed System Reliability Testing

Use when: You are designing resilience tests for microservices, message queues, or API gateways that must handle transient network failures. Guardrail: Ensure the prompt receives concrete timeout values, retry budgets, and circuit-breaker thresholds from your SLA documents to prevent vague scenario generation.

02

Bad Fit: Deterministic Transactional Guarantees

Avoid when: You need to verify strict ACID compliance, financial ledger integrity, or atomicity across distributed transactions. Guardrail: This prompt focuses on recovery behavior, not formal proof of consistency. Pair with idempotency and race-condition prompts for full coverage.

03

Required Input: Operational Runbooks and SLAs

What to watch: The prompt produces generic retry scenarios if only given a feature description. Guardrail: Always supply explicit retry policies, backoff strategies, timeout budgets, and fallback response schemas. The output quality is directly proportional to the specificity of your operational constraints.

04

Operational Risk: Over-Specifying Recovery Paths

What to watch: The model may generate exhaustive recovery scenarios that are impractical to implement or test within your release cycle. Guardrail: Prioritize scenarios by failure probability and blast radius. Use the prompt's output as a catalog to triage, not a mandatory test suite.

05

Integration Risk: Environment Drift

What to watch: Generated Gherkin scenarios may assume network topologies, service meshes, or retry middleware that differ from your actual infrastructure. Guardrail: Validate all generated preconditions against your environment configuration. Add a manual review step for infrastructure-dependent assumptions before automation.

06

Coverage Gap: Silent Failures and Observability

What to watch: The prompt may focus on retry mechanics while neglecting observability signals like log emission, metric increments, and alert triggering during recovery. Guardrail: Explicitly request scenarios that validate error logs, trace spans, and monitoring alerts as part of the expected behavior, not just the functional response.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A copy-ready prompt for generating Gherkin scenarios that validate system retry, recovery, and graceful degradation behavior.

This prompt template is designed to produce executable Gherkin scenarios for transient failure and recovery paths. It forces the model to reason about retry policies, backoff strategies, circuit breaker states, fallback responses, and recovery signals. Use it when you have a defined system boundary, a known set of dependencies, and a clear recovery policy to validate. Do not use it for generic error handling or for systems where the failure modes are not yet understood.

text
You are a reliability test engineer. Your task is to generate Gherkin scenarios that validate system behavior during transient failures and recovery.

## System Under Test
[SYSTEM_DESCRIPTION]

## Dependencies and Failure Points
[DEPENDENCY_LIST]

## Retry and Recovery Policies
[POLICY_DESCRIPTION]

## Constraints
- Generate scenarios only for transient and recoverable failures. Do not generate scenarios for permanent failures unless they trigger a defined fallback.
- Each scenario must include explicit timeout boundaries, retry counts, and backoff expectations.
- Use concrete, verifiable assertions for recovery signals (e.g., log entries, metrics, response fields).
- Tag each scenario with the failure mode it covers (e.g., @timeout, @circuit_open, @max_retry_exhausted).
- If a policy is undefined for a failure mode, generate a scenario tagged @policy_gap.

## Output Schema
Return a JSON object with a single key "scenarios" containing an array of objects. Each object must have:
- "name": A concise scenario title.
- "tags": An array of strings representing failure mode tags.
- "feature": The feature or component under test.
- "scenario": The Gherkin text block.
- "recovery_signal": A description of how to verify the system recovered correctly.

## Examples
[FEW_SHOT_EXAMPLES]

Generate scenarios for the system and policies described above.

To adapt this prompt, replace the square-bracket placeholders with your specific context. [SYSTEM_DESCRIPTION] should detail the component, its API, and its operational boundaries. [DEPENDENCY_LIST] must enumerate every external service, database, or queue the system relies on. [POLICY_DESCRIPTION] is the most critical input: specify exact retry counts, backoff algorithms (e.g., exponential with jitter), circuit breaker thresholds, and fallback responses. Provide [FEW_SHOT_EXAMPLES] that match your expected output format and domain language to improve reliability. After generation, validate that every scenario has a concrete, measurable recovery signal and that no undefined failure modes are left untagged.

IMPLEMENTATION TABLE

Prompt Variables

Inputs the Retry and Recovery Scenario Generation Prompt needs to produce reliable Gherkin scenarios. Validate each input before execution to prevent ambiguous or untestable outputs.

PlaceholderPurposeExampleValidation Notes

[SYSTEM_SPEC]

Describes the target system's retry mechanism, circuit breaker, or fallback behavior

Payment Service uses exponential backoff with a max of 3 retries and a dead-letter queue for terminal failures

Check for presence of retry policy details, timeout values, and backoff strategy. Reject if only generic 'system retries on failure' is provided

[FAILURE_MODE]

Specifies the transient failure condition to model

Database connection timeout after 30 seconds; upstream 503 Service Unavailable

Must be a specific, transient error condition. Reject permanent failures like 'invalid credentials' unless they are part of a retry-exhaustion scenario

[RECOVERY_SIGNAL]

Defines what indicates successful recovery or graceful degradation

Fallback to read-replica within 2 seconds; return cached response with stale-while-revalidate header

Must be a measurable, observable outcome. Reject vague signals like 'system works again'

[TIMEOUT_BOUNDARY]

Sets the maximum time before a retry attempt is abandoned

5000ms per attempt; 30 seconds total for the operation

Must be a numeric value with units. Validate that the boundary is shorter than any upstream caller timeout to avoid false positives

[MAX_RETRY_EXHAUSTION]

Defines the behavior when all retries are exhausted

Return HTTP 503 with a Retry-After header; publish to dead-letter topic 'payment-failures'

Must describe a terminal state. Reject if the description implies infinite retry or undefined behavior

[CIRCUIT_BREAKER_STATE]

Specifies the circuit breaker configuration and state transitions

Circuit opens after 5 failures in 60 seconds; half-open after 30 seconds with 1 probe request

Check for threshold values, time windows, and state transition rules. Reject if only 'circuit breaker enabled' without parameters

[FALLBACK_RESPONSE]

Describes the degraded response when the primary path fails

Return empty result set with metadata 'source: cache, freshness: degraded'

Must be a valid, non-exceptional response. Reject fallbacks that throw errors or return null without explicit null-handling documentation

[CONCURRENCY_MODEL]

Specifies how concurrent requests interact with retry and recovery

Idempotency key required; duplicate requests within 5-minute window return cached result

Check for idempotency guarantees, locking behavior, or optimistic concurrency controls. Reject if concurrent behavior is undefined for a stateful operation

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the retry and recovery scenario generation prompt into a reliability testing workflow with validation, tool integration, and human review gates.

This prompt is designed to be called programmatically from a test planning pipeline or a QA chatbot interface. The primary input is a structured specification of a system component, its failure modes, and its expected recovery behavior. The output is a set of Gherkin scenarios that must be validated before they are committed to a test repository. Because the generated scenarios directly influence reliability testing, the implementation harness must enforce schema validation, retry logic, and a human review step for any scenario that introduces a new retry policy or circuit breaker state.

To wire this into an application, wrap the prompt in a function that accepts a [COMPONENT_SPEC] object containing the service name, its dependencies, timeout configurations, and known failure modes. The function should call the LLM with the prompt template, then parse the response into a structured object matching the [OUTPUT_SCHEMA]—a list of Gherkin scenarios with tags for @retry, @circuit-breaker, @fallback, and @degradation. Implement a post-generation validator that checks each scenario for: (1) a valid Given-When-Then structure, (2) explicit timeout boundaries in the When step, (3) a clear recovery signal in the Then step, and (4) no unresolved placeholders. If validation fails, retry once with the error message appended to the prompt as additional [CONSTRAINTS]. Log every generation attempt, validation result, and retry decision to your observability stack for traceability.

For high-risk systems where recovery behavior affects data integrity or user safety, route all generated scenarios through a human review queue before they are accepted. The review interface should display the original component spec, the generated Gherkin, and the validator's pass/fail results. Reviewers should confirm that retry exhaustion scenarios do not lead to silent data loss and that fallback responses are explicitly defined. Once approved, the scenarios can be automatically pushed to a test management system via API. Avoid treating this prompt as a fire-and-forget generator; the harness must enforce that every recovery path is explicit, testable, and reviewed before it becomes part of the reliability test suite.

IMPLEMENTATION TABLE

Expected Output Contract

Fields, format, and validation rules for the Gherkin scenario set produced by the Retry and Recovery Scenario Generation Prompt. Use this contract to validate model output before integrating it into a test management system or CI pipeline.

Field or ElementType or FormatRequiredValidation Rule

scenario_set_id

string (UUID v4)

Must be a valid UUID v4 string. Parse check.

scenarios

array of objects

Array length must be >= 1. Schema check on each element against the scenario object contract.

scenarios[].name

string

Must be non-empty and contain a retry or recovery signal keyword (e.g., Retry, Backoff, Circuit Breaker, Fallback, Degradation). Regex check.

scenarios[].feature_tag

string

Must match pattern @[A-Za-z0-9_-]+. Prefix check for '@'.

scenarios[].gherkin_text

string (multi-line)

Must start with Scenario: and contain at least one Given, When, Then step. Gherkin keyword parse check.

scenarios[].retry_policy_reference

string or null

If non-null, must match one of [exponential_backoff, fixed_interval, immediate, linear_backoff]. Enum check. Null allowed.

scenarios[].max_retry_exhaustion_covered

boolean

Must be true if the scenario includes a step where retries are exhausted. Coverage check against gherkin_text.

scenarios[].recovery_signal

string or null

If non-null, must describe a clear recovery indicator (e.g., 200 OK after 503, Circuit closed). Null allowed only if scenario is a pure retry-exhaustion case.

PRACTICAL GUARDRAILS

Common Failure Modes

Retry and recovery scenarios are brittle when the prompt misunderstands system boundaries, timeout semantics, or the difference between transient and permanent failures. These are the most common failure modes and how to prevent them.

01

Confusing Transient and Permanent Failures

What to watch: The model generates retry logic for 4xx client errors (like 400 Bad Request or 401 Unauthorized) as if they were transient 5xx server errors. This leads to infinite retry loops on unrecoverable faults. Guardrail: Add a [RETRYABLE_ERRORS] constraint that explicitly lists which status codes, exception types, or error categories are eligible for retry. Validate output scenarios against this list.

02

Missing Timeout Boundary Scenarios

What to watch: Generated scenarios only cover success and immediate failure, ignoring the critical boundary where a request hangs or exceeds the timeout threshold. Timeout behavior is often the most common production failure. Guardrail: Require a [TIMEOUT_BOUNDARY] input specifying max wait times, and include an eval check that every generated scenario set contains at least one timeout-exceeded case with explicit expected behavior.

03

Unbounded Retry Exhaustion

What to watch: Scenarios describe retry logic but never define what happens when max retries are exhausted. The system behavior after the final failure is left unspecified, creating an ambiguity that breaks automation. Guardrail: Add a [MAX_RETRY_EXHAUSTION] output requirement mandating a scenario for the terminal state after all retries fail, including the exact error response, log signal, or fallback action.

04

Idempotency Key Lifecycle Omission

What to watch: Retry scenarios for state-changing operations (POST, PATCH, payment endpoints) omit idempotency key behavior, duplicate detection, or key expiration. This produces scenarios that would cause double-charges or duplicate records in production. Guardrail: When [OPERATION_TYPE] is state-changing, require idempotency-specific scenarios covering duplicate key submission, key reuse after success, and key collision across clients.

05

Circuit Breaker State Blindness

What to watch: Scenarios treat every retry attempt independently, ignoring circuit breaker state transitions (closed → open → half-open). The model generates retry logic that would hammer a downstream service already in a degraded state. Guardrail: Include a [CIRCUIT_BREAKER_STATES] input defining the breaker configuration, and validate that generated scenarios cover open-circuit fast-fail behavior and half-open probe attempts.

06

Fallback Ambiguity Under Partial Failure

What to watch: When a composite operation partially succeeds (e.g., payment processed but notification failed), the generated recovery scenario either retries everything or gives up entirely, missing the partial-success state. Guardrail: Require [COMPOSITE_OPERATION_BOUNDARIES] in the input, and add an eval check that scenarios address partial-failure states with explicit compensation or rollback steps, not just all-or-nothing retry.

IMPLEMENTATION TABLE

Evaluation Rubric

Use this rubric to evaluate the quality of generated retry and recovery Gherkin scenarios before integrating them into your test suite. Each criterion targets a specific failure mode common to AI-generated behavior specifications for transient failure handling.

CriterionPass StandardFailure SignalTest Method

Retry Policy Completeness

Scenario covers max-retry exhaustion, retryable vs. non-retryable error distinction, and backoff strategy

Scenario only describes the happy retry path without defining what happens when retries are exhausted

Manual review: check for explicit When steps covering retry limit reached and non-retryable error codes

Backoff Strategy Verifiability

Backoff behavior is expressed as a testable assertion (e.g., 'the time between retry 1 and retry 2 is at least 1 second')

Backoff is described vaguely as 'exponential backoff' or 'with delay' without measurable bounds

Schema check: confirm at least one Then step contains a numeric time boundary or ordering constraint

Circuit Breaker State Coverage

Scenario includes transitions through closed, open, and half-open states with distinct expected outcomes for each

Circuit breaker is mentioned only in the open state or treated as a binary on/off toggle

State machine audit: verify each state appears in at least one Given precondition and one Then outcome

Fallback Response Specification

Fallback behavior defines the exact response body, status code, or user-facing message returned when the primary path fails

Fallback is described as 'return a fallback' or 'degrade gracefully' without concrete output contract

Output contract check: confirm fallback Then step includes a specific HTTP status code, error code, or message string

Timeout Boundary Validation

Scenario includes an explicit timeout duration and tests behavior at timeout-minus-epsilon and timeout-plus-epsilon

Timeout is stated but no boundary condition is tested; scenario only covers the timeout-triggered case

Boundary analysis: verify at least two scenarios exist—one where the operation completes just before timeout and one just after

Recovery Signal Clarity

Scenario defines the exact condition that indicates recovery (e.g., 'when the downstream service returns 200 on the health check endpoint')

Recovery is assumed implicitly after a retry count or time delay without a verifiable signal

Signal traceability: confirm the When step for recovery references a specific endpoint, status code, or event

Idempotency Key Lifecycle

Scenario covers duplicate retry with same idempotency key, retry with new key after expiration, and concurrent retry collision

Idempotency is mentioned only as 'use an idempotency key' without testing key reuse, expiry, or conflict

Coverage matrix: verify at least three scenarios covering key reuse, key expiration, and concurrent submission with same key

Observability Signal Assertion

Scenario asserts that retry exhaustion, circuit breaker state change, or fallback activation produces a log entry, metric increment, or alert

Scenario only validates functional behavior without checking that the failure is observable

Observability audit: confirm at least one Then step asserts a log level, metric name, or alert firing condition

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with a single retry policy and one recovery path. Replace [RETRY_POLICY] with a simple exponential backoff description. Limit [FAILURE_MODES] to 2-3 common scenarios (timeout, 5xx). Skip the [OBSERVABILITY_SIGNALS] section and use manual review of generated Gherkin instead.

Watch for

  • Scenarios that assume infinite retries without max-retry exhaustion
  • Missing circuit breaker state transitions (half-open, open, closed)
  • Recovery signals that are too vague to automate (e.g., "system recovers" without a measurable condition)
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.