Inferensys

Prompt

Partial Result Recovery Prompt for Incomplete Tool Outputs

A practical prompt playbook for using Partial Result Recovery Prompt for Incomplete Tool Outputs in production AI workflows.
Developer demonstrating multi-agent tool use, agent tool selection interface on laptop, casual tech demo moment.
PROMPT PLAYBOOK

When to Use This Prompt

Define the job, reader, and constraints for the Partial Result Recovery Prompt.

This prompt is for integration developers and reliability engineers who need to salvage usable data from a tool call that failed mid-execution, returned a truncated response, or produced malformed output. The job-to-be-done is extracting valid, structured fields from incomplete JSON, streaming chunks, or partially populated objects while explicitly flagging which required fields are missing or corrupted. Use this when a downstream system or user still needs a best-effort answer, and discarding the entire payload is more costly than working with partial data.

The ideal user has a tool output that failed validation or was cut off by a timeout, network interruption, or upstream error. They have the raw, incomplete payload and the expected output schema. The prompt requires three concrete inputs: the [INCOMPLETE_OUTPUT] string, the [EXPECTED_SCHEMA] defining required and optional fields, and any [ERROR_CONTEXT] such as the exception type or HTTP status code. Do not use this prompt when the tool output is completely empty, when the failure is an authentication or authorization error with no data returned, or when partial data could cause silent corruption in a financial, clinical, or safety-critical system without human review.

This prompt is a recovery step, not a replacement for retry logic or circuit breakers. It should be wired into a tool execution harness that first attempts retries for transient failures, then invokes this prompt only when a retry budget is exhausted and partial data is acceptable. The output must be validated against the schema before being passed downstream. For high-risk domains, route the recovered output to a human approval queue with a clear summary of what was recovered, what is missing, and what the original error was. Never silently substitute partial data for complete data in audit trails or compliance records.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Partial Result Recovery Prompt works and where it introduces unacceptable risk. This prompt is designed for integration developers who must extract value from incomplete tool outputs, but it is not a substitute for proper error handling or idempotent retries.

01

Good Fit: Streaming or Chunked Responses

Use when: A tool returns a partial JSON array or streaming chunks before a connection reset or timeout. Guardrail: The prompt must be paired with a structural validator that confirms the extracted subset matches the expected schema before passing it downstream.

02

Good Fit: Truncated Logs or Reports

Use when: A large diagnostic output or report is cut off by a token limit or tool output cap. Guardrail: The prompt should flag the truncation point and estimate the percentage of missing data. Downstream systems must treat the output as a partial summary, not a complete record.

03

Bad Fit: Financial or Compliance Reconciliation

Avoid when: The task requires a provably complete dataset, such as transaction reconciliation or audit evidence. Guardrail: In these cases, a partial result is a failed result. The system must abort and escalate for human review rather than attempt field extraction from incomplete data.

04

Bad Fit: Non-Idempotent Write Operations

Avoid when: The tool call performed a state-changing action (e.g., POST, DELETE) and returned a partial success response. Guardrail: Do not use this prompt to guess the server-side state. Instead, use an idempotency check prompt and a separate state-verification tool call before proceeding.

05

Required Input: A Strict Output Schema

Risk: Without a defined schema, the model may hallucinate missing fields to produce a 'complete' looking object. Guardrail: The prompt template requires a [REQUIRED_SCHEMA] variable. The recovery output must explicitly list which required fields are missing or null, preventing silent data gaps.

06

Operational Risk: Masking Systemic Failures

Risk: Over-reliance on partial recovery can hide a systemic tool degradation problem from operators. Guardrail: Every invocation of this prompt must increment a partial_recovery_used metric and log the original error. If the recovery rate exceeds a threshold, a circuit breaker should open to force investigation.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A reusable prompt that extracts usable fields from incomplete tool outputs, flags missing required data, and assesses corruption risk.

The following prompt template is designed to be inserted into an agent's recovery path immediately after a tool call returns a partial, truncated, or malformed response. It instructs the model to salvage what it can, identify what is missing, and produce a structured assessment that downstream logic can act on—whether that means proceeding with degraded data, retrying with modified parameters, or escalating for human review. The template uses square-bracket placeholders that your application must populate before sending the request to the model.

