Use this prompt when you are designing or reviewing a saga-based distributed transaction and need a rigorous failure mode analysis of your compensating transactions. The prompt is built for architects and backend engineers who have already chosen the saga pattern and are now defining the rollback logic. It is not a tutorial on sagas; it assumes you understand orchestration, compensation, and eventual consistency. The primary job-to-be-done is to surface incomplete compensation paths, ordering constraints that break during partial failures, and irreversible side effects that cannot be rolled back by code alone.
Prompt
Saga Orchestration Failure Recovery Prompt

When to Use This Prompt
Define the job, reader, and constraints for the Saga Orchestration Failure Recovery Prompt.
This prompt requires specific inputs to be useful. You must provide a description of the saga steps in order, the compensating action for each step, and any known constraints such as external payment gateways, inventory systems, or third-party APIs that lack undo capabilities. Without these details, the model will produce generic advice that fails to identify the real risks in your system. The prompt works best when you also supply a concrete failure scenario—such as 'step 3 succeeds but step 4 fails after the payment is captured'—so the analysis can trace the exact compensation path and flag gaps.
Do not use this prompt for simple request-response workflows, single-service transactions, or systems that rely on ACID database transactions within a single resource manager. It is also not a substitute for chaos engineering or production testing; the output is a design-time analysis that identifies theoretical failure modes, not runtime behavior. If your system handles financial reconciliation, healthcare data, or other regulated domains, treat the prompt's output as a starting point for a formal failure mode and effects analysis (FMEA) that includes human review and evidence grounding. After running the prompt, take the identified gaps and design compensating actions or manual intervention workflows before writing implementation code.
Use Case Fit
Where this prompt works and where it does not. Use these cards to decide if the Saga Orchestration Failure Recovery Prompt fits your current architecture review task.
Good Fit: Orchestrated Sagas
Use when: you have a central orchestrator managing a multi-step distributed transaction with defined compensating actions. The prompt excels at analyzing compensation completeness and ordering constraints across known service boundaries.
Bad Fit: Choreographed Event Flows
Avoid when: your system uses event choreography without a central coordinator. The prompt assumes an orchestrator that tracks step state and triggers compensations. Choreographed systems require different failure analysis patterns.
Required Input: Complete Saga Definition
What to watch: the prompt needs the full saga step sequence, each step's compensating transaction, and the orchestrator's state machine. Missing or incomplete compensation definitions produce unreliable failure mode analysis.
Operational Risk: Irreversible Side Effects
Risk: some saga steps produce external effects that cannot be compensated (email sent, physical shipment triggered, third-party API with no undo). Guardrail: flag these steps explicitly in the input so the prompt can identify recovery gaps and recommend manual intervention points.
Good Fit: Pre-Implementation Design Review
Use when: you are designing the saga before coding begins. The prompt surfaces failure modes early, when compensating transactions are cheaper to redesign. Post-implementation reviews catch fewer structural issues.
Bad Fit: Single-Step Transactions
Avoid when: your operation is a single database transaction or a simple request-response call. The prompt's compensation ordering analysis adds no value for atomic operations that don't span multiple services.
Copy-Ready Prompt Template
A reusable prompt template for analyzing saga orchestration failure recovery and compensation completeness.
This section provides the core prompt template for evaluating saga orchestration failure recovery. The template is designed to be copied directly into your AI harness, with square-bracket placeholders that you replace with your specific saga definition, compensation catalog, and risk tolerance. The prompt forces the model to reason about compensation ordering constraints, irreversible side effects, and partial failure states—not just happy-path rollback. Use this template when you have a defined saga with explicit compensating transactions and need a structured failure mode analysis before implementation begins.
textYou are a distributed systems architect specializing in saga orchestration patterns and compensating transaction design. Your task is to analyze the failure recovery strategy for a saga orchestration and identify gaps in compensation completeness, ordering constraints, and partial failure handling. ## SAGA DEFINITION [SAGA_NAME]: [SAGA_DESCRIPTION] [SAGA_STEPS] - Step [STEP_ID]: [STEP_DESCRIPTION] | Compensation: [COMPENSATION_DESCRIPTION] | Reversible: [YES/NO/PARTIAL] ## CONTEXT [CONTEXT] Include any relevant context about the system, such as: - Service boundaries and ownership - Transactional vs. non-transactional resources - External system dependencies - Business impact of partial failures ## CONSTRAINTS [CONSTRAINTS] Specify any constraints that affect recovery design, such as: - Maximum acceptable recovery time - Data consistency requirements (eventual, strong, etc.) - Regulatory or compliance requirements - Irreversible operations that cannot be compensated ## OUTPUT SCHEMA Return a JSON object with the following structure: { "analysis": { "compensation_completeness": { "status": "COMPLETE|INCOMPLETE|PARTIAL", "missing_compensations": [ { "step_id": "string", "gap_description": "string", "risk_level": "HIGH|MEDIUM|LOW", "suggested_compensation": "string" } ], "coverage_percentage": number }, "ordering_constraints": [ { "constraint_type": "SEQUENTIAL|PARALLEL|CONDITIONAL", "affected_steps": ["string"], "description": "string", "violation_risk": "string" } ], "irreversible_side_effects": [ { "step_id": "string", "effect_description": "string", "mitigation_strategy": "string", "acceptance_required": true } ], "partial_failure_scenarios": [ { "scenario_id": "string", "failing_step": "string", "completed_steps": ["string"], "in_flight_steps": ["string"], "recovery_path": "string", "data_inconsistency_risk": "HIGH|MEDIUM|LOW", "recommended_action": "string" } ] }, "test_scenarios": [ { "scenario_name": "string", "failure_injection_point": "string", "expected_behavior": "string", "compensation_chain": ["string"], "verification_criteria": ["string"] } ], "recommendations": [ { "priority": "CRITICAL|HIGH|MEDIUM|LOW", "category": "COMPENSATION|ORDERING|IDEMPOTENCY|MONITORING|TESTING", "description": "string", "implementation_effort": "LOW|MEDIUM|HIGH" } ], "risk_summary": { "overall_risk_level": "HIGH|MEDIUM|LOW", "unresolved_risks": ["string"], "requires_human_review": true } } ## ANALYSIS REQUIREMENTS 1. For each saga step, verify that a compensating transaction exists and is complete. 2. Identify ordering dependencies between compensations—some compensations must run in reverse order, others can run in parallel. 3. Flag any irreversible side effects (e.g., sent emails, external API calls with no undo, physical actions) and recommend mitigation. 4. Enumerate partial failure scenarios where some steps succeeded and others are in-flight when failure occurs. 5. Generate test scenarios that specifically target compensation failures, not just saga step failures. 6. If any compensation itself can fail, recommend idempotency guards and retry strategies. 7. For high-risk scenarios, recommend human approval gates before compensation execution. ## RISK LEVEL [RISK_LEVEL] Specify the risk tolerance for this analysis: LOW, MEDIUM, HIGH, or CRITICAL. This affects the depth of scenario enumeration and the threshold for flagging issues.
After copying the template, replace each square-bracket placeholder with your specific saga details. The [SAGA_STEPS] section is the most critical—each step must include its compensation definition and reversibility flag. For steps marked PARTIAL or NO, the model will generate specific mitigation strategies rather than assuming full rollback is possible. The [RISK_LEVEL] parameter controls analysis depth: CRITICAL risk triggers exhaustive scenario enumeration including double-fault conditions where a compensation itself fails. Wire the output schema into your validation pipeline to ensure the JSON structure is parseable before surfacing results to your architecture review process.
Prompt Variables
Inputs the Saga Orchestration Failure Recovery Prompt needs to produce a reliable failure mode analysis. Each placeholder must be populated with concrete system design details before the prompt is invoked.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[SAGA_DEFINITION] | The full sequence of local transactions and their corresponding compensating transactions in the saga | {"steps": [{"name": "ReserveInventory", "action": "POST /inventory/reserve", "compensation": "POST /inventory/release"}, {"name": "ProcessPayment", "action": "POST /payment/charge", "compensation": "POST /payment/refund"}]} | Must be valid JSON with non-empty steps array. Each step requires action and compensation fields. Validate schema before prompt assembly. |
[FAILURE_SCENARIO] | The specific step and failure mode to analyze for compensation completeness | Step ProcessPayment fails with timeout after ReserveInventory succeeded | Must reference a step name present in [SAGA_DEFINITION]. Must describe the failure type (timeout, crash, business rejection, network partition). Free-text but required. |
[SYSTEM_BOUNDARIES] | Description of service boundaries, communication protocols, and transaction isolation levels | Inventory service: PostgreSQL with SERIALIZABLE isolation. Payment service: external Stripe API with no distributed transaction support. Communication: synchronous HTTP with 30s timeout. | Must identify each service boundary and its transactional capabilities. Missing isolation level or protocol details will degrade the analysis quality. |
[IRREVERSIBLE_ACTIONS] | List of actions in the saga that produce side effects which cannot be compensated purely through software | ["Shipment label generation triggers physical warehouse pick", "Email notification sent to customer on order confirmation"] | Array of strings. Each entry must describe a real-world side effect. Null allowed if no irreversible actions exist. Prompt uses this to flag compensation gaps that require manual intervention. |
[COMPENSATION_ORDERING] | Whether compensating transactions must execute in strict LIFO order, parallel, or a custom sequence | Strict LIFO: ProcessPayment must be compensated before ReserveInventory can be released | Must be one of: LIFO, FIFO, PARALLEL, CUSTOM. If CUSTOM, provide the explicit ordering rules. Incorrect ordering assumptions produce invalid recovery plans. |
[IDEMPOTENCY_GUARANTEES] | Which compensating transactions are idempotent and how idempotency is implemented | {"POST /inventory/release": {"idempotent": true, "mechanism": "idempotency key in request header"}, "POST /payment/refund": {"idempotent": false, "risk": "duplicate refund possible"}} | JSON object keyed by compensation endpoint. Each entry must declare idempotent boolean and mechanism string. Non-idempotent compensations are flagged as high-risk in the output. |
[RETRY_POLICY] | The retry configuration applied to compensating transactions during recovery | {"max_retries": 3, "backoff": "exponential", "initial_delay_ms": 1000, "max_delay_ms": 30000, "retryable_errors": ["TIMEOUT", "503", "CONNECTION_REFUSED"]} | Must be valid JSON matching the retry policy schema. Missing retryable_errors list will cause the prompt to assume all errors are retryable, producing overly optimistic recovery assessments. |
[OUTPUT_SCHEMA] | The expected structure of the failure mode analysis output | {"failure_modes": [{"step": "string", "failure_type": "string", "compensation_gap": "string", "severity": "HIGH|MEDIUM|LOW", "irreversible_side_effect": "boolean", "recommended_mitigation": "string"}], "overall_risk_score": "HIGH|MEDIUM|LOW", "requires_manual_intervention": "boolean"} | Must be a valid JSON Schema or example structure. The prompt will be instructed to conform to this schema. Validate output against this schema in the harness before accepting the response. |
Implementation Harness Notes
How to wire the saga failure recovery prompt into a design review pipeline with validation, retries, and human approval gates.
This prompt is designed to operate as a synchronous design review step within a broader architecture governance workflow. It should be called after a saga orchestration design document is drafted but before the design is approved for implementation. The prompt expects a structured input containing the saga definition, participant services, and compensation definitions. Wire it into your CI/CD pipeline, architecture review board tooling, or internal developer portal as a gated check that runs when a new saga design or a modification to an existing saga is proposed.
Integration pattern: POST the assembled prompt to your model API (GPT-4o, Claude 3.5 Sonnet, or Gemini 1.5 Pro are recommended for this structured reasoning task). The request must include response_format: { type: "json_object" } or equivalent structured output mode. On the client side, validate the response against a JSON schema that enforces the expected output shape: a failure_modes array, each with failure_scenario, compensation_gaps, ordering_risks, irreversible_side_effects, and severity fields. Reject and retry up to two times if the output fails schema validation or if the severity field contains values outside the expected enum (CRITICAL, HIGH, MEDIUM, LOW). Log every validation failure for prompt drift analysis.
Human review gate: For any saga design where the prompt returns one or more CRITICAL severity findings, the workflow must block automatic approval and route the output to a designated architecture reviewer. The review interface should display the original saga design, the model's failure mode analysis, and a structured approval form. The reviewer must explicitly acknowledge or override each critical finding before the design can proceed. For HIGH severity findings, consider a softer gate: allow the design to proceed with a mandatory follow-up task to address the finding within a defined sprint window. Observability: Attach trace metadata to each prompt call—saga name, version, requesting team, and model used—so you can track which designs triggered the most findings and whether prompt effectiveness drifts across model versions.
Expected Output Contract
Define the exact shape, types, and validation rules for the saga orchestration failure recovery analysis output. Use this contract to build downstream parsers, validators, and evaluation harnesses before integrating the prompt into a production pipeline.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
saga_name | string | Must match the [SAGA_NAME] input exactly; non-empty and trimmed. | |
orchestrator_id | string | Must be a non-empty string matching the [ORCHESTRATOR_ID] input. | |
compensating_transactions | array of objects | Array length must equal the number of steps in the saga. Each object must contain step_id, compensation_action, and is_reversible fields. | |
compensating_transactions[].step_id | string | Must be a unique, non-empty string within the array, matching a step defined in [SAGA_STEPS]. | |
compensating_transactions[].compensation_action | string | Must be a non-empty string describing the specific compensating action. Cannot be a generic placeholder like 'undo'. | |
compensating_transactions[].is_reversible | boolean | Must be true or false. If false, the failure_mode_analysis must include an entry for this step. | |
failure_mode_analysis | array of objects | Must contain at least one entry for each step where is_reversible is false. Each object must include step_id, failure_scenario, and impact. | |
partial_failure_states | array of objects | Must contain at least one entry. Each object must include failed_step, completed_steps, and system_state fields. completed_steps must be a subset of [SAGA_STEPS]. |
Common Failure Modes
What breaks first when using a saga orchestration failure recovery prompt and how to guard against it.
Incomplete Compensation Chain
What to watch: The model identifies compensating transactions for the happy path but misses compensation steps for side effects like audit logs, emitted events, or cache updates. Guardrail: Provide a complete service dependency graph in [CONTEXT] and explicitly request compensation for every write operation, not just database transactions.
Ordering Constraint Violations
What to watch: The model proposes compensation steps in an order that violates foreign key constraints, temporal dependencies, or business rules. Guardrail: Include explicit ordering constraints in [CONSTRAINTS] and validate the output against a dependency matrix before accepting the recovery plan.
Irreversible Side Effect Blindness
What to watch: The model treats all operations as reversible and fails to flag side effects that cannot be compensated, such as sent emails, triggered alerts, or fulfilled physical orders. Guardrail: Add a required output field for irreversible_effects and escalate any plan that contains them for human review before execution.
Partial Failure State Drift
What to watch: The model assumes a clean failure at a single step, missing scenarios where multiple services are in inconsistent intermediate states. Guardrail: Provide explicit partial-failure scenarios in [CONTEXT] and require the model to enumerate the state of each service before proposing compensation.
Compensation Idempotency Gaps
What to watch: The model generates compensation logic that is not idempotent, risking double compensation or data corruption if the recovery process itself is retried. Guardrail: Add a validation rule that every compensation step must include an idempotency key or precondition check, and flag any step that lacks one.
Timeout and Resource Leakage
What to watch: The model ignores temporal constraints, proposing compensation plans that hold locks, connections, or resources beyond acceptable timeout windows. Guardrail: Include timeout budgets in [CONSTRAINTS] and validate that each compensation step completes within its allocated window or escalates to a manual intervention path.
Evaluation Rubric
Criteria for evaluating the quality and safety of a saga orchestration failure recovery analysis before integrating it into a design review or automated pipeline.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Compensation Completeness | Every forward step in the saga has a corresponding compensating action defined | A forward step is listed without a compensating action or the compensation is marked as 'none' without explicit justification | Parse the output for the list of saga steps and compensating actions; assert that the count of forward steps equals the count of compensating actions |
Ordering Constraint Validity | Compensating actions are listed in the correct reverse order of the forward steps | A compensating action is listed out of sequence relative to its forward step, or the order is ambiguous | Extract the ordered list of forward steps and the ordered list of compensating actions; assert that the compensating list is the exact reverse of the forward list |
Partial Failure State Enumeration | At least one distinct failure scenario is described for each saga step, including the state of preceding and succeeding steps | A saga step has zero failure scenarios described, or a scenario assumes all prior steps succeeded without stating that assumption | Count the number of steps with at least one failure scenario; assert the count equals the total number of saga steps |
Irreversible Side Effect Identification | Any step with an irreversible side effect (e.g., sending an email, triggering a physical action) is explicitly flagged with a mitigation strategy | An irreversible side effect is described in a forward step but not flagged, or the mitigation strategy is 'manual intervention' without a defined escalation path | Search the output for keywords like 'email', 'notification', 'physical', 'shipment'; assert that each occurrence is accompanied by a flag and a concrete mitigation |
Test Scenario Coverage | At least one concrete test scenario is provided for each identified compensation failure mode | A compensation failure mode is listed without a corresponding test scenario, or the test scenario lacks a clear pass/fail condition | Parse the test scenarios section; assert that the number of test scenarios is greater than or equal to the number of compensation failure modes |
Data Consistency Assertion | The analysis states the final data consistency guarantee (e.g., eventual, strong) and identifies any windows of inconsistency | The consistency guarantee is missing, or a window of inconsistency is described without a duration or impact assessment | Search the output for a consistency guarantee statement; assert it is present and is followed by a description of inconsistency windows |
Human Approval Gate | The analysis identifies at least one failure mode that requires human approval before automated recovery proceeds | No human approval gate is recommended, or the gate is recommended for a trivial failure while a high-risk failure (e.g., financial reversal) is left fully automated | Search the output for 'human approval' or 'manual intervention'; assert at least one occurrence is tied to a high-severity failure mode |
Idempotency of Compensations | Each compensating action is assessed for idempotency, and non-idempotent compensations include a retry safeguard | A compensating action like a refund or delete is not assessed for idempotency, or a non-idempotent action lacks a safeguard such as a unique idempotency key | Parse each compensating action description; assert that 'idempotent' or a specific idempotency mechanism is mentioned for every action |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Start with the base prompt and a single saga definition. Remove strict schema enforcement and focus on getting a readable failure mode list. Use a simple markdown output format instead of structured JSON. Run against one known saga (e.g., an order checkout flow) and iterate on compensation completeness manually.
Prompt snippet
codeAnalyze the following saga for compensation failures: [SAGA_DESCRIPTION] List every step, its compensating action, and any scenario where compensation could fail or leave the system in an inconsistent state.
Watch for
- Missing compensation steps that the model assumes are "obvious"
- Overly generic failure modes without specific partial-failure states
- No distinction between reversible and irreversible side effects

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us