Inferensys

Prompt

Retry Budget for Partial Success Handling Prompt Template

A practical prompt playbook for using Retry Budget for Partial Success Handling Prompt Template in production AI workflows.
Operations team reviewing AI workflow automation on laptop, workflow builder visible, casual office setup.
PROMPT PLAYBOOK

When to Use This Prompt

Understand when partial-success retry budgets are the right pattern and when a simpler retry or full restart is safer.

This prompt is designed for platform teams running batch or multi-part AI workflows where sub-tasks are independent or loosely coupled. The core job-to-be-done is maximizing throughput and preserving compute by retrying only the failed portions of a job, rather than discarding all progress and starting over. Ideal users are AI platform architects, reliability engineers, and backend developers building agent harnesses, ETL pipelines with AI steps, or batch inference systems. Required context includes a clear definition of what constitutes a sub-task, a way to isolate successes from failures, and a retry budget (count, token, time, or cost) that the system is willing to spend on the failed subset.

Do not use this prompt when sub-tasks have strict ordering dependencies or shared mutable state that makes partial retry unsafe. If a failure in one sub-task invalidates the results of others, a full restart is more appropriate. Similarly, avoid this pattern for non-idempotent actions where a retry could cause duplicate side effects—use the dedicated non-idempotent action escalation prompt instead. This prompt also assumes that the model can reliably distinguish successful from failed sub-tasks; if your failure detection is noisy, invest in output validation and structured error classification before implementing partial retry logic. For high-risk domains such as healthcare, finance, or legal workflows, always include a human review step before acting on partial results, and ensure your retry budget escalation payload includes full traceability for auditors.

To implement this effectively, start by defining your sub-task boundary and success criteria in code, not just in the prompt. The prompt instructs the model on the policy, but your application harness must enforce the budget, track retry counts per sub-task, and prevent the model from exceeding its allocation. Wire the prompt into a retry loop that passes only the failed sub-tasks and their error context back to the model on each iteration. When the budget is exhausted, escalate the failed sub-tasks with a structured payload that includes retry history, error traces, and the preserved successful results. This keeps your system observable and prevents silent partial failures from reaching downstream consumers.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Retry Budget for Partial Success Handling prompt template works well and where it introduces risk. Use these cards to decide if this pattern fits your workflow before you integrate it into a harness.

01

Good Fit: Batch or Multi-Part Workflows

Use when: your system processes multiple independent sub-tasks in a single run (e.g., extracting fields from 50 documents, calling 10 APIs, or grading 100 test cases). Guardrail: the prompt must receive a clear list of sub-tasks with per-item success/failure status so it can budget retries only for failed items.

02

Bad Fit: Single Atomic Requests

Avoid when: the entire request succeeds or fails as a unit with no partial results to preserve. A retry budget for partial success adds unnecessary complexity when a simple retry-or-escalate decision suffices. Guardrail: use a single-attempt retry budget prompt instead.

03

Required Input: Partial-State Snapshot

What to watch: the prompt cannot make accurate budget decisions without knowing which sub-tasks succeeded, which failed, and what partial results are already saved. Guardrail: the harness must pass a structured partial-state object with item IDs, statuses, and preserved outputs before invoking the retry budget prompt.

04

Operational Risk: Partial-State Corruption

What to watch: if the harness incorrectly marks failed items as successful or loses preserved results between retries, the budget prompt will make decisions on bad data. Guardrail: validate the partial-state snapshot against the original task list before each retry cycle, and log state transitions for audit.

05

Operational Risk: Retry Amplification

What to watch: a large batch with many failed sub-tasks can consume the entire retry budget on low-value items, starving higher-priority failures. Guardrail: include sub-task priority or value classification in the input so the prompt can allocate budget proportionally rather than evenly.

06

Bad Fit: Non-Idempotent Sub-Tasks

Avoid when: sub-tasks have irreversible side effects (e.g., sending emails, creating database records, charging payments) and retrying could duplicate actions. Guardrail: classify sub-tasks by idempotency before invoking the retry budget prompt, and escalate non-idempotent failures immediately without retry.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A reusable prompt that budgets retries for failed sub-tasks while preserving successful partial results, with structured escalation for the failed portions.

This prompt template is designed to be pasted into your orchestration layer and populated with variables before each retry decision cycle. It instructs the model to act as a retry policy engine that evaluates a batch of sub-tasks, identifies which succeeded and which failed, allocates remaining retry budget to the failed items, and produces a structured decision payload. The prompt preserves successful partial results and only escalates the portions that cannot be recovered within the budget.

text
You are a retry policy engine for a batch AI workflow. Your job is to evaluate partial success across a set of sub-tasks, allocate remaining retry budget to failed sub-tasks, and decide whether to retry or escalate each failure.

