Inferensys

Prompt

Agent Error Reporting Message Prompt

A practical prompt playbook for SRE teams and platform engineers standardizing how agents communicate failures. Produces structured error payloads with error codes, stack context, retry eligibility, and escalation paths.
Compliance team using AI for regulatory reporting on laptop, SEC templates visible, modern office desk setup.
PROMPT PLAYBOOK

When to Use This Prompt

Standardize how every agent in a multi-agent system reports failures to an orchestrator, message bus, or dead-letter queue.

This prompt is for SRE teams and platform engineers who need every agent in a multi-agent system to report failures in a consistent, machine-readable format. Use it when an agent encounters an error during task execution and must communicate that failure to an orchestrator, a message bus, a dead-letter queue, or a human operator. The prompt produces a structured error payload that downstream systems can parse, route, and act on without manual interpretation. Do not use this prompt for successful task completion notifications, progress updates, or health checks. Those require separate payload schemas with different required fields and semantics.

The ideal user is an integration engineer or platform builder who already has an agent communication bus and needs a single, enforceable error contract. The required context includes the agent's role, the task it was attempting, the raw error or exception, and any relevant correlation IDs. The prompt forces the agent to categorize the failure (e.g., TRANSIENT, PERMANENT, POLICY_VIOLATION), declare retry eligibility, and suggest an escalation path. This removes ambiguity from error handling: a downstream orchestrator can branch on the error_category field instead of parsing free-text logs. For high-risk domains like finance or healthcare, the prompt also requires an evidence_snapshot field so human reviewers can see exactly what the agent saw before it failed.

Before using this prompt, confirm that your agent framework can capture structured error context at the point of failure. If your agents only produce unstructured stack traces, you will need to wrap their execution in a harness that catches exceptions and injects them into this prompt. Also avoid using this prompt for warnings or non-fatal anomalies—those should use a separate Agent Warning Notification schema to prevent alert fatigue. Once you have a validated error payload, route it to your dead-letter queue, incident management system, or human review dashboard based on the escalation_path field.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Agent Error Reporting Message Prompt delivers value and where it introduces risk. Use these cards to decide whether this prompt fits your operational context before wiring it into an agent communication bus.

01

Good Fit: Standardized Multi-Agent Platforms

Use when: You operate a platform with 3+ specialized agents that must communicate failures through a shared message bus. Why it works: The prompt enforces a single error schema, preventing each agent from inventing its own error format and causing downstream parsing failures.

02

Bad Fit: Single-Agent or Monolithic Systems

Avoid when: You have a single agent handling end-to-end execution with no inter-agent communication. Risk: Introducing structured error payloads adds schema maintenance overhead without the coordination benefit. Use application-level error handling instead.

03

Required Inputs: Error Context and Agent Identity

Prerequisites: The prompt requires the failing agent's role identifier, the original task context, the error category, and the raw error trace. Guardrail: Validate that all required fields are populated before sending; missing agent identity produces untraceable errors in multi-agent logs.

04

Operational Risk: Retry Storm Amplification

What to watch: If the retry eligibility field is set too permissively, a single root-cause failure can trigger cascading retries across multiple agents. Guardrail: Enforce a maximum retry count and a global retry budget at the orchestration layer, not just in the error payload.

05

Operational Risk: Escalation Path Staleness

What to watch: Hardcoded escalation targets in error payloads become stale as teams reorganize or on-call rotations change. Guardrail: Resolve escalation paths dynamically at send time from a live service registry rather than baking them into the prompt template or agent configuration.

06

Operational Risk: Error Categorization Drift

What to watch: Agents may miscategorize novel failures into overly generic buckets like 'UNKNOWN_ERROR', defeating downstream routing and alerting. Guardrail: Run periodic eval suites that inject known failure modes and measure categorization accuracy. Flag categories with >5% misclassification for prompt refinement.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A copy-ready prompt for generating a structured agent error report, ready to be wired into an agent communication bus.

This prompt template instructs a model to act as an error-reporting agent. It takes raw failure context from a source agent and produces a structured error payload that downstream systems—such as orchestrators, retry queues, or human review dashboards—can parse reliably. The template is designed to be used within a multi-agent system where ad-hoc error strings are not acceptable and every failure must carry enough metadata for automated triage.

text
SYSTEM:
You are an Agent Error Reporter. Your only job is to convert raw agent failure information into a structured error report that follows the exact schema and constraints provided. Do not attempt to fix the error. Do not speculate about root causes beyond what is in the input context. If required fields are missing from the input, mark the report as incomplete and set the error code to `INCOMPLETE_INPUT`.

