This prompt is designed for an execution monitoring harness that compares a recorded agent trace against a predefined reference plan. Its primary job is to detect structural and behavioral deviations—such as skipped steps, reordered actions, unplanned additions, or altered output targets—and produce a structured, machine-readable report. The ideal user is an AI engineer or platform operator building a supervised autonomy system where an orchestrator needs to programmatically decide whether to pause, replan, or escalate based on plan fidelity. You should use this prompt when you already have a complete or in-progress execution trace and a canonical plan artifact, and you need a deterministic classification of divergence before taking corrective action.
Prompt
Plan Deviation Detection Prompt

When to Use This Prompt
Defines the operational context, required inputs, and boundaries for the Plan Deviation Detection Prompt to ensure it is deployed in the correct monitoring harness.
This prompt is not a replanning, retry, or correction mechanism. It does not modify the agent's behavior or fix the plan; it strictly performs differential analysis. Deploy it as a post-step or post-completion validation gate within a larger control loop. For example, after an agent completes a subtask, pipe the step description, expected output schema, and actual tool call log into this prompt to get a severity rating (CRITICAL, MAJOR, MINOR, NONE) and a boolean plan_sync_required flag. In high-risk domains like healthcare or finance, the output of this prompt should never directly trigger an automated rollback. Instead, route CRITICAL deviations to a human review queue and use the structured report as the handoff artifact. Ensure your harness validates the output against a strict JSON schema before acting on the plan_sync_required recommendation.
Do not use this prompt when you lack a formal, machine-readable plan to compare against. If the agent's plan is implicit, generated on the fly without structured recording, or stored only in conversational history, the deviation detection will be unreliable and produce false positives. Similarly, avoid using this prompt for real-time intervention on latency-sensitive paths; the comparison logic is thorough and may add unacceptable overhead for sub-second decision loops. Before wiring this into production, run a batch of evaluation cases with known deviations (skipped steps, injected actions, reordered sequences) to calibrate your severity thresholds and confirm that the output schema matches your downstream handler's expectations.
Use Case Fit
Where the Plan Deviation Detection Prompt works and where it introduces risk. Use these cards to decide if this prompt fits your agent architecture before integrating it into a production monitor.
Good Fit: Structured Plan Contracts
Use when: your agent produces an explicit, machine-readable plan with step IDs, expected tools, and output targets before execution. The prompt compares actual execution traces against this contract. Guardrail: require the planner to emit a versioned plan schema that the deviation detector can parse without ambiguity.
Bad Fit: Open-Ended Exploration
Avoid when: the agent is designed for open-ended research, browsing, or creative exploration where no fixed plan exists. Deviation detection will generate false positives for valid exploratory behavior. Guardrail: gate the deviation prompt behind a plan-existence check; skip detection when no structured plan was committed.
Required Inputs
What you need: the original plan (step list with IDs, expected tools, and output schemas), the execution trace (tool calls, outputs, timestamps), and a deviation severity policy. Guardrail: validate that plan and trace share a common execution ID and timestamp range before invoking the prompt to prevent cross-session comparison errors.
Operational Risk: False Alarms
What to watch: the prompt flags benign reordering or equivalent tool substitutions as deviations, generating noise that operators learn to ignore. Guardrail: configure a severity threshold that distinguishes critical deviations (skipped steps, changed output targets) from minor ones (parallelized execution, equivalent tool choice) and suppress low-severity alerts in normal operation.
Operational Risk: Stale Plan Comparison
What to watch: the agent replans mid-execution but the deviation detector compares against the original plan, generating a cascade of false deviation alerts. Guardrail: subscribe the deviation detector to plan revision events; always compare against the most recent active plan version, not the initial snapshot.
Latency and Cost Sensitivity
What to watch: running deviation detection on every step adds token cost and latency to the critical path of agent execution. Guardrail: run detection asynchronously or at checkpoint boundaries rather than synchronously after each step; batch multiple step traces into a single detection call where possible.
Copy-Ready Prompt Template
A reusable prompt template for comparing actual agent execution traces against the original plan and producing a structured deviation report.
The prompt below is designed to be injected into your agent monitoring harness at runtime. It expects the original execution plan and the actual execution trace as structured inputs, and it returns a deviation report with severity ratings and a plan-sync recommendation. Use square-bracket placeholders for all dynamic values; your application layer should replace these before sending the request to the model.
textYou are an execution monitor for an autonomous agent system. Your job is to compare the agent's actual behavior against its original execution plan and detect deviations. ## INPUTS ### Original Plan [ORIGINAL_PLAN] ### Actual Execution Trace [EXECUTION_TRACE] ## TASK Analyze the execution trace against the original plan and identify all deviations. For each deviation, classify it into one of these categories: - SKIPPED_STEP: A planned step was never executed. - REORDERED_STEP: Steps were executed in a different order than planned. - ADDED_STEP: The agent performed an action not present in the original plan. - MODIFIED_OUTPUT: A step produced output that differs from the expected target. - TIMING_DEVIATION: A step exceeded its expected duration or started late. - DEPENDENCY_VIOLATION: A step was executed before its prerequisites were satisfied. For each deviation, provide: - deviation_id: A unique identifier for this deviation. - category: One of the categories above. - planned_step_id: The ID of the affected step from the original plan, or null if not applicable. - actual_action: What the agent actually did. - expected_action: What the plan specified. - evidence: A direct quote or reference from the execution trace that supports this finding. - severity: One of LOW, MEDIUM, HIGH, CRITICAL based on the impact on overall goal completion. - downstream_impact: Which subsequent steps or outputs are affected by this deviation. After listing all deviations, produce a plan-sync recommendation from these options: - CONTINUE: Deviations are minor; the plan remains valid. - REVISE_PLAN: The plan needs updating but execution can continue. - REPLAN_FROM_CURRENT: Significant deviations require regenerating the plan from the current state. - ABORT_AND_ESCALATE: The deviations make the original goal unreachable; escalate to a human operator. ## OUTPUT SCHEMA Return a JSON object with this structure: { "analysis_id": string, "timestamp": string (ISO 8601), "total_deviations": integer, "deviations": [ { "deviation_id": string, "category": "SKIPPED_STEP" | "REORDERED_STEP" | "ADDED_STEP" | "MODIFIED_OUTPUT" | "TIMING_DEVIATION" | "DEPENDENCY_VIOLATION", "planned_step_id": string | null, "actual_action": string, "expected_action": string, "evidence": string, "severity": "LOW" | "MEDIUM" | "HIGH" | "CRITICAL", "downstream_impact": string } ], "plan_sync_recommendation": "CONTINUE" | "REVISE_PLAN" | "REPLAN_FROM_CURRENT" | "ABORT_AND_ESCALATE", "recommendation_rationale": string, "unresolved_risks": [string] } ## CONSTRAINTS - Only report deviations you can support with evidence from the execution trace. - If no deviations are found, return an empty deviations array and a CONTINUE recommendation. - Do not invent deviations to fill the report. - If the execution trace is incomplete or ambiguous, note this in unresolved_risks. - Assign CRITICAL severity only when the deviation makes the original goal unreachable. - If the plan is [RISK_LEVEL] HIGH or CRITICAL, flag any deviation of MEDIUM severity or above for human review.
This template separates the monitoring logic from the application harness. The [ORIGINAL_PLAN] and [EXECUTION_TRACE] placeholders should be populated with structured JSON or formatted text that includes step IDs, expected outputs, and timestamps. The [RISK_LEVEL] placeholder allows you to adjust the escalation threshold dynamically based on the workflow's risk profile. Before deploying, validate that your plan and trace schemas include the fields this prompt references—missing step IDs or timestamps will produce unreliable deviation reports.
After integrating this prompt, wire the output through a JSON schema validator before acting on the recommendation. For HIGH or CRITICAL severity deviations, route the report to a human review queue rather than allowing automated replanning. Log every deviation report alongside the plan version and trace ID so you can audit detection accuracy over time and tune severity thresholds.
Prompt Variables
Required inputs for the Plan Deviation Detection Prompt. Each placeholder must be populated before the prompt is sent. Validation notes describe how to confirm the input is well-formed before execution.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[ORIGINAL_PLAN] | The complete, step-by-step execution plan the agent was expected to follow, including step IDs, descriptions, dependencies, and expected outputs. | {"plan_id": "PLAN-042", "steps": [{"step_id": "S1", "description": "Fetch customer record from CRM", "depends_on": [], "expected_output": "Customer object with account_status field"}, {"step_id": "S2", "description": "Check account_status against eligibility rules", "depends_on": ["S1"], "expected_output": "Eligibility boolean with rule reference"}]} | Parse check: valid JSON with required fields plan_id and steps array. Each step must have step_id, description, and depends_on. Reject if steps array is empty or step_id values are not unique. |
[EXECUTION_TRACE] | The actual sequence of actions the agent performed, including tool calls, their arguments, outputs, timestamps, and any reasoning or observation text produced between actions. | {"trace_id": "TRACE-042", "actions": [{"action_id": "A1", "tool": "crm_lookup", "args": {"customer_id": "CUST-8821"}, "output": {"status": "active", "tier": "premium"}, "timestamp": "2025-01-15T10:03:22Z"}, {"action_id": "A2", "tool": "eligibility_check", "args": {"status": "active"}, "output": {"eligible": true}, "timestamp": "2025-01-15T10:03:45Z"}]} | Parse check: valid JSON with actions array. Each action must have action_id, tool, and timestamp. Timestamps must be ISO 8601 and monotonically increasing. Reject if trace is empty or timestamps are out of order. |
[DEVIATION_TYPES] | The categories of deviation the detector should flag. Controls sensitivity and what counts as a reportable event. | ["SKIPPED_STEP", "REORDERED_STEP", "UNPLANNED_ACTION", "OUTPUT_MISMATCH", "DEPENDENCY_VIOLATION"] | Must be a non-empty array of strings from the allowed enum: SKIPPED_STEP, REORDERED_STEP, UNPLANNED_ACTION, OUTPUT_MISMATCH, DEPENDENCY_VIOLATION, TIMING_ANOMALY. Reject if any value is not in the allowed set. |
[SEVERITY_THRESHOLD] | Minimum severity level required to include a deviation in the report. Deviations below this threshold are noted but not escalated. | "MEDIUM" | Must be one of: LOW, MEDIUM, HIGH, CRITICAL. Reject if value is not in the allowed enum. Default to MEDIUM if not provided. |
[OUTPUT_SCHEMA] | The expected structure of the deviation report. Defines required fields, their types, and whether they are nullable. | {"report_id": "string", "plan_id": "string", "trace_id": "string", "generated_at": "ISO8601", "deviations": [{"deviation_id": "string", "type": "DEVIATION_TYPE_ENUM", "severity": "SEVERITY_ENUM", "planned_step_id": "string | null", "actual_action_id": "string | null", "description": "string", "evidence": "string", "recommendation": "PLAN_SYNC | REPLAN | ESCALATE | IGNORE"}], "summary": {"total_deviations": "integer", "by_severity": {"LOW": "integer", "MEDIUM": "integer", "HIGH": "integer", "CRITICAL": "integer"}, "plan_sync_recommended": "boolean"}} | Schema check: valid JSON Schema or TypeScript interface. Required top-level fields: report_id, plan_id, trace_id, deviations, summary. deviations must be an array. Each deviation must have deviation_id, type, severity, description, and recommendation. Reject if required fields are missing. |
[CONTEXT_WINDOW_BUDGET] | Maximum token budget available for the prompt plus response. Used to decide whether to truncate the execution trace or summarize plan steps. | 8000 | Must be a positive integer. If the combined ORIGINAL_PLAN and EXECUTION_TRACE exceed 70% of this budget, the caller should summarize or truncate before sending. Reject if value is less than 2000. |
[PLAN_SYNC_RULES] | Rules that determine when a deviation should trigger an automatic plan update versus a human review. Defines the boundary between autonomous correction and escalation. | {"auto_sync_for": ["SKIPPED_STEP"], "require_approval_for": ["UNPLANNED_ACTION", "OUTPUT_MISMATCH"], "max_auto_sync_severity": "MEDIUM"} | Parse check: valid JSON with auto_sync_for and require_approval_for arrays. Values must be from the DEVIATION_TYPES enum. max_auto_sync_severity must be from the SEVERITY_ENUM. Reject if a deviation type appears in both arrays. |
Implementation Harness Notes
How to wire the Plan Deviation Detection Prompt into an agent runtime or monitoring harness with validation, retries, and escalation logic.
The Plan Deviation Detection Prompt is not a standalone chat interaction—it is a monitoring component that sits inside an agent execution loop or a sidecar observer process. The harness should invoke this prompt after every significant agent action or at configurable checkpoints (every N steps, after tool calls that modify state, or when a step's output diverges from expected schema). The prompt expects two structured inputs: the original plan (a list of steps with IDs, descriptions, expected outputs, and dependencies) and the execution trace (a chronological log of actions taken, tool calls made, outputs produced, and any errors encountered). The harness is responsible for assembling these inputs from the agent's plan store and trace buffer before each invocation.
Wire the prompt into a post-action hook that fires after the agent's execution step completes but before the next step is authorized. The hook should: (1) extract the current plan snapshot and the latest trace segment since the last deviation check, (2) populate the [ORIGINAL_PLAN] and [EXECUTION_TRACE] placeholders with structured JSON, (3) call the model with a strict JSON output schema that includes deviations (array of deviation objects with step_id, deviation_type, severity, evidence, and plan_sync_recommendation), (4) validate the response against that schema, and (5) route the result. If severity is critical or high, pause the agent and queue the deviation for human review or an automated replanning module. If severity is medium, log the deviation and continue with a warning flag. If low or none, continue execution without interruption. Use a model with strong structured-output support (GPT-4o, Claude 3.5 Sonnet, or equivalent) and set temperature=0 to minimize variance in severity classification.
Build validation and retry logic around the model's output. After receiving the deviation report, validate that every step_id in the deviations array exists in the original plan and that deviation_type is one of the allowed enum values: skipped_step, reordered_execution, unplanned_action, output_target_changed, dependency_violation, or scope_creep. If validation fails, retry once with the validation error message appended to the prompt as a [CONSTRAINTS] note. If the retry also fails, escalate to a human operator with the raw trace and plan attached. Log every deviation check—including the plan version, trace segment, model response, and routing decision—to an audit store so that downstream post-mortem and plan-archiving workflows can reconstruct what the monitor saw and why it acted.
For production deployments, consider running the deviation detector as an asynchronous sidecar rather than blocking the main agent loop on every check. The sidecar consumes a stream of plan-and-trace snapshots, runs detection, and publishes deviation events to a decision channel that the agent runtime subscribes to. This decouples detection latency from agent step latency and allows batching multiple checks when the agent is moving quickly. Set a watchdog timer: if the deviation detector has not produced a result within a configured window (e.g., 30 seconds), assume a monitoring failure and either pause the agent or fall back to a lightweight heuristic check that flags any step with a missing expected output. The heuristic check is not a replacement for the prompt but a safety net that prevents silent monitoring gaps.
Expected Output Contract
Defines the required fields, types, and validation rules for the deviation report produced by the Plan Deviation Detection Prompt. Use this contract to build downstream parsers, alerting logic, and automated plan-sync actions.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
deviation_detected | boolean | Must be true if any deviation item exists; false otherwise. Fail if mismatch between flag and items array. | |
deviation_items | array of objects | Must be present. If empty, deviation_detected must be false. Each item must conform to the item schema below. | |
deviation_items[].step_id | string matching plan step ID | Must match a step identifier from the [ORIGINAL_PLAN]. Fail if reference is missing or malformed. | |
deviation_items[].deviation_type | enum: skipped | reordered | added | modified | output_changed | Must be one of the five allowed values. Reject any unrecognized type. | |
deviation_items[].description | string (1-200 chars) | Must concisely describe what deviated. Null or empty string is invalid. Length check enforced. | |
deviation_items[].severity | enum: low | medium | high | critical | Must be one of the four allowed values. Critical reserved for skipped mandatory steps or irreversible unplanned actions. | |
deviation_items[].evidence | string or null | If provided, must quote or reference the specific [EXECUTION_TRACE] line. Null allowed when deviation is inferred from absence. | |
recommendation | enum: continue | replan | pause_for_approval | abort | Must be one of the four allowed values. pause_for_approval required if any deviation severity is critical. |
Common Failure Modes
Plan deviation detection fails silently when the monitor can't distinguish between a legitimate replan and a dangerous drift. These are the most common failure patterns and how to guard against them before they reach production.
False Negatives from Vague Plans
What to watch: The monitor fails to flag a real deviation because the original plan is too high-level or uses ambiguous language. When the plan says 'analyze the data,' the agent can justify almost any action as compliant. Guardrail: Require plans to include concrete step descriptions with expected tool names, output artifacts, and measurable completion criteria before deviation detection runs.
False Positives from Legitimate Replanning
What to watch: The monitor flags every dynamic adjustment as a deviation, flooding operators with alerts for correct behavior. This happens when the prompt treats the original plan as immutable rather than a living contract. Guardrail: Include a replanning legitimacy check in the prompt that distinguishes between goal-preserving adaptations and goal-changing drift. Require the monitor to cite which original constraint was violated, not just that a step changed.
Severity Inflation on Low-Impact Changes
What to watch: The monitor assigns CRITICAL severity to cosmetic changes like reordered non-dependent steps or renamed output files, desensitizing operators to real alerts. Guardrail: Define a severity rubric in the prompt that weighs dependency chain impact, output correctness risk, and reversibility. Low-severity deviations should be logged but not escalated.
Stale Plan Comparison After Mid-Execution Replan
What to watch: The agent replans mid-execution but the monitor continues comparing against the original plan, generating a cascade of spurious deviation alerts. Guardrail: Require the monitor to accept a current-plan reference that updates when replanning occurs. The prompt should compare against the most recent authorized plan version, not the initial snapshot.
Missing Context for Skipped Steps
What to watch: The monitor flags a skipped step as a deviation but lacks the execution context to know whether the step was intentionally bypassed because its preconditions were already satisfied or its outputs were produced by a prior step. Guardrail: Include step-level precondition and postcondition fields in the plan schema. The monitor should check whether the skipped step's intended outcome was already achieved before classifying it as a deviation.
Output-Only Comparison Misses Intent Drift
What to watch: The monitor only compares output artifacts and misses cases where the agent followed the plan steps but changed the goal interpretation, producing superficially correct outputs that serve a different objective. Guardrail: Add an intent-alignment check that compares the agent's stated subgoal at each step against the original plan's objective hierarchy. Flag when step-level intent diverges even if outputs match expected schemas.
Evaluation Rubric
Use this rubric to test the Plan Deviation Detection Prompt before deployment. Each criterion targets a specific failure mode common in execution monitoring. Run these checks against a golden dataset of known plan-execution pairs.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Deviation Recall | All known deviations (skipped, reordered, added steps) are detected with correct step IDs | Missing deviation in report; step ID mismatch; false negative on an unplanned action | Run against 20+ execution traces with pre-labeled deviations; require 100% recall on severity 'high' deviations |
False Positive Rate | No deviations reported for steps that were executed correctly and in order | Report flags a correctly executed step as deviated; hallucinated step ID; phantom reordering | Run against 5 clean execution traces with zero deviations; require zero deviation entries in output |
Severity Classification Accuracy | High-severity deviations involve skipped mandatory steps or unplanned destructive actions; low-severity covers minor reordering with no side effects | A skipped critical step marked as 'low'; a cosmetic reorder marked as 'high'; inconsistent severity logic across similar cases | Provide 10 deviation cases with pre-assigned severity labels; require exact match on 8/10; remaining 2 must be within one level |
Plan-Sync Recommendation Correctness | Recommendation matches ground-truth action: 'replan' when dependencies break, 'resume' when reorder is safe, 'abort' when goal is unreachable | Recommends 'resume' after a skipped prerequisite; recommends 'replan' for a safe reorder; recommendation contradicts severity | Test 15 scenarios with known correct recovery actions; require 90% match rate; flag any 'abort' recommendation for manual review |
Evidence Grounding | Every deviation entry includes a specific trace reference (step index, timestamp, or tool call ID) from the execution log | Deviation listed with no trace evidence; evidence points to wrong step; justification is generic ('seems wrong') | Parse output for [EVIDENCE] field; require non-empty, trace-matching reference for every deviation; fail if any reference is unresolvable |
Output Schema Compliance | Valid JSON matching the [OUTPUT_SCHEMA] with all required fields present and correctly typed | Missing 'deviations' array; 'severity' field is string instead of enum; 'recommendation' is null when required; extra fields not in schema | Validate output with JSON Schema validator; fail on any schema violation; test with 50 varied outputs to catch edge cases |
Empty Execution Handling | When execution trace is empty or contains only a start event, report zero deviations with recommendation 'insufficient_data' | Report hallucinated deviations from empty trace; crashes on null input; recommends 'resume' with no evidence | Pass empty trace array and trace with only a 'plan_start' event; require zero deviations and recommendation 'insufficient_data' |
Partial Execution Handling | When execution stopped mid-plan, deviations are reported only for completed steps; unexecuted steps are listed separately as 'incomplete', not 'deviated' | Unexecuted steps flagged as 'skipped' deviations; incomplete steps mixed with true deviations; no distinction between abandoned and deviated | Provide a trace where agent stopped after step 3 of 7; require 'incomplete' list for steps 4-7 and deviations only within steps 1-3 |
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 deviation detection prompt but relax strict schema enforcement. Use a single severity scale (LOW/MEDIUM/HIGH) without numeric scoring. Omit the plan-sync recommendation field and focus on detection only. Accept free-text deviation descriptions before committing to a structured output format.
Prompt modification
Replace the [OUTPUT_SCHEMA] placeholder with: Return a JSON object with fields: deviations (array of strings describing each deviation found), severity (one of LOW, MEDIUM, HIGH), and summary (one-sentence assessment).
Watch for
- False positives on minor reordering that doesn't affect outcomes
- Missing context about why a step was skipped (tool unavailability vs. agent error)
- Overly sensitive detection treating optional steps as required

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