text
You are a partial result recovery specialist. A tool call returned incomplete or corrupted output. Your job is to extract every usable field, identify what is missing, and assess whether the partial result is safe to use downstream.

## CONTEXT
- Tool name: [TOOL_NAME]
- Tool description: [TOOL_DESCRIPTION]
- Expected output schema: [OUTPUT_SCHEMA]
- Required fields (must be present for downstream use): [REQUIRED_FIELDS]
- Optional fields (nice to have): [OPTIONAL_FIELDS]
- Error or interruption context: [ERROR_CONTEXT]
- Previous successful output shape (if available): [PREVIOUS_OUTPUT_EXAMPLE]

## RAW TOOL OUTPUT

[RAW_TOOL_OUTPUT]

code

## INSTRUCTIONS
1. Parse the raw tool output and extract every field that matches the expected output schema, even if partially populated.
2. For each field in the schema, report:
   - `field`: the field name
   - `status`: one of `complete`, `partial`, `truncated`, `corrupted`, `missing`
   - `extracted_value`: the value you recovered, or null if unrecoverable
   - `confidence`: 0.0 to 1.0 indicating how confident you are that the extracted value is correct
   - `issue`: description of any problem with the field, or null if none
3. Flag any data that appears corrupted (encoding errors, mid-field truncation, structural breaks, inconsistent types).
4. Determine whether all required fields are present with confidence >= [MIN_CONFIDENCE_THRESHOLD].
5. Assess overall output safety: can the partial result be used downstream, or must it be discarded?

## OUTPUT FORMAT
Return a JSON object with this exact structure:
{
  "tool_name": "string",
  "recovery_timestamp": "ISO 8601",
  "overall_completeness": 0.0-1.0,
  "required_fields_satisfied": true/false,
  "safe_for_downstream_use": true/false,
  "safety_rationale": "string explaining the decision",
  "fields": [
    {
      "field": "string",
      "status": "complete|partial|truncated|corrupted|missing",
      "extracted_value": any or null,
      "confidence": 0.0-1.0,
      "issue": "string or null"
    }
  ],
  "corruption_indicators": ["string"],
  "recommended_action": "proceed_degraded|retry|retry_with_modified_args|fallback|escalate_to_human|discard",
  "retry_suggestions": {
    "modified_args": {},
    "reason": "string or null"
  }
}

## CONSTRAINTS
- Never invent data to fill missing fields. Use null when a value cannot be recovered.
- If the raw output contains multiple records or streaming chunks, consolidate them before field extraction.
- Flag encoding errors (mojibake, invalid UTF-8 sequences, binary artifacts) as corruption.
- If a field is present but its type does not match the expected schema, mark it as `corrupted`.
- Do not trust field ordering in truncated output; validate each field independently.

To adapt this template for your system, replace each bracketed placeholder with live data from your agent's execution context. [OUTPUT_SCHEMA] should contain a JSON Schema or a clear field-by-field description of what the tool is expected to return. [REQUIRED_FIELDS] is the subset of fields that downstream logic cannot function without—this is your circuit breaker. [MIN_CONFIDENCE_THRESHOLD] should be tuned per workflow: 0.9 for financial data, 0.7 for informational summaries, and 0.5 or lower only when partial data is strictly better than nothing. The [ERROR_CONTEXT] placeholder should include the exception type, status code, or interruption reason so the model can correlate specific failures with specific field damage. If your tool returns streaming chunks, concatenate them into [RAW_TOOL_OUTPUT] before invoking this prompt; the model's consolidation instruction handles chunk boundaries but cannot reassemble fragments you haven't provided.

Before deploying this prompt into a production recovery path, wire the output through a schema validator that enforces the JSON structure described in the OUTPUT FORMAT block. A common failure mode is the model producing a correct assessment but omitting the retry_suggestions object or using a non-enum value for recommended_action. Post-process the safe_for_downstream_use boolean against your own business rules—the model may be optimistic about degraded data that your system cannot safely consume. For high-risk domains, route any output where required_fields_satisfied is false or overall_completeness is below your threshold to a human review queue before allowing downstream consumption.

IMPLEMENTATION TABLE