USER MESSAGE:
Generate a structured error report from the following failure context.

FAILURE CONTEXT:
[FAILURE_CONTEXT]

SOURCE AGENT ID: [SOURCE_AGENT_ID]
TARGET AGENT ID: [TARGET_AGENT_ID]
CORRELATION ID: [CORRELATION_ID]

OUTPUT SCHEMA (JSON):
{
  "error_report": {
    "report_id": "string, unique identifier for this error report",
    "timestamp": "string, ISO 8601 UTC timestamp of report generation",
    "source_agent_id": "string",
    "target_agent_id": "string",
    "correlation_id": "string",
    "error_code": "string, from the approved error code enumeration",
    "severity": "string, one of: CRITICAL, HIGH, MEDIUM, LOW",
    "retry_eligibility": {
      "retryable": "boolean",
      "max_retries": "integer, 0 if not retryable",
      "retry_strategy": "string, one of: IMMEDIATE, EXPONENTIAL_BACKOFF, FIXED_DELAY, NONE",
      "suggested_delay_seconds": "integer"
    },
    "escalation_path": "string, one of: HUMAN_REVIEW, FALLBACK_AGENT, DEAD_LETTER_QUEUE, NONE",
    "stack_context": {
      "failed_operation": "string, the specific operation that failed",
      "input_summary": "string, brief summary of the input that caused the failure",
      "observed_error": "string, the raw error message or symptom",
      "agent_state_at_failure": "string, what the agent was doing when it failed"
    },
    "evidence": [
      {
        "type": "string, one of: LOG, TOOL_OUTPUT, MESSAGE, TRACE",
        "content": "string, the evidence snippet"
      }
    ],
    "incomplete": "boolean, true if required input fields were missing"
  }
}

CONSTRAINTS:
- Use only the approved error codes: TIMEOUT, TOOL_FAILURE, SCHEMA_VIOLATION, PERMISSION_DENIED, RATE_LIMITED, INVALID_INPUT, AGENT_UNAVAILABLE, INCOMPLETE_INPUT, UNKNOWN.
- If the failure context does not contain enough information to determine retry_eligibility, set retryable to false and escalation_path to HUMAN_REVIEW.
- Never invent evidence. Only include evidence items that are explicitly present in the failure context.
- If the failure context is empty or missing, return an error report with error_code INCOMPLETE_INPUT and incomplete set to true.

Adaptation notes: Replace [FAILURE_CONTEXT] with the raw error output, tool response, or exception message from the failing agent. [SOURCE_AGENT_ID] and [TARGET_AGENT_ID] should come from your agent registry. [CORRELATION_ID] must match the trace ID used across your agent message bus. The error code enumeration and severity levels should be aligned with your organization's incident response taxonomy. Before deploying, validate that the output JSON parses correctly and that the error_code field matches one of the approved values—schema validation should be applied at the application layer, not trusted to the model alone.

IMPLEMENTATION TABLE

Prompt Variables

Inputs the Agent Error Reporting Message Prompt needs to produce a structured, actionable error payload. Validate each placeholder before calling the model to prevent malformed error reports and silent failures in agent communication.

PlaceholderPurposeExampleValidation Notes

[ERROR_SOURCE_AGENT]

Identifies the agent that encountered the failure

data-fetcher-v2

Must match a registered agent ID in the system registry; reject if null or unrecognized

[ERROR_CODE]

Machine-readable error category for routing and retry logic

TOOL_TIMEOUT

Must match an entry in the approved agent status code enumeration; reject unknown codes

[ERROR_SEVERITY]

Indicates impact level for escalation decisions

CRITICAL

Must be one of: CRITICAL, HIGH, MEDIUM, LOW; reject if missing or invalid

[FAILED_OPERATION]

Description of the specific operation that failed

fetch_user_profile(api_call)

Must be a non-empty string under 200 characters; reject if generic or missing

[STACK_CONTEXT]

Serialized snapshot of agent state at failure time

{"task_id": "t-442", "step": 3}

Must be valid JSON; parse and reject if malformed or exceeds 2KB size limit

[RETRY_ELIGIBILITY]

Boolean flag indicating if the operation can be safely retried

Must be true or false; reject if null or non-boolean; if true, [RETRY_STRATEGY] must also be provided

[ESCALATION_PATH]

Target agent, human queue, or fallback for unresolved errors

