This prompt is for integration developers and agent infrastructure engineers who need to produce a sequenced execution plan where tool calls depend on each other's outputs. Use it when you have a set of tools with known input-output contracts and need the model to generate a valid execution order with explicit field-level data mapping between steps. The core job-to-be-done is translating a high-level objective and a tool registry into a machine-readable execution graph that your orchestration engine can directly consume. This prompt does not execute the tools; it produces the plan that your orchestration engine will execute. It assumes you already know which tools are needed and are now solving for ordering and data flow.
Prompt
Sequential Chaining Prompt with Intermediate Results

When to Use This Prompt
Defines the job-to-be-done, ideal user, required context, and boundaries for the sequential chaining prompt.
Apply this prompt when you are building multi-step pipelines where the output of Tool A is a required input for Tool B, and you need the model to reason about field compatibility, type coercion, and missing intermediate values. It is particularly useful when your tool set includes operations like search_customer(query) -> customer_id, get_orders(customer_id) -> [order_ids], and get_order_details(order_id) -> details, where the data flow is linear but the field mapping must be explicit. Do not use this prompt for simple single-tool selection tasks, for deciding whether to call a tool at all, or for parallel-only execution plans with no dependencies. Those scenarios are better served by the tool selection and parallel orchestration prompts in this pillar. This prompt also assumes your tools are idempotent or that you have external guardrails for side-effect isolation; it does not generate rollback logic or transactional boundaries.
Before using this prompt, you must have a complete tool manifest with declared input schemas, output schemas, and semantic descriptions. The prompt will fail silently or produce hallucinated field mappings if the tool contracts are ambiguous. Always validate the generated plan against your actual tool schemas before execution. For high-risk workflows involving state mutations, financial transactions, or clinical data, insert a human approval gate between plan generation and plan execution. The next section provides the copy-ready prompt template you can adapt with your own tools and constraints.
Use Case Fit
Where sequential chaining with intermediate results delivers value and where you should reach for a different approach.
Good Fit: Output-to-Input Dependency Chains
Use when: each tool call genuinely requires a field from the previous tool's output to construct its arguments. Guardrail: validate that the dependency is a hard data requirement, not a logical preference. If tools can run independently, use a parallel fan-out pattern instead.
Bad Fit: Independent Data Retrieval
Avoid when: multiple tools fetch unrelated data that could be retrieved concurrently. Risk: unnecessary sequencing adds latency equal to the sum of all call durations. Guardrail: audit the dependency graph before implementing. If no tool consumes another's output, switch to parallel execution.
Required Input: Explicit Field Mapping
Use when: you can specify exactly which output fields map to which input parameters for each subsequent step. Guardrail: define a field mapping schema before writing the prompt. Missing or ambiguous mappings cause silent argument construction failures that are hard to debug in production traces.
Operational Risk: Cascading Failure Propagation
Risk: an error or empty result in step 2 poisons every downstream step, wasting compute and producing garbage output. Guardrail: insert validation gates between steps that check for required fields, non-empty results, and schema compatibility before proceeding. Abort the chain early on unrecoverable failures.
Operational Risk: Context Window Bloat
Risk: carrying full intermediate results through every step consumes context budget rapidly, especially with verbose tool outputs. Guardrail: extract and pass only the fields required by downstream steps. Strip verbose metadata, logs, and raw payloads before appending to the chain context.
Bad Fit: Low-Latency User-Facing Flows
Avoid when: the user is waiting for a response and each tool call adds perceptible delay. Risk: sequential chains multiply latency, degrading UX for interactive copilots and chat. Guardrail: if total chain latency exceeds 2-3 seconds, consider precomputing, caching intermediate results, or redesigning as an async background workflow.
Copy-Ready Prompt Template
A copy-ready prompt that instructs the model to produce a sequenced execution plan with explicit data mappings between dependent tool calls.
This prompt template is designed for integration developers who need a model to generate a reliable, multi-step execution plan where each step consumes the output of a previous one. Instead of merely listing tool calls, the model is forced to define the data flow: which specific fields from one tool's response are required as arguments for the next. This reduces the primary failure mode in sequential chaining—passing incompatible or missing data between steps—by making the mapping explicit and reviewable before any code executes.
textYou are an execution planner for a multi-step tool pipeline. Your task is to produce a strictly sequenced plan where each tool call after the first depends on the output of a preceding call. ## TASK DESCRIPTION [TASK_DESCRIPTION] ## AVAILABLE TOOLS [TOOLS] ## CONSTRAINTS - You must produce a JSON execution plan. - Each step must declare its dependencies explicitly. - For every dependent step, specify a field-level mapping: which output field from a prior step is used as which input argument. - If a required input cannot be sourced from any prior output, flag it as [MISSING_DEPENDENCY] and do not fabricate a value. - If the task can be partially satisfied with available tools, produce a partial plan and flag the unsatisfied parts. - Do not call tools in parallel unless you can prove they share no data dependencies. ## OUTPUT SCHEMA { "plan": [ { "step_id": "string", "tool_name": "string", "arguments": {}, "depends_on": [ { "step_id": "string", "mapping": { "target_argument": "source_output_field" } } ], "expected_output_schema": {} } ], "unresolved_dependencies": [ { "step_id": "string", "missing_argument": "string" } ] } ## EXAMPLES [EXAMPLES] ## RISK LEVEL [RISK_LEVEL]
To adapt this template, replace the square-bracket placeholders with your specific context. [TASK_DESCRIPTION] should contain the user's high-level goal. [TOOLS] must be a complete JSON schema array defining each function's name, description, and parameters. The [EXAMPLES] placeholder is critical for teaching the model the expected mapping granularity; include at least one few-shot example showing a correct field-level mapping and one showing a correctly flagged missing dependency. Set [RISK_LEVEL] to high if the pipeline includes state-changing writes, which should trigger a human review step before execution. After pasting, validate that the model's output strictly conforms to the OUTPUT_SCHEMA using a JSON schema validator before feeding the plan into your execution engine.
Before integrating this prompt into your application, build a lightweight validation harness that checks for common structural failures: missing depends_on arrays for non-initial steps, circular dependencies, and arguments that reference non-existent output fields from prior steps. For high-risk pipelines, insert a confirmation gate that renders the generated plan for a human operator to approve before any tool is invoked. When a plan contains unresolved_dependencies, route it to a clarification prompt that asks the user for the missing information rather than executing a partial plan with guessed values.
Prompt Variables
Every placeholder required by the sequential chaining prompt. Replace each with concrete values before sending the prompt to the model. Validation notes describe how to check that the placeholder is filled correctly.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[TOOL_REGISTRY] | JSON array of available tool definitions with schemas, descriptions, and input/output type signatures | [{"name": "get_customer", "parameters": {"customer_id": "string"}, "returns": {"email": "string", "tier": "string"}}] | Schema check: each tool must have name, parameters, and returns fields. Type check: parameters and returns must be valid JSON Schema objects. Null not allowed. |
[USER_OBJECTIVE] | Natural language description of the goal the tool chain must accomplish | "Retrieve the customer's recent orders, check inventory for each item, and generate a restock recommendation" | Non-empty string required. Must describe a multi-step outcome. If objective can be satisfied by a single tool call, this prompt is the wrong choice. |
[CONTEXT_DATA] | Optional initial data available before any tool calls, such as user input fields or session state | {"customer_id": "cust_421", "lookback_days": 30} | Must be valid JSON or null. If provided, all referenced fields must exist. Null allowed when no prior context exists. |
[MAX_STEPS] | Integer upper bound on the number of sequential tool calls to prevent runaway chains | 5 | Must be a positive integer between 1 and 20. If exceeded during execution, the chain must abort and return a partial-results error. Default: 10. |
[OUTPUT_SCHEMA] | JSON Schema describing the required structure of the final execution plan | {"type": "object", "properties": {"steps": {"type": "array"}}, "required": ["steps"]} | Schema check: must be valid JSON Schema draft-2020-12 or later. Required fields must include steps array. Each step must have tool_name, arguments, and depends_on_step fields. |
[FIELD_MAPPING_RULES] | Instructions for how output fields from one step map to input parameters of subsequent steps | "Use exact field name matching. If step N returns 'order_ids', step N+1 may reference it as [STEP_N.output.order_ids]" | Non-empty string. Must specify reference syntax for upstream outputs. Parse check: downstream argument references must resolve to declared output fields of upstream steps. |
[MISSING_FIELD_POLICY] | Instruction for how to handle required downstream inputs that are not present in upstream outputs | "If a required input field is missing from upstream output, mark the step as BLOCKED and include the missing field name in the plan's warnings array" | Must be one of: BLOCKED, USE_DEFAULT, PROMPT_USER, or SKIP_STEP. If USE_DEFAULT, a defaults map must also be provided. Null not allowed. |
[CONFIDENCE_THRESHOLD] | Minimum confidence score (0.0 to 1.0) required for each field mapping to be accepted without human review | 0.85 | Must be a float between 0.0 and 1.0. Mappings below this threshold must be flagged for review in the plan output. Default: 0.8. |
Implementation Harness Notes
How to wire the sequential chaining prompt into an application, validate the output, and execute the plan safely.
The sequential chaining prompt produces a structured execution plan, not a final answer. Your application must parse this plan, execute each tool call in the specified order, feed intermediate outputs into subsequent inputs, and handle failures at any step. Treat the prompt output as a machine-readable directive, not a suggestion. The plan includes explicit data mappings between steps—your harness must enforce those mappings by extracting the declared fields from each tool response and injecting them into the next call's arguments. If a step produces an unexpected shape, stop the chain rather than guessing.
Implement a stateful execution loop that reads the model's JSON plan and maintains a context accumulator. For each step, validate that all required input fields from prior steps are present and correctly typed before calling the tool. Use a schema validator (such as Pydantic or Zod) to check each intermediate output against the expected fields declared in the plan's data mapping. If validation fails, log the mismatch, capture the raw output, and either retry with a repair prompt or escalate to a human reviewer. For high-risk workflows—financial transactions, clinical data, legal filings—insert a confirmation gate between steps where a human must approve the accumulated state before the next tool call executes. Log every step's input, output, latency, and validation result to an observability backend for debugging and audit.
Choose a model with strong structured output support and reliable tool-call argument generation. GPT-4o, Claude 3.5 Sonnet, and Gemini 1.5 Pro are suitable defaults. Set temperature=0 or near-zero to maximize plan determinism. Implement a retry budget per step: if a tool call fails due to a transient error, retry up to three times with exponential backoff. If a step fails due to a validation error, feed the error message and raw output into a repair prompt that attempts to fix the malformed result before retrying. If the repair fails or the step exhausts its retry budget, abort the chain, preserve partial progress, and route to a human-in-the-loop queue. Never silently skip a failed step or fabricate missing intermediate data—the chain's integrity depends on every output being real and verified.
Expected Output Contract
The fields your parser should expect from the sequential chaining prompt, their types, and pass/fail conditions. Use this contract to build a validation layer before executing any tool calls.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
execution_plan | array of objects | Must be a non-empty array. Each element must have a step_number, tool_name, and arguments field. Reject if array is empty or not present. | |
execution_plan[].step_number | integer | Must be a positive integer starting at 1 and incrementing by 1 with no gaps. Validate sequence continuity: step N+1 must equal step N + 1. | |
execution_plan[].tool_name | string | Must match an entry in the [TOOL_REGISTRY] list. Case-sensitive exact match required. Reject unknown tool names. | |
execution_plan[].arguments | object | Must be a valid JSON object. Each key must match a parameter name from the tool's schema in [TOOL_REGISTRY]. Reject if arguments is null, missing, or contains undeclared keys. | |
execution_plan[].depends_on_step | integer or null | If not null, must reference a valid step_number that appears earlier in the plan. Reject if self-referencing, referencing a future step, or referencing a non-existent step. | |
execution_plan[].output_mapping | object | Each key must be a parameter name in this step's arguments. Each value must be a JSONPath expression referencing a field in the output of the step specified in depends_on_step. Reject if mapping references a step with no depends_on_step relationship. | |
execution_plan[].expected_output_schema | object | If present, must be a valid JSON Schema fragment describing the expected shape of the tool's output. Used for pre-execution compatibility checks. Null allowed. | |
execution_plan[].fallback_step | integer or null | If not null, must reference a valid step_number that appears later in the plan or be set to -1 to indicate abort. Reject if referencing the current step or a step with a circular fallback chain. |
Common Failure Modes
What breaks first when chaining tool calls sequentially and how to guard against it.
Intermediate Output Schema Drift
What to watch: A tool's output changes shape (field renamed, type changed, optional removed) and the next step in the chain receives malformed input. The model may hallucinate missing fields or silently pass incorrect data. Guardrail: Validate each intermediate output against its expected schema before passing it to the next tool. Use strict JSON Schema validation with additionalProperties: false and required field checks at every step boundary.
Missing Intermediate Field Propagation
What to watch: A tool returns a partial or empty result for a field that the next tool requires. The model either invents a value to keep the chain moving or calls the downstream tool with null/empty arguments that cause a cryptic failure. Guardrail: Insert a field-presence check after each tool call. If a required downstream field is missing, halt the chain and return a structured error with the missing field name and source tool, rather than proceeding with incomplete data.
Context Window Exhaustion Mid-Chain
What to watch: Each tool call adds its full output to the context window. By step three or four, the accumulated intermediate results push critical instructions or earlier context out of the model's attention. The model loses track of the original goal or skips validation rules. Guardrail: Summarize or extract only the downstream-relevant fields from each intermediate result before appending to context. Set a token budget per step and truncate verbose outputs to the fields declared in the data mapping specification.
Silent Type Coercion Between Steps
What to watch: Tool A returns a number as a string, and Tool B expects an integer. The model passes the value without conversion, and the downstream tool either rejects it or behaves unpredictably. Guardrail: Define explicit type coercion rules in the data mapping between steps. Validate that each passed value matches the target tool's parameter type before execution. Reject the chain step with a type-mismatch error rather than relying on the model to convert correctly.
Chain Continuation After Partial Failure
What to watch: A mid-chain tool call fails or returns an error, but the model continues executing subsequent steps using stale, empty, or hallucinated data from the failed step. The final result looks plausible but is built on a broken foundation. Guardrail: Implement a hard stop on any non-successful tool response. Define a chain-level abort condition that triggers when any step returns an error status. Log the failure point, preserve partial results for debugging, and escalate rather than continuing.
Stale Reference to Prior Step Output
What to watch: The model references a field from step 1 when constructing arguments for step 3, but step 2 modified or filtered that data. The chain proceeds with outdated values because the model didn't track the transformation. Guardrail: Require explicit data lineage in the prompt: each step must declare which prior step's output it consumes and which fields it transforms. Validate that referenced fields exist in the declared source step's output before allowing the next call.
Evaluation Rubric
Criteria for evaluating the quality of a sequential chaining plan before deploying the prompt to production. Use these checks in your eval harness, CI pipeline, or manual review process.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Step ordering validity | All steps respect declared input-output dependencies; no step consumes an output from a later step | A step references [OUTPUT] from a step that appears after it in the sequence | Topological sort check: parse the execution plan and verify each dependency edge points to an earlier step index |
Intermediate field mapping completeness | Every required input field for each step is mapped from a prior step output, [USER_INPUT], or a declared default | A step has a required input field with no source mapping and no default value | Schema diff: for each step, subtract available fields from required inputs; flag any unmapped required fields |
Type compatibility across steps | The type of each mapped output field matches or is safely coercible to the expected input type of the consuming step | A string output is mapped to an integer input without an explicit transformation rule | Type check: compare JSON Schema types of source output and target input; flag mismatches without coercion rules |
No circular dependencies | The dependency graph contains zero cycles; every execution path terminates | Step A requires output of Step B, and Step B requires output of Step A | Cycle detection: run depth-first search on the dependency graph; fail if any back-edge is found |
Missing intermediate field handling | The plan specifies behavior when an intermediate output field is null, absent, or partial: skip step, use default, retry, or escalate | A required intermediate field is absent and the plan proceeds without a defined fallback | Null injection test: simulate a prior step returning null for a mapped field; verify the plan either halts, retries, or substitutes a declared default |
Output-to-input data transformation clarity | Any non-trivial transformation between steps (rename, reshape, aggregate, filter) is explicitly described with a transformation rule | A field is mapped between steps with different structures but no transformation rule is specified | Transformation audit: for each mapped field, check if source and target schemas match; flag structural mismatches without a transformation rule |
Plan-level abort and escalation conditions | The plan defines stopping conditions: max total steps, timeout, consecutive failures, or confidence drop below [CONFIDENCE_THRESHOLD] | The plan describes an unbounded sequence with no termination criteria | Boundary test: run the plan with a simulated persistent failure at step 2; verify the plan halts within the declared limit rather than continuing indefinitely |
Intermediate result observability | Each step's output is logged or returned in a structured trace so failures can be attributed to a specific step | A step fails and the trace does not identify which step produced the bad output | Trace completeness check: inject a deliberate schema violation at step 3; verify the error report includes step index, tool name, and the offending output |
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 small set of known tools and a single dependency chain. Remove strict output schema validation and allow the model to describe the sequence in prose before converting to structured JSON. Start with two or three tools that have obvious input-output dependencies.
Watch for
- The model skipping intermediate steps and hallucinating final results
- Missing field mappings when tool output field names don't match the next tool's input field names
- Overly broad instructions that cause the model to invent tool calls not in the provided set

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