Prompt Variables

Required and optional inputs for the Partial Result Recovery Prompt. Each placeholder must be populated before the prompt is assembled. Validation notes describe how to check the input before sending it to the model.

PlaceholderPurposeExampleValidation Notes

[TOOL_NAME]

Identifies the tool that produced the partial output for context and logging

salesforce_query_tool

Must be a non-empty string matching a registered tool name in the agent registry

[EXPECTED_SCHEMA]

Defines the complete output contract the tool should have fulfilled

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

Must be valid JSON Schema; validate with a schema parser before prompt assembly

[PARTIAL_OUTPUT]

The incomplete, truncated, or partially corrupted tool response to recover

{"id":"ord-8821","status":"shipped","line_items":[{"sku":"A1","qty":2},{"sku":"B3"

Must be a non-empty string; check for parseable fragments and total byte length before sending

[ERROR_CONTEXT]

The error message, code, or exception that accompanied the partial output

{"error_code":"STREAM_TRUNCATED","bytes_received":2048,"bytes_expected":4096,"message":"Connection closed before response complete"}

Must be a valid JSON object with at least an error_code field; null allowed if no error metadata is available

[REQUIRED_FIELDS]

The subset of fields from the expected schema that are mandatory for downstream processing

["id","status","line_items"]

Must be a JSON array of strings; each string must exist in the EXPECTED_SCHEMA required or properties list

[CORRUPTION_INDICATORS]

Known patterns that signal data corruption in the partial output

["unmatched_quotes","truncated_array","invalid_utf8_sequence","missing_closing_brace"]

Must be a JSON array of strings drawn from a predefined corruption indicator taxonomy; empty array allowed

[RECOVERY_STRATEGY_HINT]

Optional instruction for how aggressively to recover versus flag as unrecoverable

prefer_partial_over_rejection

Must be one of an enum: prefer_partial_over_rejection, strict_completeness_only, or conservative_flag_all; default to conservative_flag_all if omitted

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the Partial Result Recovery Prompt into a production tool-calling loop with validation, retry integration, and safe downstream consumption.

The Partial Result Recovery Prompt is not a standalone module; it is a recovery interceptor that sits between a failed or incomplete tool call and the rest of your agent's execution context. When a tool returns a 200 OK with a truncated JSON body, a streaming response that closed early, or a batch result where only 7 of 10 requested records arrived, this prompt extracts what is usable and flags what is missing. Wire it into your tool execution harness as a post-processing step that fires when the tool's output fails a completeness check but is not entirely empty. The prompt expects the raw partial output, the expected schema or field list, and any error metadata the tool provided. It returns a structured recovery payload: usable_fields, missing_required_fields, corruption_flags, and a confidence_score that downstream logic can threshold against.

Integration pattern: In your tool execution wrapper, after catching a PartialResultError or detecting a schema validation failure, call this prompt with the raw output and the tool's contract. Use the returned confidence_score to decide whether to pass the recovered data forward. For example, if the score is above 0.85 and no missing_required_fields are critical, inject the usable_fields into the agent's context with a clear [PARTIAL RESULT] prefix. If the score is below 0.5 or critical fields are missing, route to the Retry Decision Prompt or the Fallback Tool Selection Prompt instead. Validation layer: Before the recovered output re-enters the agent's context, run a schema validator against the usable_fields to confirm they match the expected types and constraints. Log every recovery event with the original error, the prompt's output, and the validator's pass/fail result. This audit trail is essential for debugging silent data corruption in multi-step agent workflows.

Model choice and latency: This prompt is a recovery path, not the happy path. It should be fast and cheap. Use a lightweight model (e.g., a small fast variant) for this classification and extraction task unless the tool output contains complex nested structures that require stronger reasoning. Set a short timeout—if the recovery prompt itself times out, treat the tool output as unrecoverable and escalate to the Retry Budget Exhaustion Escalation Prompt. What to avoid: Do not pass the raw partial output directly into the agent's main reasoning context without this recovery step. Partial JSON, truncated arrays, and mid-stream fragments cause the agent to hallucinate missing data or silently proceed with corrupted state. Also avoid using this prompt as a substitute for proper tool output validation on successful calls—it is designed for incomplete outputs, not for normalizing valid but messy responses.

IMPLEMENTATION TABLE

Expected Output Contract

Defines the structured output fields, types, and validation rules for the Partial Result Recovery Prompt. Use this contract to parse the model's response and decide whether the recovered output is safe for downstream consumption.

Field or ElementType or FormatRequiredValidation Rule

recovered_data

object

Must be a valid JSON object. Cannot be null. If no fields are recoverable, return an empty object {}.

recovered_data.[FIELD_NAME]

any

Each key must match a field from [EXPECTED_SCHEMA]. Value type must match the expected type in [EXPECTED_SCHEMA].

missing_required_fields

array of strings

Must be a JSON array. Each element must be a string matching a required field name from [EXPECTED_SCHEMA] that could not be recovered. Empty array if all required fields are present.

corruption_flags

array of objects

Must be a JSON array. Each object must have 'field' (string), 'issue' (string enum: 'truncated', 'type_mismatch', 'encoding_error', 'invalid_value'), and 'detail' (string). Empty array if no corruption detected.

completeness_score

number

Must be a float between 0.0 and 1.0. Represents the fraction of [EXPECTED_SCHEMA] fields successfully recovered. 1.0 indicates full recovery.

confidence_assessment

string

Must be one of: 'high', 'medium', 'low'. Determined by completeness_score and presence of corruption_flags. 'low' if completeness_score < [CONFIDENCE_THRESHOLD] or corruption_flags is non-empty.

recovery_method

string

Must be one of: 'json_parse_partial', 'stream_chunk_assembly', 'regex_extraction', 'key_value_heuristic', 'none'. Describes the primary technique used to extract data from the [INCOMPLETE_OUTPUT].

recovery_note

string or null

A human-readable summary of what was recovered, what is missing, and any assumptions made. Null if recovery_method is 'none' and no data was extracted.

PRACTICAL GUARDRAILS

Common Failure Modes

What breaks first when recovering partial results from incomplete tool outputs, and how to guard against it in production.

01

Silent Data Corruption in Partial Payloads

Risk: The model accepts a truncated JSON object or streaming chunk without detecting missing closing braces, broken strings, or incomplete arrays, then treats the corrupted data as valid. Guardrail: Implement a structural integrity check before the prompt processes the payload. Validate JSON syntax, bracket matching, and string termination. If the payload is malformed, feed the raw bytes and error to the prompt with an explicit instruction to flag corruption before extraction.

02

Hallucinated Fills for Missing Required Fields

Risk: When the prompt encounters a required field that is missing from the partial output, it invents a plausible value instead of flagging it as absent. This is common when the prompt prioritizes producing a complete output over an honest one. Guardrail: Provide an explicit [REQUIRED_FIELDS] schema in the prompt. Instruct the model to set missing required fields to null and populate a separate missing_required_fields array. Validate this array in post-processing before allowing downstream consumption.

03

Confidence Inflation on Recovered Data

Risk: The model assigns high confidence to fields extracted from a damaged payload because it successfully parsed them, ignoring the underlying corruption context. Downstream systems then trust low-integrity data. Guardrail: Require the prompt to output a recovery_confidence score (0.0–1.0) for the entire payload and per-field confidence for critical fields. Set a system threshold below which the output is routed to a dead-letter queue for human review rather than consumed automatically.

04

Schema Drift After Partial Recovery

Risk: The model successfully extracts fields from the incomplete output but changes their types (e.g., string to number, object to array) to fit the requested schema, causing downstream parsing failures. Guardrail: Include a strict [OUTPUT_SCHEMA] with explicit types and a post-extraction validation step. Instruct the prompt to coerce nothing and to place any value that fails type matching into an unrecoverable_fields object with the original value and a reason for rejection.

05

Infinite Retry on Unrecoverable Corruption

Risk: The recovery prompt succeeds in extracting some fields, but the overall payload is too damaged. Without a stop condition, the orchestrator retries the prompt repeatedly, burning tokens and latency. Guardrail: Define a minimum completeness threshold (e.g., 70% of required fields recovered). If the prompt's output falls below this threshold, bypass further retries and escalate to a human operator or a dead-letter queue with the raw payload and recovery attempt log attached.

06

Context Window Overflow from Raw Error Dumps

Risk: The raw tool output is large, and the error context plus the partial payload exceeds the model's context window when combined with the recovery instructions. The prompt is truncated, losing critical recovery logic. Guardrail: Pre-process the input. Truncate the raw payload to a safe token limit before handing it to the prompt, preserving the head and tail of the data where structural breaks are most visible. Include a truncation_applied boolean in the prompt input so the model knows the data is incomplete.

IMPLEMENTATION TABLE

Evaluation Rubric

Use this rubric to evaluate the quality of a partial result recovery prompt before deploying it in a production agent. Each criterion targets a specific failure mode common to incomplete tool outputs.

CriterionPass StandardFailure SignalTest Method

Field Extraction Accuracy

All usable fields from a truncated JSON payload are correctly extracted into the [OUTPUT_SCHEMA] without hallucinated values.

A field appears in the output that was not present in the partial input, or a present field is assigned a fabricated value.

Provide a deliberately truncated JSON object with 3 known fields. Assert that only those 3 fields are populated and their values match the source exactly.

Missing Field Flagging

Every required field in [OUTPUT_SCHEMA] that is absent from the partial input is flagged with a missing: true marker and a null value.

A required field is absent from the partial input but is not flagged as missing, or is silently populated with a default value.

Provide a partial input missing a top-level required field. Parse the output and assert that the field's missing attribute is true and its value is null.

Corruption Detection

The prompt identifies and quarantines any field containing unparseable data (e.g., a truncated string inside a numeric field) into a corrupted_fields array.

Corrupted data is silently coerced into a wrong type or omitted without being logged in the corruption report.

Inject a string value like 'INCOMPLETE_DA' into a numeric field. Assert the field is listed in the corrupted_fields output array and excluded from the main structured output.

Confidence Scoring

A confidence_score between 0.0 and 1.0 is returned, reflecting the proportion of required fields successfully recovered.

The confidence score is 1.0 when required fields are missing, or 0.0 when most data is intact.

Provide a partial input with 4 of 5 required fields. Assert the confidence_score is approximately 0.8. Provide an input with 0 of 5 required fields and assert the score is 0.0.

Streaming Chunk Assembly

Multiple streaming chunks are correctly concatenated and parsed as a single partial JSON structure, preserving field order.

Chunks are parsed individually, causing duplicate keys or an unparseable final structure.

Simulate a stream by providing 3 sequential string chunks that form a valid JSON object when combined. Assert the final output contains the complete, correctly merged object.

Truncation Boundary Handling

A string value cut off mid-word is recovered as-is without hallucinating a completion.

The model 'completes' a truncated string (e.g., 'San Franc' becomes 'San Francisco').

Provide a JSON object where a city field has the value 'San Franc'. Assert the recovered value is exactly 'San Franc' and not an inferred completion.

Error Context Preservation

The original error message or status code from the tool is included in the recovery_metadata output field.

The recovery output contains no reference to the original error, making root cause analysis impossible.

Provide a partial input alongside a simulated tool error message 'TIMEOUT_ERROR'. Assert that 'TIMEOUT_ERROR' is present in the recovery_metadata.error_context field of the output.

Schema Adherence Under Stress

The final output strictly conforms to the defined [OUTPUT_SCHEMA], even when the input is 90% corrupted.

The model abandons the output schema and returns a free-text error description or an empty object.

Provide a malformed input that is 90% unparseable garbage. Assert the output is still a valid instance of [OUTPUT_SCHEMA] with all fields marked as missing or corrupted.

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with a simplified output schema. Focus on extracting any usable fields from the partial response without strict completeness checks. Accept a best-effort JSON object with a recovered_fields map and a missing_fields list. Skip confidence scoring and corruption detection initially.

code
Extract all readable fields from this partial tool output:
[PARTIAL_OUTPUT]

Return a JSON object with:
- recovered_fields: { field_name: value }
- missing_fields: [ field_name ]

Watch for

  • Accepting malformed values as valid without type checking
  • Missing nested fields that are partially present
  • No distinction between empty fields and truly missing fields
  • Overly permissive extraction that pulls in error text as data
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.