human-ops-tier2

Must reference a valid escalation target from the system routing table; reject if null or unregistered

[ERROR_TIMESTAMP]

UTC timestamp of when the error was detected

2025-03-15T14:32:00Z

Must be ISO 8601 UTC format; reject if in the future or unparseable

PROMPT PLAYBOOK

Implementation Harness Notes

Wire the error reporting prompt into your agent framework with validation, retry logic, and escalation routing.

The error reporting prompt must be integrated into the agent's execution wrapper, not called as an afterthought. Wrap every agent task execution in a try-catch block. In the catch path, invoke the model call with the error context, agent state, and correlation ID. If the model call itself fails—due to a network error, rate limit, or model unavailability—fall back to a minimal static error payload. That fallback must include at least the error_id, correlation_id, agent_id, error_category set to INFRASTRUCTURE, and a sanitized error_message derived from the caught exception type. Never expose raw stack traces in the fallback payload; log them internally and replace the external-facing message with a generic description such as 'Internal agent error during error reporting.'

After the model returns a structured error payload, validate it against the expected schema before publishing it to the message bus. Check that all required fields are present, enums match allowed values, and the error_category is one of the defined levels (e.g., TRANSIENT, RECOVERABLE, CRITICAL, INFRASTRUCTURE). If validation fails, log the malformed payload with its correlation ID and fall back to the static error payload. Route the validated payload based on severity: if error_category is CRITICAL or the retry_count exceeds the configured maximum (e.g., 3), publish directly to the escalation target—typically a human review queue, a PagerDuty incident, or a dead-letter topic. For non-critical errors with remaining retries, publish to the retry queue with retry_count incremented by one and the original correlation_id preserved for trace continuity.

Log every generated error report—whether model-produced or fallback—with its correlation ID, timestamp, agent ID, and error category. This creates an audit trail for debugging agent chains and measuring error reporting accuracy. In production, monitor the ratio of fallback payloads to model-generated payloads; a rising fallback rate signals model endpoint instability or prompt drift. Also track the distribution of error categories to identify whether agents are failing due to transient infrastructure issues or recoverable logic errors. For high-risk domains, consider adding a human review step before escalation payloads are delivered, especially when the error involves sensitive data or regulated actions. The goal is a harness that fails safely, communicates clearly, and never leaves an agent failure unlogged or misrouted.

IMPLEMENTATION TABLE

Expected Output Contract

The model must return a single JSON object conforming to this schema. Reject any output that does not parse or that violates these constraints.

Field or ElementType or FormatRequiredValidation Rule

error_id

string (UUID v4)

Must parse as valid UUID v4. Reject if missing or malformed.

error_code

string (enum)

Must match one of: AGENT_UNAVAILABLE, TOOL_FAILURE, TIMEOUT, INVALID_STATE, PERMISSION_DENIED, INPUT_VALIDATION_ERROR, INTERNAL_ERROR, DEPENDENCY_FAILURE. Reject unknown codes.

severity

string (enum)

Must be one of: CRITICAL, HIGH, MEDIUM, LOW. Reject if missing or invalid.

retry_eligible

boolean

Must be true or false. If true, retry_strategy must be present.

retry_strategy

object | null

Required when retry_eligible is true. Must contain max_retries (integer >= 0) and backoff_seconds (integer >= 0). Null allowed when retry_eligible is false.

escalation_path

string (enum)

Must be one of: HUMAN_REVIEW, FALLBACK_AGENT, DEAD_LETTER_QUEUE, NONE. Reject unknown paths.

source_agent_id

string

Must be a non-empty string matching the reporting agent's registered identifier. Reject empty or whitespace-only.

timestamp

string (ISO 8601 UTC)

Must parse as valid ISO 8601 datetime in UTC with timezone offset Z. Reject if unparseable or missing timezone.

PRACTICAL GUARDRAILS

Common Failure Modes

Agent error reporting fails silently when payloads are malformed, codes are ambiguous, or escalation paths are missing. These are the most common production failure modes and how to prevent them.

01

Error Code Collision and Ambiguity

Risk: Multiple agents reuse the same error code for different failure modes, making automated routing impossible. TIMEOUT might mean a tool timeout, an agent timeout, or a message bus timeout. Guardrail: Use a namespaced error taxonomy with agent, domain, and specific failure codes. Validate against the shared status code enumeration before deployment.

02

Missing Escalation Path in Payload

