Prompting technique

Context-Chained Prompting

Context manipulation attacks : Web agents are susceptible to corrupted memory, arXiv:2506.17318 (2025) · read the paper

What it does

A technique for building cause-and-effect chains in prompts, where each subsequent step explicitly relies on the result of the previous one. Creates an unbreakable logical sequence of actions, transforming a prompt from a set of instructions into a clear algorithm. Based on the principle of context-linked prompting to improve accuracy in complex tasks.

Task typemulti step
Shapechain of thought
Efforttwo or three steps
Addressesrefusals on legitimate requests; the model losing what was agreed earlier; the same prompt giving different answers
Published2025-06-18
AuthorsAtharv Singh Patlan, Ashwin Hebbar, Pramod Viswanath et al.

When it helps

Apply this technique when creating complex multi-step prompts for LLM agents, when a task requires sequential execution of several related actions. Particularly useful in developing secure systems where context manipulation prevention is important. Use for building reliable chains of reasoning where each step logically follows from the previous one. Critical when working with web agents, RAG systems, and automated assistants where the agent interacts with external

A prompt you can paste

Generic by design: it applies the technique without knowing your task. Adapt the marked parts.

Prompt
**Role:** You are an AI agent designed to perform web-based tasks.

**Task:** Execute a series of web searches and analyses to achieve a user-defined goal.

