This prompt is designed for platform engineers and orchestration system architects who manage a fleet of heterogeneous AI agents. The core job-to-be-done is to programmatically determine when a specific agent has reached the boundary of its defined capabilities and must escalate a task rather than attempt it and fail silently or hallucinate. The ideal user is building a reliability layer into an agent mesh, where a 'dispatcher' or 'supervisor' agent needs to introspect a task against a known capability contract and produce a structured handoff decision. The required context includes a clear definition of the current agent's capabilities, the incoming task, and a catalog of available downstream agents or human fallback queues.
Prompt
Capability Gap Detection and Escalation Prompt

When to Use This Prompt
Define the job, reader, and constraints for the Capability Gap Detection and Escalation Prompt.
Do not use this prompt when the agent's capabilities are so broad that a gap is unlikely, or when the cost of a failed attempt is lower than the cost of escalation. It is also the wrong tool for simple keyword-based routing or for agents that operate in a single, well-defined domain with no fallback options. This prompt is specifically for heterogeneous fleets where a wrong delegation creates reconciliation debt, duplicated work, or a silent failure. It is a pre-execution guard, not a post-hoc error handler. Use it before the agent acts, not after a tool call fails. For post-failure workflows, use the 'Tool Failure Escalation and Recovery Prompt' instead.
Before implementing, ensure you have a machine-readable capability contract for each agent in your fleet. The prompt's effectiveness is directly tied to the quality of the [AGENT_CAPABILITIES] input. A vague capability description will produce vague gap assessments. Start by defining explicit inclusions and exclusions for each agent, and test the prompt against a golden dataset of tasks that should and should not be escalated. The next step is to wire this prompt into your agent's pre-processing hook so that no task reaches an execution loop without first passing this capability boundary check.
Use Case Fit
Where the Capability Gap Detection and Escalation Prompt works, where it fails, and the operational conditions required for reliable use in production.
Good Fit: Heterogeneous Agent Fleets
Use when: you operate multiple specialized agents with distinct capability boundaries and need a single prompt to assess which tasks fall outside the current agent's scope. Guardrail: maintain a current capability registry for each agent so the prompt can reference concrete skill boundaries rather than guessing.
Bad Fit: Single-Agent Monoliths
Avoid when: your system has only one general-purpose agent with no alternative routing targets. Gap detection without a handoff destination creates dead-end escalations. Guardrail: deploy this prompt only when at least two specialized agents or a human fallback path are available.
Required Inputs
Risk: incomplete inputs produce false negatives where real capability gaps go undetected. Guardrail: always provide the current agent's capability manifest, the full task specification, available agent roster with skill descriptions, and any policy constraints. Validate input completeness before invoking the prompt.
Operational Risk: Stale Capability Data
Risk: agent capabilities change over time as models update or tools are added. A prompt referencing stale capability manifests will miss gaps or escalate unnecessarily. Guardrail: version your capability manifests alongside agent deployments and refresh them in the prompt context on every deploy cycle.
Operational Risk: Escalation Loops
Risk: agent A escalates to agent B, which detects its own gap and escalates back to A, creating infinite loops. Guardrail: include a visited-agent stack in the handoff context and trigger a circuit breaker after N hops. Pair this prompt with an escalation loop detection prompt in production.
Boundary: Confidence vs. Certainty
Risk: the prompt may produce high-confidence gap assessments that are factually wrong, especially for edge-case tasks near capability boundaries. Guardrail: require the output to include a confidence score and uncertainty rationale. Route low-confidence assessments to human review instead of automated handoff.
Copy-Ready Prompt Template
A reusable prompt for detecting capability gaps and generating structured escalation payloads for heterogeneous agent fleets.
This prompt template is designed to be injected into an agent's execution loop when it encounters a task it cannot confidently complete. It forces a structured self-assessment of the agent's own capabilities against the request, identifies the specific gap, and produces a machine-readable handoff payload for an orchestrator. The primary goal is to prevent silent failures or hallucinated completions by making the 'I cannot do this' decision explicit and actionable.
textYou are a capability assessment module for an autonomous agent. Your task is to analyze the current request and your own operational boundaries to determine if you can fulfill it. Do not attempt to partially complete or guess the task if a capability gap exists. ## Request [USER_REQUEST] ## Your Capabilities [AGENT_CAPABILITY_MANIFEST] ## Available Specialist Agents [AVAILABLE_AGENT_CATALOG] ## Instructions 1. **Gap Analysis:** Compare the [USER_REQUEST] against your [AGENT_CAPABILITY_MANIFEST]. Identify any specific requirements in the request that you cannot satisfy. Classify the gap type as one of: `tool_missing`, `knowledge_gap`, `policy_restriction`, `confidence_below_threshold`, `domain_unsupported`, or `other`. 2. **Escalation Decision:** If no gap exists, respond with `{"action": "accept"}`. If a gap exists, respond with `{"action": "escalate"}` and populate the escalation payload. 3. **Target Selection:** If escalating, select the most appropriate target from the [AVAILABLE_AGENT_CATALOG] based on the required capability. If no suitable agent exists, set the target to `human_operator`. 4. **Context Packing:** Extract the minimum essential context from [USER_REQUEST] and your current session state required for the target to resume the task without repetition. Include the original request, relevant data, and your partial progress, if any. ## Output Schema Respond exclusively with a valid JSON object. Do not include any text outside the JSON block. { "action": "accept" | "escalate", "gap_type": "tool_missing" | "knowledge_gap" | "policy_restriction" | "confidence_below_threshold" | "domain_unsupported" | "other", "gap_description": "A concise, specific explanation of what you cannot do and why.", "target_agent_id": "[TARGET_AGENT_ID_OR_human_operator]", "handoff_payload": { "original_request": "[VERBATIM_USER_REQUEST]", "session_context_summary": "[RELEVANT_STATE_AND_DATA]", "failure_reason_code": "[GAP_TYPE]", "recommended_action": "A one-sentence instruction for the target agent." }, "confidence": 0.0 }
To adapt this template, replace the square-bracket placeholders with your system's live data. [AGENT_CAPABILITY_MANIFEST] should be a static, structured description of the agent's tools, knowledge domains, and policy constraints. [AVAILABLE_AGENT_CATALOG] is a dynamic list of other agents and their capabilities, typically fetched from an orchestration service. The handoff_payload must be treated as a contract; the receiving agent or human operator should be able to resume the task using only the information in that object. Before deploying, validate the JSON output against the schema and implement a retry or repair step if parsing fails, as a malformed escalation is a critical failure mode.
Prompt Variables
Inputs required by the Capability Gap Detection and Escalation Prompt to produce a reliable capability assessment and routing decision.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[AGENT_CAPABILITY_MANIFEST] | Defines the current agent's known skills, tools, and authority boundaries | {"agent_id": "billing-agent-v2", "capabilities": ["invoice_lookup", "refund_processing"], "max_refund_amount": 500} | Must be a valid JSON object with required fields: agent_id (string), capabilities (array of strings). Reject if manifest is empty or missing capabilities array. |
[TASK_REQUEST] | The full task or user request the agent is attempting to process | Process a refund for order #ORD-9921 in the amount of $1,250.00 and update the customer's subscription tier. | Must be a non-empty string. Check for minimum length of 10 characters. Reject if null or whitespace only. |
[AGENT_SELF_ASSESSMENT] | The agent's own confidence score and reasoning about its ability to handle the task | {"confidence": 0.35, "concern": "Refund amount exceeds authorized limit of $500", "partial_capabilities": ["invoice_lookup"]} | Must be valid JSON with confidence (float 0.0-1.0) and concern (string). Reject if confidence is above 0.9 but concern indicates a clear gap. |
[AVAILABLE_AGENTS_REGISTRY] | Catalog of all available specialized agents with their capabilities and routing addresses | [{"agent_id": "high-value-refund-agent", "capabilities": ["large_refund_processing", "subscription_modification"], "routing_key": "refunds.high-value"}] | Must be a valid JSON array with at least one agent entry. Each entry requires agent_id, capabilities (array), and routing_key (string). Reject if registry is empty. |
[ESCALATION_POLICY] | Organizational rules governing when and how escalation must occur | {"rules": [{"condition": "refund_amount > agent_max_refund", "action": "escalate_to_agent", "target_capability": "large_refund_processing"}], "require_human_approval_above": 1000} | Must be valid JSON with a rules array. Each rule requires condition (string) and action (string). Reject if policy is missing or rules array is empty. |
[PREVIOUS_HANDOFF_CONTEXT] | Context from prior handoffs or escalations in the same session, if any | {"previous_agent": "triage-agent", "handoff_reason": "refund_amount_exceeds_threshold", "preserved_state": {"order_id": "ORD-9921"}} | Can be null for first attempt. If present, must be valid JSON with previous_agent (string) and handoff_reason (string). Validate that preserved_state contains required task identifiers. |
[CAPABILITY_GAP_SCHEMA] | Expected output schema for the capability gap assessment | {"gaps": [{"required_capability": "string", "available_in_current_agent": false, "severity": "blocker"}], "recommended_agent": "string", "escalation_required": true} | Must be a valid JSON Schema object. Validate that it defines required fields: gaps (array), recommended_agent (string), escalation_required (boolean). Reject if schema allows escalation_required: true with no recommended_agent. |
Implementation Harness Notes
How to wire the capability gap detection prompt into an agent orchestration layer with validation, retries, and escalation routing.
This prompt is designed to sit at the boundary of an agent's execution cycle, invoked whenever the agent encounters a task it cannot complete with high confidence. The implementation harness must treat this prompt as a structured decision point, not a free-text suggestion. The output is a machine-readable capability assessment that your orchestration layer parses to route work to the next specialized agent, a human queue, or a graceful degradation path. The harness is responsible for enforcing the output schema, validating gap coverage completeness, and preventing the prompt from being bypassed when the agent's internal confidence falls below a configured threshold.
Integration pattern: Wrap the prompt in a function that accepts the current agent's role definition, the failed or uncertain task description, the agent's self-reported confidence score, and the available downstream agent registry with capability descriptions. The function should call the LLM with response_format set to a strict JSON schema matching the expected output fields: detected_gaps (array of capability shortfalls), recommended_escalation_target (agent ID or human_review), gap_coverage_completeness (boolean), and rationale. After receiving the response, run a validator that checks: (1) every gap in detected_gaps maps to at least one capability in the agent registry, (2) the recommended_escalation_target exists in the registry or is the reserved human_review token, and (3) gap_coverage_completeness is true. If validation fails, retry once with the validation errors injected into the prompt as [PREVIOUS_ERRORS]. If the retry also fails, escalate to a human operator with the raw output and validation trace attached.
Model choice and latency: Use a model with strong instruction-following and structured output support for this prompt. The decision is high-stakes—routing to the wrong agent or failing to detect a gap can cause silent failures downstream. Expect latency in the 1-3 second range for capable models. If your agent loop is sub-second, consider running this check asynchronously after the agent's primary response, with a circuit breaker that halts further autonomous action until the capability assessment returns. Logging and audit: Every invocation must produce a structured log entry containing the input context, the raw model output, the validation result, the final routing decision, and a timestamp. This audit trail is essential for debugging handoff failures and demonstrating governance controls. Human review trigger: When recommended_escalation_target is human_review, the harness must package the capability assessment alongside the original task context and the agent's partial work into a structured handoff payload for your human-in-the-loop queue. Do not silently downgrade a human escalation to an automated fallback.
What to avoid: Do not use this prompt as a replacement for agent-level confidence scoring. The prompt works best when the agent already has a calibrated internal confidence estimate to provide as input. Avoid invoking this prompt on every agent turn—reserve it for low-confidence states, tool failures, or tasks that fall outside the agent's declared capability boundary. Do not skip the validation step; even strong models occasionally produce hallucinated agent IDs or incomplete gap lists. Finally, test the harness end-to-end with a gap coverage eval set: a collection of scenarios where the correct escalation target is known, including edge cases where multiple gaps exist or no suitable downstream agent is available. Measure routing accuracy, false-negative gap detection rate, and validation pass rate before deploying to production.
Expected Output Contract
Validate the capability gap assessment payload before routing to the escalation handler. Each field must pass the listed check before the handoff proceeds.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
gap_id | string (UUID v4) | Must parse as valid UUID v4; reject if missing or malformed | |
current_agent_id | string | Must match an agent ID in the active fleet registry; reject unknown agents | |
detected_gaps | array of objects | Array length >= 1; each object must contain 'capability', 'severity', and 'evidence' keys | |
detected_gaps[].capability | string | Must match an entry in the fleet capability taxonomy; reject unknown capabilities | |
detected_gaps[].severity | enum: CRITICAL, HIGH, MEDIUM, LOW | Must be one of the four allowed values; case-sensitive check | |
detected_gaps[].evidence | string (min 20 chars) | Must contain a concrete observation or log excerpt; reject empty or placeholder strings like 'N/A' | |
recommended_target_type | enum: AGENT, HUMAN, FALLBACK_PATH | Must be one of the three allowed values; reject if missing | |
recommended_target_id | string or null | Required when target_type is AGENT or FALLBACK_PATH; must resolve to a registered target; null allowed only for HUMAN | |
confidence_score | number (0.0-1.0) | Must be a float between 0.0 and 1.0 inclusive; reject values outside range or non-numeric | |
escalation_reason_code | string | Must match a reason code in the escalation policy registry; reject unmapped codes | |
timestamp | ISO 8601 UTC string | Must parse as valid ISO 8601 in UTC; reject future timestamps or unparseable formats |
Common Failure Modes
Capability gap detection fails silently when agents overestimate their competence or miss edge cases. These cards cover the most common production failure patterns and how to prevent them.
Overconfident Capability Claims
What to watch: The agent asserts it can handle a task that falls outside its actual capability boundary, producing plausible but incorrect output instead of escalating. This is most common with general-purpose models that default to helpfulness over honesty. Guardrail: Require the agent to self-assess against a predefined capability manifest before attempting any task. Include explicit CANNOT_DO examples in few-shot prompts and validate capability claims against a known skill registry.
Incomplete Gap Coverage
What to watch: The capability assessment identifies some gaps but misses others, especially compound gaps where the task requires multiple missing capabilities simultaneously. Single-capability checks fail when the real blocker is an interaction between missing skills. Guardrail: Use a structured capability taxonomy with required capability combinations. Test gap detection against composite failure scenarios where two or more capabilities are absent. Log missed gaps and update the taxonomy iteratively.
Escalation Target Mismatch
What to watch: The prompt correctly identifies a capability gap but routes to the wrong specialized agent or human queue, creating a handoff that the receiver cannot fulfill. This happens when agent capability descriptions are stale or overlapping. Guardrail: Maintain a machine-readable agent capability registry with versioned skill definitions. Validate escalation targets against the registry at decision time. Include a confirmation step where the receiving agent acknowledges capability fit before accepting the handoff.
Threshold Drift Under Load
What to watch: Confidence thresholds that work in testing produce excessive escalations or missed escalations in production as input distributions shift. Agents become either trigger-happy or dangerously passive when real-world data differs from eval sets. Guardrail: Monitor escalation rates, false-positive ratios, and false-negative incidents in production. Implement threshold calibration runs against recent production samples. Set alerting thresholds on escalation rate anomalies rather than relying on static confidence cutoffs.
Context Stripping During Handoff
What to watch: The escalation decision correctly identifies the gap and target, but the context payload passed to the next agent is incomplete. Critical evidence, partial results, or user constraints are dropped during the transfer, forcing the receiving agent to re-derive information or make decisions with missing data. Guardrail: Use a structured handoff schema with required fields. Validate context completeness before transfer. Include a context checksum or summary that the receiving agent can verify. Log handoff payloads for post-incident review.
Silent Escalation Failures
What to watch: The escalation decision is correct, but the handoff mechanism fails silently due to queue misconfiguration, agent unavailability, or timeout. The user receives no response while the system assumes the escalation succeeded. Guardrail: Implement acknowledgment receipts for all handoffs. Set escalation timeouts with fallback paths. Monitor handoff success rates and escalation-to-resolution latency. Build a dead-letter queue for escalations that cannot be delivered, with alerting and human review.
Evaluation Rubric
Criteria for testing whether the capability gap detection and escalation prompt produces complete, actionable, and safe outputs before deployment.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Gap Coverage Completeness | All capability gaps present in the input are identified and mapped to at least one target agent or human role | One or more known gaps are missing from the output; gaps are described vaguely without a target | Run against a golden set of 10 inputs with known capability gaps; require 100% recall of pre-labeled gaps |
Target Agent Validity | Every escalated target agent exists in the current fleet registry and matches the capability required | Output references a deprecated agent, hallucinated agent name, or agent with mismatched capability | Validate each target agent name against the fleet registry schema; flag any name not in the allowed list |
Handoff Reason Code Accuracy | Reason code matches the escalation taxonomy and correctly reflects the gap type | Reason code is missing, generic, or contradicts the gap description | Check that reason code is from the allowed enum; spot-check 20 outputs for semantic alignment between gap and code |
Confidence Score Calibration | Confidence score correlates with actual handoff success rate; low-confidence outputs should not claim high certainty | Confidence score is always 0.9+ regardless of gap ambiguity; score is missing or unparseable | Track confidence scores against downstream handoff acceptance rates over 100 production traces; require monotonic relationship |
Context Payload Completeness | Handoff payload includes user intent, session summary, partial results, and unresolved questions | Payload is empty, contains only the gap label, or omits critical session state needed by the target agent | Schema-validate the payload against required fields; human review 10 samples for missing essential context |
Escalation Threshold Adherence | Escalation only triggers when confidence is below the configured threshold or capability is explicitly absent | Escalation fires for in-scope capabilities the agent can handle; no escalation when confidence is above threshold | Run 50 test cases with known threshold boundaries; measure false-positive and false-negative escalation rates |
Hallucinated Capability Claims | Output never claims the current agent can handle a task outside its defined capability contract | Output states the agent can perform a task not in its capability manifest; missing gap leads to silent failure | Diff the output's claimed capabilities against the agent's manifest; any addition is a failure |
Output Schema Compliance | Output is valid JSON matching the expected schema with all required fields present and correctly typed | Output is malformed JSON, missing required fields, or contains fields with wrong types | Parse output with the schema validator; reject any output that fails validation; measure schema compliance rate over 100 runs |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

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

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Start with the base prompt and a simple JSON schema. Use a single model call without retries. Focus on getting the capability gap list and escalation target correct before adding thresholds or confidence scores.
codeYou are a capability gap detector. Given [AGENT_CAPABILITIES] and [TASK_DESCRIPTION], identify what the current agent cannot handle and recommend which specialized agent or human role should take over. Return JSON with fields: gaps[], escalation_target, rationale.
Watch for
- Overly broad gap descriptions that don't map to a real escalation target
- Missing edge cases where the agent partially handles a task but shouldn't
- No validation on the escalation_target field against a known agent registry

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