Risk: An agent reports an error but omits the escalation_target or retry_strategy fields. The orchestrator cannot decide whether to retry, escalate to a human, or route to a fallback agent. Guardrail: Require escalation_path and retry_eligibility as mandatory fields in the error schema. Reject payloads that lack them at the message validation layer.

03

Stack Context Leakage

Risk: Error payloads include raw stack traces, internal tool outputs, or unredacted user data that leaks across agent boundaries into logs or downstream agents. Guardrail: Strip raw stack details at the agent boundary. Replace with a structured failure_context object containing only sanitized component, operation, and failure_reason fields.

04

Silent Parsing Failures on Receipt

Risk: The receiving agent or orchestrator fails to parse the error payload due to schema drift or malformed JSON but swallows the exception, treating the task as still in progress. Guardrail: Implement a strict validation layer that checks every incoming error message against the shared schema. On parse failure, immediately escalate to a dead-letter queue with the raw payload preserved.

05

Retry Eligibility Misclassification

Risk: Transient failures are marked as fatal, or permanent failures are marked as retryable, causing either abandoned work or infinite retry loops. Guardrail: Include a retry_eligibility enum with values RETRYABLE, RETRYABLE_WITH_BACKOFF, and FATAL. Validate that FATAL errors always include an escalation_target and never trigger automated retries.

06

Correlation Chain Breakage

Risk: The error payload lacks a correlation_id or causation_id, breaking the trace across agent boundaries. Operators cannot reconstruct which upstream task caused the failure. Guardrail: Require correlation_id and causation_id in every error payload. Validate that the causation_id references a known upstream message or task ID before accepting the error report.

IMPLEMENTATION TABLE

Evaluation Rubric

Run these checks against a golden dataset of 20 known failure scenarios to validate the Agent Error Reporting Message Prompt before deployment.

CriterionPass StandardFailure SignalTest Method

Error Code Categorization Accuracy

Error code matches the ground-truth category for the given stack trace and context

Mismatched or generic fallback code (e.g., UNKNOWN_ERROR) when a specific code exists

Run 20 labeled failure scenarios; measure exact match and macro-F1 against golden codes

Retry Eligibility Flag Correctness

Retryable flag is true for transient errors (timeouts, rate limits) and false for permanent errors (validation, auth)

Retryable=true for a 4xx auth error or retryable=false for a 503 with Retry-After header

Binary classification test on 10 transient and 10 permanent error cases; require 100% accuracy

Escalation Path Validity

Escalation target matches the predefined routing table for the error category and severity

Escalation to wrong team (e.g., auth error routed to infrastructure instead of IAM)

Validate against a static escalation routing table; 0 routing violations allowed

Payload Schema Compliance

Output is valid JSON matching the [ERROR_PAYLOAD_SCHEMA] with all required fields present

Missing required field (e.g., error_id, timestamp) or wrong type (string instead of array for stack_trace)

JSON Schema validation with strict mode; reject on additionalProperties or missing required fields

Stack Context Completeness

Stack trace includes the top 3 frames from the original error, file paths, and line numbers

Truncated stack trace, missing line numbers, or generic 'internal error' without source location

Compare extracted frames against original error input; require at least 3 frames with file:line format

Severity Level Assignment

Severity matches the defined SRE severity matrix based on error type, scope, and user impact

P0 severity assigned to a single-user validation error or P4 assigned to a full service outage

Run 10 severity-labeled scenarios; require exact match on all or flag for human review if confidence < 0.9

Correlation ID Propagation

Output includes the [CORRELATION_ID] from the input context without modification

Missing correlation_id, truncated value, or new ID generated instead of propagating the original

String equality check between input [CORRELATION_ID] and output correlation_id field

Human-Readable Summary Quality

Summary contains actionable description with error type, affected component, and immediate next step in under 200 characters

Vague summary like 'something went wrong' or summary exceeding 500 characters with irrelevant details

LLM-as-judge evaluation against 3 criteria: actionability, component identification, length constraint; pass threshold >= 4/5

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Add strict JSON schema validation on the output payload before publishing to the agent message bus. Include a correlation ID from the originating agent's context, a full error code taxonomy with severity levels, and a structured escalation_path field. Wire in retry logic: if retry_eligible: true, include retry_after_seconds and max_retries fields. Log every error report to an observability store with the trace ID.

Watch for

  • Silent format drift when models change the JSON structure under load
  • Missing correlation_id breaking end-to-end trace reconstruction
  • Escalation paths that name unavailable agents or humans, causing dead-letter queues
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.