**Context:**
- **User's Original Goal:** [User's primary objective, e.g., "Research the market for sustainable packaging solutions."]
- **Initial Search Query:** [The first search query derived from the user's goal, e.g., "sustainable packaging market trends 2024"]

**Execution Plan (Context-Chained Prompting Method):**

Follow this logical sequence, ensuring each step naturally builds upon the previous one.

**Step 1: Initial Information Gathering**
- **Action:** Perform a web search using the provided "Initial Search Query".
- **Analysis:** Identify and extract the top 3-5 most relevant search results. For each result, summarize its key findings and provide the URL.
- **Output:** Present the summaries and URLs.

**Step 2: Deep Dive into Key Findings**
- **Based on the analysis in Step 1**, identify the most promising or critical pieces of information (e.g., emerging trends, key players, challenges).
- **Action:** For each identified key finding, formulate a more specific follow-up search query (e.g., "leading companies in biodegradable packaging" or "challenges in scaling bioplastics").
- **Analysis:** Execute these follow-up searches and summarize the findings from the top 1-2 results for each query.
- **Output:** Present these detailed findings, clearly linked to the findings from Step 1.

**Step 3: Synthesize and Identify Potential Risks/Opportunities**
- **Building upon the detailed findings from Step 2**, synthesize the information to identify overarching themes, potential market opportunities, and any potential risks or limitations associated with the user's original goal.
- **Action:** Formulate a final set of focused queries to investigate these specific risks or opportunities (e.g., "regulatory landscape for sustainable packaging in EU" or "consumer perception of recycled materials in food packaging").
- **Analysis:** Execute these final searches and summarize the critical insights.
- **Output:** Present a synthesized overview of opportunities and risks, supported by the information gathered in this step.

**Step 4: Final Report Generation**
- **Consolidating all previous steps**, generate a comprehensive report that addresses the user's original goal.
- **Structure:**
    - Executive Summary (brief overview of findings)
    - Detailed Findings (from Steps 1, 2, and 3, clearly organized)
    - Identified Opportunities
    - Identified Risks/Challenges
    - Recommendations (based on the gathered information)
- **Output:** The final report.

**Constraint:** At each step, ensure the actions and analysis are a logical and direct continuation of the previous step's outcome, directly serving the "User's Original Goal". Do not introduce unrelated tasks.

If this one does not fit, the two closest alternatives in the corpus are Sandwich Prompting and Polymorphic Prompt Assembling (PPA), which target the same failure from a different angle.

Worked example

The same technique applied to a concrete job: turn a vague goal into an ordered plan with checkpoints. Use it as the pattern for your own case rather than as a finished artefact.

Worked example
**Role:** You are an AI agent designed to perform web-based tasks. Your primary function is to execute user-defined plans, search for information, and interact with web tools.

**Task:** Execute the following plan to gather information about "Context manipulation attacks on web agents" and summarize the findings.

**Context:** The user is interested in understanding how AI agents can be manipulated through their internal "plan of action" or "memory," specifically focusing on attacks that disguise malicious commands as logical next steps within a task.

**Plan of Action (Context-Chained Prompting):**

**Step 1: Initial Information Gathering**
*   **Action:** Search the web for academic papers, security research articles, and reputable tech blogs discussing "Context manipulation attacks on web agents," "corrupted memory in AI agents," and "context-chained injection."
*   **Checkpoint:** Identify at least 3-5 high-quality sources that explain the core mechanism of these attacks.

**Step 2: Mechanism Analysis (Building on Step 1)**
*   **Context:** Based on the sources found in Step 1, analyze *how* these attacks work. Focus on the principle of disguising malicious commands as natural continuations of the user's original task.
*   **Action:** Summarize the "logical bridge" or "chain" that attackers create between the legitimate task and the malicious payload. Explain why this method is more effective than direct command injection.
*   **Checkpoint:** Clearly articulate the "Principle of the Logical Bridge" as described in the research.

**Step 3: Practical Application (Adaptation for Defense)**
*   **Context:** Given the understanding from Step 2 that AI agents follow logical chains, consider how this principle can be used defensively to improve prompt reliability.
*   **Action:** Formulate a strategy for creating robust prompts that minimize the risk of such manipulation. This should involve structuring prompts as a clear, step-by-step plan where each step explicitly relies on the outcome of the previous one. Provide a hypothetical example of how a user might structure a prompt to achieve a specific goal (e.g., researching a topic, planning an event) using this chained approach.
*   **Checkpoint:** Define 3 key characteristics of a "manipulation-resistant" prompt structure.

**Step 4: Synthesis and Summary**
*   **Context:** Consolidate all findings from Steps 1, 2, and 3.
*   **Action:** Provide a concise summary that covers:
    1.  The nature of context manipulation attacks on web agents.
    2.  The core mechanism ("logical bridge").
    3.  The defensive strategy of using chained prompts for improved reliability.
*   **Final Output:** Present the summary in a clear, structured format.

**Execution Constraints:**
*   Prioritize information from academic sources and well-known cybersecurity research platforms.
*   Ensure that the explanation of the attack mechanism is clear and easy to understand.
*   The defensive strategy should be actionable for a user creating prompts.
*   Do not execute any actions that could be construed as malicious or harmful.

Get this written for your actual task

Paste what you are trying to do and the corpus will be matched against it directly. Free, no account, about ten seconds.

Free · no signup · ~10s
0.00match confidence
single retrieval pass
Prompt for your task

      

That number is low on purpose, and it is real. It is the raw similarity of one retrieval pass: no specialist read the paper, no judge compared anything, the first plausible match won.

6,235techniques in the corpus
one of which is this page

Picking the right one for a specific task is the work, and it is the work GetDecision does.

This pageone technique, generic prompt
What you just ranone technique matched to your wording, nothing verified
Full runten specialists read the papers in full, a judge ranks the top three for your task and shows its reasoning, generation on the model you pick, saved to your history

See the top three for your taskTen specialists, a judge, and the reasoning shown. Free account, first run included.

Run the full analysis

Related techniques

Sandwich PromptingSandwich Prompting — a technique for protecting against indirect prompt injections, in which potentially dange…Polymorphic Prompt Assembling (PPA)A method of protection against prompt injection through random generation of unique delimiters for wrapping un…Multi-Turn Conversational PromptingMethod of multi-step dialog interaction with LLM where complex tasks are broken into a chain of simple steps. …Debugging Prompts FrameworkA systematic framework for diagnosing and preventing typical errors of language models in instruction understa…

All techniques · Failure modes and fixes