This prompt is for agent runtime developers and platform engineers who need a deterministic, programmatic decision when a long-running agent step exceeds its latency budget. The job-to-be-done is not to generate a user-facing apology or a generic error message. It is to produce a structured recovery action—accept partial results, retry with a reduced scope, or escalate—based on the concrete output and state that existed at the moment of timeout. The ideal user is integrating this prompt into an orchestrator's error-handling loop, where the model's response is parsed by a state machine, not read by an end user.
Prompt
Timeout Recovery Prompt for Long-Running Agent Steps

When to Use This Prompt
Define the job, the reader, and the constraints for the Timeout Recovery Prompt.
Use this prompt when a step has a hard deadline and you need to decide what to do with the incomplete work. This is common in multi-turn tool use, code execution sandboxes, browser agents, and long-running data processing pipelines. The prompt requires the original goal, the partial output captured before the timeout, the step's dependency graph, and the remaining global token or time budget as inputs. Do not use this prompt for simple API calls that can be retried idempotently with exponential backoff; those are better handled by a standard retry library. Do not use it when the step has no observable partial output, as the model will have no evidence to ground its decision and may hallucinate a recovery plan.
The primary risk is that the model will overestimate the usefulness of partial results and recommend proceeding with dangerously incomplete data. To mitigate this, always pair this prompt with a postcondition validation step that checks the accepted partial output against a schema or a set of required fields before it flows to downstream steps. For high-risk domains such as financial transactions or healthcare data processing, the escalation path should route to a human operator with the full partial output and the model's recovery recommendation attached as a non-binding suggestion. The next section provides the copy-ready prompt template you can adapt and wire into your agent harness.
Use Case Fit
Where the Timeout Recovery Prompt delivers value and where it introduces risk. Use these cards to decide if this prompt fits your agent architecture before wiring it into a production harness.
Good Fit: Long-Running Tool Calls with Partial Results
Use when: your agent calls tools (browser, code execution, API orchestration) that can produce useful partial output before hitting a wall-clock timeout. Guardrail: design tool contracts to return intermediate state, not just final results, so the recovery prompt has something to evaluate.
Bad Fit: Atomic Transactions Without Checkpoints
Avoid when: the timed-out step performs a database transaction, payment, or state mutation that cannot be safely inspected mid-flight. Guardrail: wrap atomic operations in idempotency keys and require explicit commit confirmation before the recovery prompt can decide to accept partial work.
Required Input: Structured Progress Snapshot
Risk: without a machine-readable record of what completed before timeout, the recovery prompt hallucinates progress. Guardrail: require a [PROGRESS_SNAPSHOT] input containing completed subtasks, pending items, and any error codes. Validate this snapshot exists before invoking the prompt.
Operational Risk: Token Budget Exhaustion During Recovery
Risk: the recovery prompt itself consumes significant context tokens analyzing the partial state, pushing the agent closer to its context limit. Guardrail: enforce a separate [RECOVERY_TOKEN_BUDGET] and abort recovery if the analysis alone exceeds 30% of remaining headroom. Fall back to a pre-written partial summary template.
Operational Risk: Repeated Timeout Loops
Risk: the recovery prompt recommends a retry with reduced scope, but the reduced scope also times out, creating a chain of recovery attempts. Guardrail: cap recovery depth at 2 attempts. On the third timeout, force escalation to a human operator or a dead-letter queue with the full trace attached.
Bad Fit: Real-Time User-Facing Latency Budgets
Avoid when: the end user is waiting synchronously and the timeout threshold is under 2 seconds. Guardrail: for synchronous user flows, precompute a static fallback response. Use the timeout recovery prompt only in asynchronous background agent loops where a 5-15 second recovery decision is acceptable.
Copy-Ready Prompt Template
A reusable prompt template for deciding how to handle an agent step that has exceeded its latency budget.
This template is designed to be inserted into your agent's error-handling middleware. When a step times out, the agent runtime should capture the step's objective, the partial output (if any), the elapsed time, and the remaining plan context. This prompt then forces a structured decision: accept the partial work, retry with a reduced scope, or escalate to a human or a parent orchestrator. The goal is to prevent the agent from silently hanging or burning tokens on a task that will never complete within its constraints.
textYou are a timeout recovery controller for an autonomous agent. A step has exceeded its maximum allowed execution time. Your job is to analyze the available evidence and output a strict JSON decision. Do not continue the original task. Do not fabricate missing results. [PLAN_CONTEXT] [STEP_OBJECTIVE] [PARTIAL_OUTPUT] [ELAPSED_TIME_MS] [TIMEOUT_BUDGET_MS] [RETRY_COUNT] [MAX_RETRIES] [DOWNSTREAM_DEPENDENCIES] [TOOLS_AVAILABLE] [CONSTRAINTS] Analyze the situation and output a single JSON object with the following schema: { "decision": "accept_partial" | "retry_reduced_scope" | "escalate", "confidence": 0.0-1.0, "rationale": "string explaining the decision with reference to specific evidence", "reduced_scope": { "new_objective": "string (only if decision is retry_reduced_scope)", "new_timeout_ms": number (only if decision is retry_reduced_scope) }, "partial_result_summary": "string describing what was completed before timeout (only if decision is accept_partial)", "escalation_reason": "string (only if decision is escalate)", "downstream_impact": ["list of affected downstream steps"], "missing_information": ["list of what we still don't know"] } Rules: - If [PARTIAL_OUTPUT] is empty or contains only an error, you cannot accept_partial. - If [RETRY_COUNT] >= [MAX_RETRIES], you cannot retry_reduced_scope. - If [DOWNSTREAM_DEPENDENCIES] includes critical path steps, escalate if confidence is below 0.7. - A reduced scope retry must request less work than the original [STEP_OBJECTIVE]. - Never invent data to fill gaps in [PARTIAL_OUTPUT].
To adapt this template, replace each square-bracket placeholder with data from your agent runtime. [PLAN_CONTEXT] should include the overall goal and completed steps. [PARTIAL_OUTPUT] is whatever the model or tool returned before the timeout fired—this could be a truncated JSON object, a partial text stream, or an empty string. The [DOWNSTREAM_DEPENDENCIES] field is critical: if the timed-out step is a prerequisite for a high-risk action, the prompt is instructed to escalate rather than silently degrade. Before deploying, test this prompt against three scenarios: a step that produced 80% of the expected output, a step that produced nothing, and a step that timed out on its final retry. Validate that the JSON output strictly conforms to the schema and that the decision rules are followed. For high-stakes workflows, route escalate decisions to a human review queue with the full trace attached.
Prompt Variables
Required inputs for the timeout recovery prompt. Each placeholder must be populated by the agent runtime before invoking the model. Missing or malformed inputs cause the prompt to produce unsafe recovery decisions.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[STEP_DESCRIPTION] | The original objective of the timed-out step | Fetch all open invoices from Stripe API for Q3 reconciliation | Must be non-empty string. Truncate at 500 chars to avoid context pollution |
[TIMEOUT_DURATION_MS] | The configured timeout threshold that was exceeded | 30000 | Must be positive integer. Validate against agent's max step timeout config. Reject if > 2x configured max |
[ELAPSED_MS] | Actual time elapsed before timeout fired | 31247 | Must be >= [TIMEOUT_DURATION_MS]. If less, timeout was premature; flag for infra investigation |
[PARTIAL_OUTPUT] | Any output produced before timeout, or null if none | {"invoices_fetched": 142, "cursor": "txn_2024..."} | Can be null. If non-null, must be valid JSON or plain text. Schema check against expected output shape before passing to prompt |
[STEP_CRITICALITY] | How essential this step is to overall plan completion | required | Must be one of: required, important, optional. Controls whether skip is ever allowed. Reject unknown values |
[RETRY_COUNT] | Number of times this step has already been retried | 2 | Must be non-negative integer. If >= max retry policy, prompt should default to escalate without model decision |
[REMAINING_TOKEN_BUDGET] | Estimated tokens remaining before context window exhaustion | 45000 | Must be positive integer. If < 5000, force accept-partial or escalate path regardless of model output |
[DOWNSTREAM_DEPENDENCIES] | List of subsequent steps that depend on this step's output | ["generate_report", "send_summary_email"] | Can be empty array. Each entry must match a valid step ID in the active plan. Used to assess cascade risk of skip vs escalate |
Implementation Harness Notes
How to wire the timeout recovery prompt into an agent runtime with validation, retries, and partial-output handling.
The timeout recovery prompt is not a standalone utility—it is a decision node inside an agent execution loop. Wire it into your agent runtime so that when a step exceeds its latency budget, the runtime captures the partial output, elapsed time, and remaining plan context, then invokes this prompt to decide the next action. The prompt expects structured inputs: the original step objective, the partial result (if any), the timeout threshold, the elapsed duration, the remaining token budget, and the downstream steps that depend on this step's output. Without these inputs, the model cannot reliably distinguish between a step that produced useful partial work and one that produced nothing salvageable.
Build a validation layer around the prompt's output before acting on it. The prompt returns a structured decision—accept_partial, retry_reduced_scope, or escalate—along with a rationale and, for retry decisions, a modified step specification with reduced constraints. Validate that the decision is one of the three allowed values, that a retry decision includes a concrete scope reduction (not just 'try again'), and that an escalate decision includes a specific reason a human or orchestrator can act on. If validation fails, default to escalation with the raw partial output attached. Log every timeout event with the prompt's input, output, validation result, and final action taken—these logs become your tuning dataset for adjusting timeout thresholds and scope-reduction strategies over time.
For production reliability, implement a circuit breaker around the recovery prompt itself. If the model call for recovery decision-making times out or returns malformed output, do not loop. Fall back to a hardcoded policy: accept partial results if they pass a minimum completeness check (e.g., at least one required field populated), otherwise escalate. Test this harness by simulating timeouts at different completion percentages—25%, 50%, 90%—and verifying that the system correctly distinguishes between salvageable partial work and unrecoverable failures. The most common production failure mode is accepting partial results that look structurally valid but are semantically empty; add a post-decision check that partial outputs contain substantive content, not just placeholder text or empty arrays.
Expected Output Contract
Fields, types, and validation rules for the structured recovery decision object returned by the Timeout Recovery Prompt. Use this contract to parse, validate, and route the model's output before executing any recovery action.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
recovery_action | enum: accept_partial | retry_reduced | escalate | abort | Must match exactly one of the four enum values. Reject any output with multiple actions or unrecognized strings. | |
partial_result_summary | string (max 500 chars) | true if action=accept_partial, else false | Must be non-empty when action is accept_partial. Must not fabricate data not present in [PARTIAL_OUTPUT]. Check for hallucinated completion claims. |
retry_scope | object with fields: reduced_steps (string[]), max_retry_duration_ms (int) | true if action=retry_reduced, else false | reduced_steps must be a subset of [REMAINING_STEPS]. max_retry_duration_ms must be less than [TIMEOUT_MS]. Reject if scope is identical to original remaining steps. |
escalation_reason | string (max 300 chars) | true if action=escalate, else false | Must reference specific evidence from [COMPLETED_STEPS] or [ERROR_CONTEXT]. Reject generic reasons like 'it failed' without trace evidence. |
confidence_score | float between 0.0 and 1.0 | Must be a number. Reject if missing. Flag for human review if score > 0.95 with action=escalate or score < 0.5 with action=accept_partial. | |
completed_artifacts | array of strings (artifact IDs) | Each ID must match an artifact_id present in [COMPLETED_STEPS]. Reject if any ID is fabricated. Empty array is valid if no steps completed. | |
unrecoverable_blockers | array of strings (max 5 items) | If present, each blocker must cite a specific step_id from [REMAINING_STEPS] or a tool name from [AVAILABLE_TOOLS]. Reject vague blockers like 'system error'. | |
recommended_follow_up | string (max 200 chars) or null | If non-null, must be an actionable instruction for the next agent or human operator. Reject if it restates the failure without a concrete next step. |
Common Failure Modes
Timeout recovery prompts fail in predictable ways. Here are the most common failure modes and how to guard against them in production.
Partial Output Fabrication
What to watch: The model invents plausible-sounding completions for steps that never executed, filling gaps with hallucinated data instead of marking them as incomplete. This is especially dangerous when partial results look convincing enough to pass cursory review. Guardrail: Require the prompt to output an explicit completed_steps array and unexecuted_steps array. Validate that claimed outputs correspond to steps in the completed list. Flag any output for a step not present in the completed array as a fabrication risk.
Over-Optimistic Progress Reporting
What to watch: The model reports steps as 'partially complete' when only trivial progress was made, inflating the apparent value of timed-out work. This leads downstream agents or users to trust incomplete results. Guardrail: Include a completion_confidence field (0.0-1.0) for each step. Define a minimum threshold below which steps are treated as unexecuted. Test with deliberately short timeouts to verify the model honestly reports low-confidence partial work.
Retry Scope Creep
What to watch: When the prompt recommends retrying with reduced scope, the new scope is still too large to complete within the remaining latency budget. This creates a cycle of repeated timeouts. Guardrail: Require the prompt to estimate token or time cost for the reduced-scope retry. Compare against remaining budget before accepting the recommendation. Implement a hard limit of one reduced-scope retry before forcing escalation or abort.
Escalation Avoidance
What to watch: The model avoids recommending escalation even when partial results are too incomplete to be useful, because escalation language in training data is often treated as a last resort. This buries unrecoverable failures under optimistic retry suggestions. Guardrail: Add an explicit escalation threshold in the prompt: 'If fewer than [MIN_COMPLETED_STEPS] steps completed or critical-path steps are missing, you must recommend escalation regardless of retry eligibility.' Test with scenarios where 80%+ of steps are unexecuted.
State Corruption on Partial Writes
What to watch: The agent wrote partial data to external systems before timing out, and the recovery prompt doesn't account for dirty state. Retry or continue decisions made without knowing what was persisted lead to duplicate writes or inconsistent state. Guardrail: Include a side_effects field in the prompt input that captures what external changes were confirmed before timeout. Require the recovery decision to explicitly address each side effect with a cleanup, idempotency, or verification action.
Timeout Simulation Drift
What to watch: The timeout scenarios used in testing don't match production timeout patterns. Tests use clean cutoffs at predictable points, but real timeouts happen mid-tool-call, during streaming, or after variable network delays. Guardrail: Build timeout simulation that injects failures at random points in execution, not just at step boundaries. Include mid-tool-call timeouts, partial-stream timeouts, and timeouts that occur during the recovery prompt's own execution. Validate that recovery logic handles all three.
Evaluation Rubric
Use this rubric to test the Timeout Recovery Prompt before deploying it in a production agent harness. Each criterion targets a specific failure mode common in partial-output recovery scenarios.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Partial output acceptance | Output explicitly lists completed items and flags [INCOMPLETE_ITEMS] without fabricating results for timed-out steps | Output contains data for steps that did not complete or hallucinates a final result | Simulate a timeout mid-execution with a known partial state; diff the output against the ground-truth partial state |
Retry vs. escalate decision | Decision field is exactly one of the allowed enum values: retry, reduce_scope, or escalate | Decision field is missing, null, or contains an unsupported value like continue or abort | Validate output against the [DECISION_ENUM] schema using a strict JSON Schema check |
Scope reduction logic | When decision is reduce_scope, the proposed [REDUCED_PLAN] contains a strict subset of the remaining [INCOMPLETE_ITEMS] | Reduced plan includes items already marked complete, adds new items, or is identical to the original remaining plan | Set up a scenario with 5 incomplete items; assert the reduced plan length is less than 5 and contains only items from the original set |
Budget awareness | Output references the remaining [TOKEN_BUDGET_REMAINING] or [LATENCY_BUDGET_REMAINING] and the recovery plan fits within it | Proposed retry or reduced plan ignores the budget and would certainly exceed the remaining allocation | Provide a budget of 2 seconds remaining; assert the recovery plan estimates fit within 2 seconds or escalates |
Evidence grounding | Every claim about what completed references a specific [COMPLETED_STEP_LOG] entry by step ID | Output describes completed work in vague terms without citing step IDs or log evidence | Inject a log with 3 completed steps; use a substring check to verify each completed item in the output maps to a log entry |
Escalation payload completeness | When decision is escalate, the [ESCALATION_PACKAGE] contains step_id, failure_reason, partial_output, and recommended_human_action | Escalation package is missing one or more required fields, or contains placeholder text instead of real values | Trigger an escalate decision; validate the escalation package against a required-fields schema |
No silent data loss | Output preserves all partial results from [COMPLETED_STEP_LOG] without truncation or omission | Completed step outputs are missing, truncated, or replaced with summaries that lose critical data | Compare the byte length and key field presence of the input completed log against the output partial results section |
Confidence calibration | Confidence score in [CONFIDENCE_SCORE] is between 0.0 and 1.0 and correlates with the amount of incomplete work | Confidence is 1.0 when 80% of steps timed out, or 0.0 when 90% completed successfully | Run 10 timeout scenarios with varying completion percentages; assert a negative Pearson correlation between completion percentage and confidence |
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
Use the base prompt with a simple timeout simulation harness. Focus on getting the decision logic right before adding production constraints. Replace [TIMEOUT_DURATION_MS] with a hardcoded value and [PARTIAL_RESULT_SCHEMA] with a loose JSON structure.
Watch for
- The model defaulting to 'retry' without checking partial results
- Missing timeout context in the prompt causing generic recovery suggestions
- Overly verbose recovery plans that waste tokens in fast-fail scenarios

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