## INPUT
- Sub-task results: [SUB_TASK_RESULTS]
- Remaining retry budget: [REMAINING_RETRY_BUDGET]
- Per-sub-task retry cost: [RETRY_COST_PER_TASK]
- Escalation threshold: [ESCALATION_THRESHOLD]
- Task priority weights: [PRIORITY_WEIGHTS]
- Error classification rules: [ERROR_CLASSIFICATION_RULES]

## CONSTRAINTS
- Preserve all successful sub-task results without modification.
- Do not retry sub-tasks that have already succeeded.
- Allocate retries to failed sub-tasks based on priority weight and retry cost.
- If a sub-task has consumed more than [MAX_RETRIES_PER_TASK] retries, mark it for escalation regardless of remaining budget.
- If the total retry cost of all eligible failures exceeds the remaining budget, select the highest-priority subset that fits within budget and escalate the rest.
- For sub-tasks marked for escalation, include the failure reason, retry count, and last error message.

## OUTPUT_SCHEMA
Return a valid JSON object with this structure:
{
  "preserved_successes": [
    {
      "task_id": "string",
      "result": "object"
    }
  ],
  "retry_queue": [
    {
      "task_id": "string",
      "retry_instruction": "string describing what to correct",
      "allocated_budget": "integer"
    }
  ],
  "escalation_queue": [
    {
      "task_id": "string",
      "failure_reason": "string",
      "retry_count": "integer",
      "last_error": "string",
      "escalation_priority": "high | medium | low"
    }
  ],
  "budget_summary": {
    "total_remaining": "integer",
    "allocated_for_retries": "integer",
    "unallocated": "integer"
  },
  "decision_rationale": "string explaining allocation choices"
}

## EXAMPLES
[EXAMPLES]

## RISK_LEVEL
[RISK_LEVEL]

If RISK_LEVEL is high, require human approval before executing the retry queue. If RISK_LEVEL is low, proceed with retries automatically but log all escalation decisions.

To adapt this template, replace each square-bracket placeholder with concrete values from your application state. The [SUB_TASK_RESULTS] should be a structured array of task IDs, statuses, outputs, and error details. The [ERROR_CLASSIFICATION_RULES] should define which error types are retryable versus immediately escalatable—for example, transient API errors may be retryable while schema violations that persist across two attempts should escalate. The [EXAMPLES] placeholder should contain one or two few-shot demonstrations showing correct budget allocation when some sub-tasks succeed and others fail. If your workflow involves non-idempotent actions, set [RISK_LEVEL] to high and ensure the escalation queue includes enough context for a human reviewer to safely resume or roll back the failed sub-tasks.

IMPLEMENTATION TABLE

Prompt Variables

Inputs required by the Retry Budget for Partial Success Handling prompt. Each variable must be populated before the prompt is assembled to ensure the model can correctly isolate failed sub-tasks, preserve successful results, and enforce budget limits.

PlaceholderPurposeExampleValidation Notes

[TASK_BATCH]

The complete list of sub-tasks or items to process, each with a unique identifier.

{"items": [{"id": "t1", "payload": "..."}, {"id": "t2", "payload": "..."}]}

Must be a valid JSON array of objects. Each object requires a unique 'id' field. Empty batch should trigger immediate termination.

[PARTIAL_RESULTS]

The set of sub-tasks that have already succeeded, with their outputs.

{"t1": {"status": "success", "output": "..."}}

Must be a valid JSON object keyed by sub-task ID. IDs must be a subset of [TASK_BATCH] IDs. Null allowed on first attempt.

[FAILED_ITEMS]

The subset of sub-tasks that failed validation or execution, with error details.

[{"id": "t2", "error": "Schema validation failed: missing 'email' field"}]

Must be a valid JSON array. Each entry requires 'id' and 'error' fields. IDs must exist in [TASK_BATCH] and not in [PARTIAL_RESULTS].

[RETRY_BUDGET_REMAINING]

The number of retry attempts still available for the current batch.

3

Must be a non-negative integer. If 0, the prompt should not be invoked; escalate immediately. Validate type before prompt assembly.

[MAX_RETRIES_PER_ITEM]

The maximum number of times a single sub-task can be retried before it is permanently failed.

2

Must be a positive integer. Used to prevent a single poisoned item from consuming the entire batch budget. Validate that it is less than or equal to [RETRY_BUDGET_REMAINING].

[OUTPUT_SCHEMA]

The exact JSON schema that each sub-task output must conform to.

{"type": "object", "properties": {"name": {"type": "string"}}, "required": ["name"]}

