This prompt is designed for platform engineers and AI SREs who need to diagnose a single agent trace where tool-call behavior deviated from expectations. The primary job-to-be-done is to take a raw, captured trace span from an agent session and produce a structured fault report. This report must identify incorrect tool selection, malformed arguments, or missing calls, and it must provide root-cause hypotheses. Use this prompt when you have isolated a problematic session and need a deep, forensic analysis before you aggregate data across multiple sessions or escalate to an incident. The ideal user has access to the raw trace data, understands the expected tool schemas, and needs a repeatable diagnostic process.
Prompt
Tool-Call Sequence Diagnosis Prompt

When to Use This Prompt
A practical guide for platform engineers and AI SREs diagnosing a single agent trace with unexpected tool-call behavior.
This prompt is not a replacement for real-time monitoring or alerting systems. Do not use it for live traffic analysis, aggregate trend detection, or as a substitute for a production observability dashboard. It is also not suitable for diagnosing issues that span multiple agent sessions, such as a systemic model drift problem, which would require a different, aggregation-focused analysis. The prompt assumes the fault is isolated to a single trace and that the root cause is likely within the tool-call sequence itself—not a broader infrastructure failure, a network timeout, or a model serving error. If you haven't already captured the full trace with tool-call arguments and responses, you must do that first; this prompt is for analysis, not data collection.
To get the most out of this prompt, you should provide the complete trace data, including the system prompt, user input, and the full sequence of tool calls with their arguments and responses. The prompt is most effective when you also supply the expected tool schemas as a [TOOLS] variable, allowing the model to validate the actual calls against the contract. The output will be a structured report, which you should validate against your own knowledge of the system. In high-stakes production environments, always treat the model's root-cause hypothesis as a starting point for your own investigation, not a final verdict. The next step after receiving the diagnosis is to reproduce the issue in a controlled test environment using the identified failure conditions.
Use Case Fit
Where the Tool-Call Sequence Diagnosis Prompt delivers value and where it creates noise. Use this card set to decide if this prompt fits your current trace review workflow.
Good Fit: Agent Trace with Tool Failures
Use when: You have a single production trace where an agent called tools but produced an incorrect result, and you suspect tool selection, argument formatting, or missing calls are the root cause. Guardrail: Confirm the trace captures the full tool-call round-trip—request arguments and response payloads—before running the diagnosis.
Bad Fit: Model-Only Responses
Avoid when: The trace contains only model-generated text with no tool calls. This prompt is designed to analyze tool-call sequences, not general output quality or hallucination. Guardrail: Route traces without tool calls to the Hallucination Source Trace Prompt or Output Format Drift Diagnosis Prompt instead.
Required Input: Complete Tool-Call Spans
What to watch: The prompt requires raw spans that include tool names, input arguments, response payloads, and timestamps. Partial traces with missing response data will produce incomplete or misleading fault reports. Guardrail: Validate span completeness with the End-to-End Trace Reconstruction Prompt before running tool-call sequence diagnosis.
Operational Risk: Schema Drift Between Trace and Expected Tools
What to watch: If the expected tool schemas provided to the prompt are outdated or don't match the agent's actual tool definitions, the diagnosis will flag valid calls as malformed and miss real argument errors. Guardrail: Version your tool schemas alongside your prompts and validate them against the agent's current tool manifest before diagnosis.
Operational Risk: Multi-Agent Trace Confusion
What to watch: If the trace spans multiple agents or sub-agents with different tool sets, the prompt may misattribute tool calls to the wrong agent or apply incorrect expected schemas. Guardrail: Pre-process the trace to segment spans by agent identity and run the diagnosis separately for each agent's tool-call sequence.
Bad Fit: Latency or Cost Investigation
Avoid when: Your primary question is why a trace was slow or expensive, not whether the tool calls were correct. This prompt focuses on functional correctness of tool sequences. Guardrail: For latency and cost questions, use the Latency Spike Root-Cause Analysis Prompt or Token Consumption Breakdown Prompt instead.
Copy-Ready Prompt Template
A copy-ready prompt for diagnosing tool-call sequence failures from a single production trace.
This prompt template is designed to be pasted directly into your trace review workflow. It instructs the model to act as a platform engineer auditing a single agent trace, focusing exclusively on the sequence of tool calls, their arguments, and the responses they received. The goal is to produce a structured fault report that identifies incorrect tool selection, malformed arguments, or missing calls, along with root-cause hypotheses. Before using this prompt, ensure you have extracted the relevant spans from your observability platform (e.g., LangSmith, Arize, or a custom trace store) and have the expected tool schemas available for validation.
codeYou are a platform engineer diagnosing an agent trace failure. Your task is to analyze the provided tool-call sequence and identify any faults in tool selection, argument formatting, or call ordering. ## INPUT **Trace Spans (Chronological):** [TRACE_SPANS] **Expected Tool Schemas:** [TOOL_SCHEMAS] **Agent's Stated Goal:** [AGENT_GOAL] ## INSTRUCTIONS 1. **Reconstruct the Sequence:** Parse the [TRACE_SPANS] to build a chronological list of every tool call, including the tool name, input arguments, and the response or error received. 2. **Validate Against Schemas:** For each tool call, compare the provided arguments against the expected schema in [TOOL_SCHEMAS]. Flag any missing required parameters, incorrect data types, or hallucinated parameters. 3. **Evaluate Selection and Order:** Assess whether the correct tool was chosen for the step and if the sequence of calls is logical for achieving the [AGENT_GOAL]. Identify any missing but necessary calls or calls that are redundant or out of order. 4. **Formulate Root-Cause Hypotheses:** Based on the identified faults, propose the most likely root cause for the failure. Prioritize hypotheses that are specific and testable (e.g., 'The system prompt omitted a required parameter for the search tool' rather than 'The agent made a mistake'). ## OUTPUT FORMAT Respond with a JSON object conforming to this schema: { "reconstructed_sequence": [ { "step": number, "tool_name": "string", "arguments": {}, "response_or_error": "string", "schema_validation_errors": ["string"] } ], "faults_identified": [ { "step": number, "fault_type": "incorrect_selection | malformed_arguments | missing_call | redundant_call | ordering_error", "description": "string", "evidence": "string" } ], "root_cause_hypotheses": [ { "hypothesis": "string", "confidence": "high | medium | low", "rationale": "string", "suggested_test": "string" } ], "overall_assessment": "string" } ## CONSTRAINTS - Base your analysis strictly on the provided [TRACE_SPANS] and [TOOL_SCHEMAS]. Do not invent information. - If the trace is incomplete or missing critical spans, note this in the `overall_assessment` and flag it as a limiting factor for your diagnosis. - Do not suggest fixes that require changing the agent's core reasoning logic; focus on prompt, schema, and configuration adjustments.
To adapt this template, replace the square-bracket placeholders with real data. [TRACE_SPANS] should contain the raw JSON or a structured text representation of the tool-use spans from your trace. [TOOL_SCHEMAS] should be the complete JSON Schema definitions for every tool the agent had access to. [AGENT_GOAL] is the user's original request or the agent's top-level objective for that session. After running the prompt, you must validate the output JSON against the provided schema. For high-stakes debugging, pair this automated diagnosis with a manual review of the trace to confirm the model's hypotheses before implementing any prompt or configuration changes.
Prompt Variables
Placeholders required by the Tool-Call Sequence Diagnosis Prompt. Replace each with concrete values from your trace system before sending the prompt.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[TRACE_JSON] | Raw trace data for a single agent session, including all spans, tool calls, arguments, and responses | {"trace_id": "abc123", "spans": [...]} | Must be valid JSON. Parse check required. Minimum required spans: user input, tool call, tool response, model output. Null not allowed. |
[EXPECTED_TOOL_SCHEMAS] | JSON Schema definitions for every tool the agent was authorized to call during this session | {"search_kb": {"parameters": {"query": {"type": "string"}}}} | Must be valid JSON Schema objects keyed by tool name. Schema check required. At minimum, include parameters and required fields for each tool. Null not allowed. |
[AGENT_POLICY_RULES] | Natural language description of the agent's allowed tool-use behavior, selection priorities, and constraints | "Agent must call search_kb before generate_answer. Never call delete_record without human approval." | Must be non-empty string. Should match the system prompt rules active during the traced session. Null not allowed. |
[SESSION_METADATA] | Context about the session: user ID, session start time, model version, prompt version, and deployment environment | {"model": "claude-3-opus-20240229", "prompt_version": "v2.3.1", "env": "production"} | Must include model identifier and prompt version at minimum. Used to correlate behavior with specific configurations. Null allowed if unavailable, but reduces diagnostic accuracy. |
[EXPECTED_TOOL_SEQUENCE] | Optional reference for the ideal or expected sequence of tool calls for this type of request | "search_kb -> analyze_results -> generate_answer" | Used for comparison against actual sequence. Null allowed. When provided, must be a comma-separated or arrow-delimited ordered list of tool names. |
[OUTPUT_SCHEMA] | Desired structure for the fault report output: fault type, root cause hypothesis, evidence spans, confidence, and recommended action | {"faults": [{"type": "string", "root_cause_hypothesis": "string", "evidence_span_ids": ["string"], "confidence": "number"}]} | Must be valid JSON Schema. Defines the shape the prompt should return. Schema check required. Null not allowed. |
[CONFIDENCE_THRESHOLD] | Minimum confidence score (0.0 to 1.0) for including a fault hypothesis in the output | 0.7 | Must be a float between 0.0 and 1.0. Faults below this threshold should be omitted or flagged as speculative. Default 0.5 if not specified. |
Implementation Harness Notes
How to wire the Tool-Call Sequence Diagnosis Prompt into an observability pipeline for automated trace review.
This prompt is designed to be triggered programmatically when an agent trace flags an error or when an engineer pulls a specific trace ID for manual review. The implementation harness should fetch the raw trace data from your observability platform—such as LangSmith, Arize, or a custom logging pipeline—and inject it into the [TRACE_JSON] placeholder. The prompt expects a structured JSON array of tool calls, including timestamps, function names, arguments, and responses. Before sending the prompt, validate that the trace payload contains all required fields; if the trace is incomplete, prepend a warning to the [CONTEXT] block so the model can flag missing data as part of its diagnosis.
The harness should enforce a strict output contract by appending the [OUTPUT_SCHEMA] directly to the prompt and validating the model's response against it before surfacing results to the engineer. Use a JSON Schema validator to check that the fault_report contains the required root_cause_hypotheses array, that each hypothesis includes a confidence score between 0 and 1, and that the sequence_analysis correctly references the tool call indices from the input trace. If validation fails, implement a retry loop with a maximum of two additional attempts, appending the validation error message to the prompt as feedback. For high-severity faults—such as malformed arguments that could cause downstream data corruption—route the validated report to a human reviewer via a ticketing system or Slack notification before any automated remediation is triggered.
Log every diagnosis attempt, including the raw trace, the prompt version, the model response, and the validation outcome, to an audit table. This creates a feedback dataset for evaluating the prompt's accuracy over time. When deploying changes to the prompt template, replay a sample of historical traces through the new version and compare the root_cause_hypotheses against the previous diagnoses to detect regressions. Avoid using this prompt for real-time agent intervention without human approval gates; the diagnosis is a forensic tool, not a live decision-maker. For traces exceeding the model's context window, preprocess the tool-call sequence to include only the calls immediately surrounding the failure point, and note the truncation in the [CONTEXT] field so the model can account for missing information in its confidence scores.
Expected Output Contract
Defines the structured fault report that the Tool-Call Sequence Diagnosis Prompt must produce. Use this contract to validate the model's output before routing it to downstream alerting or logging systems.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
trace_id | string | Must match the [TRACE_ID] input exactly. Reject if missing or altered. | |
diagnosis_summary | string (1-3 sentences) | Must not be empty. Length must be between 50 and 500 characters. Reject if it contains unresolved placeholders. | |
root_cause_hypothesis | object | Must contain 'primary_cause' (enum: INCORRECT_SELECTION, MALFORMED_ARGUMENTS, MISSING_CALL, HALLUCINATED_CALL, CORRECT) and 'confidence' (float 0.0-1.0). Reject if enum is invalid or confidence is out of range. | |
tool_call_sequence | array of objects | Each object must have 'step' (int), 'tool_name' (string), 'arguments' (object), 'response' (object or null), and 'assessment' (enum: CORRECT, INCORRECT, MISSING, REDUNDANT). Reject if steps are not sequential or if the array is empty. | |
expected_tool_schema_violations | array of objects | Each object must have 'step' (int), 'field' (string), 'expected_type' (string), 'actual_value' (string), and 'violation' (string). Array can be empty if no violations found. Reject if 'step' references a non-existent step. | |
missing_required_calls | array of strings | List of tool names from [EXPECTED_TOOL_SCHEMAS] that should have been called but were not. Array can be empty. Reject if a listed tool name is not present in the input schema. | |
remediation_suggestion | string | Must be a concrete, actionable instruction referencing specific prompt or code changes. Reject if length is less than 20 characters or contains only generic advice like 'fix the prompt'. | |
harness_validation_passed | boolean | Set to true only if the output passes all validation rules defined in this contract. Null if validation was not run. Reject if true but any validation rule is violated. |
Common Failure Modes
What breaks first when diagnosing tool-call sequences and how to guard against it.
Incomplete Trace Data
What to watch: Missing spans, truncated arguments, or absent tool responses in the trace prevent accurate diagnosis. The prompt hallucinates tool calls that never occurred or skips failed steps entirely. Guardrail: Validate span completeness before analysis. Reject traces with missing required segments and request re-instrumentation.
Tool Schema Drift
What to watch: The prompt compares trace arguments against an outdated tool schema, flagging valid calls as malformed or missing new required parameters. Guardrail: Always supply the deployed tool schema version as a [TOOL_SCHEMAS] input. Include a schema_version field and diff against the trace's recorded version.
False Causal Attribution
What to watch: The prompt incorrectly attributes a downstream failure to an earlier tool call that was actually correct, creating a misleading root-cause hypothesis. Guardrail: Require the prompt to trace failure propagation step-by-step with explicit evidence links. Flag any hypothesis that skips intermediate spans.
Overfitting to a Single Failure Pattern
What to watch: The prompt latches onto the first anomaly it finds and ignores later, more critical failures. A malformed argument early in the trace distracts from a missing tool call later. Guardrail: Instruct the prompt to enumerate all anomalies before ranking by severity. Use a structured output that requires a complete anomaly list before root-cause selection.
Ignoring Tool Response Semantics
What to watch: The prompt analyzes tool call arguments but ignores the actual response payload, missing cases where the call was correct but the tool returned an error or unexpected data. Guardrail: Require the prompt to pair each tool call with its response and validate both. Flag any analysis that only inspects request arguments.
Ambiguous Fault Classification
What to watch: The prompt produces vague fault labels like 'tool error' without specifying whether it was incorrect selection, malformed arguments, missing call, or tool-side failure. Guardrail: Constrain the output schema to a fixed taxonomy of fault types. Validate that every reported fault maps to exactly one category from the taxonomy.
Evaluation Rubric
Criteria for evaluating the quality of a tool-call sequence diagnosis report before integrating it into an automated incident response or review pipeline. Each criterion should be tested independently using a golden set of annotated traces.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Tool-Call Sequence Completeness | All tool calls in the trace are listed in chronological order with no omissions. | Missing tool calls or gaps in the reconstructed sequence. | Diff the extracted sequence list against the ground-truth span list from the trace. Assert count and order match. |
Argument Malformation Detection | Any tool call argument that violates the tool's JSON schema is flagged with the specific field and violation. | Malformed arguments are present in the trace but not flagged in the report, or correct arguments are incorrectly flagged. | Inject a trace with a known schema violation. Assert the report's |
Incorrect Tool Selection Identification | Any tool call where the selected tool is semantically wrong for the intent is flagged with a justification. | A wrong-tool call is missed, or a correct tool call is flagged as incorrect. | Use a trace where the agent calls a |
Missing Tool-Call Identification | Required tool calls that are absent from the sequence are identified with a root-cause hypothesis. | A critical missing step is not reported, or a non-required step is falsely flagged as missing. | Provide a trace where the agent answers without calling a mandatory |
Root-Cause Hypothesis Validity | The primary root-cause hypothesis is the most direct explanation for the first observed failure in the sequence. | The hypothesis blames a downstream symptom while ignoring an earlier trigger event, or it hallucinates a non-existent error. | Compare the report's top hypothesis against a pre-labeled root cause in a benchmark trace. Assert a match within the top 2 hypotheses. |
Schema Validation Harness Output | The report includes a machine-readable validation block that can be parsed to programmatically confirm pass/fail for each tool call. | The validation block is missing, unparseable, or contains incorrect pass/fail assertions. | Parse the |
Trace Evidence Grounding | Every fault flag and hypothesis in the report cites a specific span ID, timestamp, or log line from the trace. | The report makes a diagnostic claim without a trace reference, or cites a non-existent span ID. | Extract all cited evidence references. Assert each one resolves to a valid span or event in the source trace data. |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

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

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Use the base prompt with a single trace and lighter validation. Focus on getting a readable fault report without strict schema enforcement. Replace [EXPECTED_TOOL_SCHEMAS] with a simple list of tool names and their expected arguments.
Watch for
- The model may hallucinate tool names or argument shapes if schemas are not provided
- Root-cause hypotheses may be too generic without concrete trace evidence
- No retry or validation loop means format drift goes undetected

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