Must be a valid JSON Schema (Draft 7+). Used by the harness to validate outputs, not just by the prompt. Schema parse failure should block prompt execution.

[ESCALATION_POLICY]

Instructions for what to do with items that exhaust their per-item retry budget.

"Move to dead-letter queue 'dlq-partial' and notify #ops-alerts"

Must be a non-empty string. Should specify a concrete routing or notification target. Vague instructions like 'handle later' should fail validation.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the partial-success retry budget prompt into a batch processing harness with validation, state tracking, and escalation.

This prompt is designed to sit inside a batch processing loop where a parent task has been decomposed into multiple sub-tasks. The harness must maintain a persistent state object that tracks which sub-tasks succeeded, which failed, and how many retries have been consumed per sub-task. Before invoking the LLM, the harness should extract the current retry budget, the list of failed sub-tasks with their error contexts, and the preserved successful partial results. The prompt receives these as [SUCCESSFUL_RESULTS], [FAILED_TASKS], [RETRY_BUDGET_REMAINING], and [ERROR_CONTEXT] and returns a decision for each failed sub-task: retry, skip, or escalate.

The harness must validate the model's output against a strict schema before acting on it. Each decision object should contain a task_id, an action enum (retry | skip | escalate), and a reasoning string. If the action is retry, the harness should decrement the retry budget for that sub-task and re-invoke the original sub-task handler with any corrected parameters from the model's output. If the action is skip, the harness should mark the sub-task as permanently failed and log the skip reason for downstream reporting. If the action is escalate, the harness should package the sub-task's full error history, retry count, and the model's reasoning into an escalation payload and route it to the configured escalation target (a human queue, a dead-letter topic, or a fallback model). The harness must also enforce a global retry budget across all sub-tasks to prevent a single sub-task from consuming all available retries while others starve.

For production reliability, implement idempotency keys on sub-task execution to prevent duplicate side effects if the harness retries a sub-task that had partially succeeded. Log every retry decision with the model's reasoning, the retry budget state before and after, and the sub-task outcome. Set a hard limit on the total number of retry-budget evaluation calls to the LLM per batch to avoid runaway loops. If the model returns an invalid schema or an action that would exceed the remaining budget, the harness should reject the response, increment a validation-failure counter, and re-invoke the prompt with the validation error included in [ERROR_CONTEXT]. After three consecutive validation failures, escalate the entire batch to human review rather than continuing to consume tokens on unparseable outputs.

IMPLEMENTATION TABLE

Expected Output Contract

Fields, types, and validation rules for the partial-success retry policy output. Use this contract to build a parser or validator in your AI harness before accepting the model's response.

Field or ElementType or FormatRequiredValidation Rule

retry_policy_id

string (UUID v4)

Must parse as valid UUID v4; reject if missing or malformed

budget_definition

object

Must contain max_retries (integer >= 0) and budget_scope (enum: per_task | per_batch | per_session)

partial_results_preserved

array of task_id strings

Each entry must match a task_id from the input batch; empty array allowed if no tasks succeeded

failed_tasks

array of objects

Each object must include task_id (string), error_category (enum), and retry_attempts_remaining (integer >= 0)

retry_instructions

array of objects

Each object must include target_task_id (string), action (enum: retry | escalate | skip), and revised_prompt (string or null)

escalation_payload

object or null

If present, must include escalation_reason (enum), failed_task_summary (string), retry_history (array), and recommended_recipient (string)

integrity_check

object

Must include successful_count (integer), failed_count (integer), and total_count (integer); successful_count + failed_count must equal total_count

policy_metadata

object

Must include generated_at (ISO 8601 timestamp), model_version (string), and budget_exhausted (boolean)

PRACTICAL GUARDRAILS

Common Failure Modes

Partial success handling introduces unique failure modes where retry budgets are consumed on the wrong sub-tasks, partial state becomes corrupted, or the system fails to isolate failures. These cards cover what breaks first and how to guard against it.

01

Budget Exhaustion on Recoverable Failures

What to watch: The retry budget is consumed entirely by a single stubborn sub-task, leaving no budget for other sub-tasks that could have succeeded with one more attempt. This starves the rest of the batch. Guardrail: Implement per-sub-task budget caps in addition to the global budget. When a sub-task hits its individual cap, freeze it and preserve its last partial result for escalation.

02

Partial State Corruption Across Retries

What to watch: A retry on a failed sub-task inadvertently overwrites or invalidates the successful partial results from other sub-tasks, corrupting the aggregate output. This often happens when the retry prompt regenerates the entire response rather than patching only the failed portion. Guardrail: Design the retry prompt to accept and preserve a [SUCCESSFUL_RESULTS] block explicitly, instructing the model to merge only the repaired sub-task output into the existing structure.

03

Non-Idempotent Side Effects on Retry

What to watch: A sub-task that performed a non-idempotent action (e.g., sending an email, creating a database record) succeeds but is marked as failed due to a parsing error. The retry re-executes the action, causing duplicates. Guardrail: Classify sub-tasks by idempotency before retry. For non-idempotent sub-tasks, the retry prompt must first verify whether the side effect already occurred and, if so, skip re-execution and repair only the output representation.

04

Escalation Payload Missing Failed Context

What to watch: When the retry budget is exhausted and the system escalates, the escalation payload contains only the final failed output without the retry history, error traces, or attempted corrections. The human reviewer lacks the context to resolve the issue efficiently. Guardrail: Build the escalation payload incrementally across retries. Append each attempt's error, correction strategy, and output diff to a [RETRY_LOG] that is included in the escalation message.

05

Silent Degradation of Successful Sub-Tasks

What to watch: The model, when asked to repair a failed sub-task, subtly alters the content of previously successful sub-tasks in the same response, introducing regressions that go undetected because only the failed sub-task is re-validated. Guardrail: After every retry that produces a merged output, run a checksum or semantic-equivalence check on the previously successful sub-tasks against their stored originals. Flag any drift for review.

06

Infinite Retry on Unrecoverable Validation Errors

What to watch: A sub-task fails validation due to a fundamental input problem (e.g., missing required source data) rather than a model output error. The retry loop attempts repair repeatedly, consuming the entire budget with no chance of success. Guardrail: Classify validation errors as recoverable or unrecoverable before retrying. Unrecoverable errors skip the retry budget entirely and go directly to escalation with a clear explanation of why repair is impossible.

IMPLEMENTATION TABLE

Evaluation Rubric

Use this rubric to test whether the retry budget prompt correctly handles partial success, preserves valid sub-task results, and escalates only the failed portions. Each criterion targets a specific failure mode in batch or multi-part AI workflows.

CriterionPass StandardFailure SignalTest Method

Partial Result Preservation

All successful sub-task outputs appear unchanged in the final payload; no re-execution of passed tasks

Successful sub-task results are missing, overwritten, or regenerated unnecessarily

Run a batch with 3 pass, 2 fail; verify the 3 passed outputs are byte-identical in the final response

Failed Sub-Task Isolation

Only failed sub-tasks are retried; retry budget is consumed per failed item, not globally

Retry budget is applied to the entire batch, causing passed tasks to be re-executed or budget exhausted prematurely

Inject 2 failures in a 5-item batch; confirm retry count increments only for the 2 failed items

Retry Budget Enforcement

Retries stop when the per-item or total budget is exhausted; no infinite loops

System retries beyond the configured budget or enters a retry storm on a single item

Set budget to 2 retries; inject a persistent failure; confirm escalation after exactly 2 attempts per failed item

Escalation Payload Completeness

Escalation payload includes original input, retry history, error traces, and partial success summary

Escalation payload is missing error context, retry count, or the preserved partial results

Trigger budget exhaustion; validate the escalation payload schema contains all required fields with non-null values

State Integrity Across Retries

Partial success state remains consistent; no data corruption or field loss between retry attempts

Fields from successful sub-tasks are dropped, truncated, or mutated during retry of failed sub-tasks

Compare pre-retry and post-retry partial results; assert field-level equality for all successful sub-tasks

Budget Arithmetic Accuracy

Remaining budget is correctly decremented per retry; budget tracking matches actual retry count

Budget counter desynchronizes from actual retries (off-by-one, double-count, or missed decrement)

Log budget remaining after each retry; assert remaining = initial - actual_retries for each failed sub-task

Non-Idempotent Action Handling

Sub-tasks flagged as non-idempotent are retried at most once or escalated immediately

Non-idempotent sub-tasks are retried multiple times, risking duplicate side effects

Mark one failed sub-task as non-idempotent; confirm it receives at most 1 retry before escalation

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Start with the base prompt and a simple in-memory counter. Use a single retry budget for all sub-tasks instead of per-task budgets. Skip partial-state integrity checks and just log which sub-tasks succeeded or failed.

code
[SYSTEM]
You are processing a batch of [SUB_TASK_COUNT] sub-tasks. You may retry failed sub-tasks up to [MAX_RETRIES] times total across the batch. Preserve successful results. For any sub-task that still fails after retries, mark it as ESCALATE and include the last error.

Watch for

  • Retry budget exhaustion before all sub-tasks are attempted
  • No tracking of which sub-tasks consumed retries
  • Silent data loss when partial results aren't persisted between retries
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.