# How to Handle Prompt Injection in Web Research Agents > Build web research agents that treat retrieved pages as untrusted evidence, limit tool permissions, validate outputs, and review consequential results. - Canonical URL: https://replynodes.com/blog/prompt-injection-web-research-agents/ - Published: 2026-11-01 - Updated: 2026-11-01 - Author: ReplyNodes Team - Publisher: ReplyNodes (https://replynodes.com/) A web research agent needs to read material it does not control. That material might contain useful evidence, misleading claims, or text intended to manipulate the agent. The design goal is not to make every retrieved page trustworthy. It is to keep untrusted content from becoming instructions, and to limit what the agent can do if it is influenced by that content. OWASP identifies prompt injection as a risk for large language model applications. In a research agent, the risk can arrive directly in a user’s request or indirectly through retrieved content, such as a web page or tool output. These are different entry points, but both can try to steer the model away from its intended task. [OWASP LLM01:2025 — Prompt Injection](https://genai.owasp.org/llmrisk/llm01-prompt-injection/) This guide outlines a defense-in-depth workflow for building a research agent that treats retrieved pages as untrusted evidence rather than policy. ## Direct and indirect prompt injection **Direct prompt injection** comes from content supplied as part of the user’s interaction—for example, a request that tries to override the agent’s task or instructions. **Indirect prompt injection** arrives through material the agent retrieves or processes. A page might include text addressed to an AI system, such as a request to ignore prior directions, reveal private information, or take an unrelated action. The agent may encounter that text while trying to extract facts from the page. The key distinction is where the attempted instruction enters. For a web research agent, retrieved content is a particularly important boundary: the agent needs to inspect it, but should not treat it as an authority over its behavior. ## A safer research workflow ### 1. Narrow retrieval to the research task Retrieve only the sources and content needed to answer the user’s question. Set practical limits on the scope of retrieval, such as permitted source types, page counts, or content size, where appropriate for the application. Narrow retrieval is a risk-reduction measure, not a trust signal. A relevant page can still contain malicious or misleading text, and a reputable-looking source is not an instruction channel. ### 2. Preserve provenance and label retrieved content Keep each passage associated with its source URL and retrieval context. Clearly separate retrieved text from system and developer instructions in the data you pass to the model. Label it as untrusted evidence, and tell the model to analyze or quote it only in service of the research task—not to follow directions found inside it. For example, keep retrieved passages in application data with stable IDs, then provide them as evidence—not by concatenating them into the trusted instruction text: ```python import json page_text = "The report says the service launched in June." sources = [ {"id": "s1", "url": "https://example.org/report", "text": page_text} ] trusted_task = "Summarize the evidence for the user's question. Cite source IDs." untrusted_evidence = json.dumps(sources, ensure_ascii=False) # In your model adapter, send trusted_task through its instruction channel # and untrusted_evidence as a separate data input. Adapter field names vary. # Afterward, reject citations whose IDs are not in this retrieved set. known_ids = {source["id"] for source in sources} model_result = {"summary": "The service launched in June.", "source_ids": ["s1"]} assert all(citation_id in known_ids for citation_id in model_result["source_ids"]) ``` The final assertion checks citation references only; it does not prove a cited passage supports a claim. Keep the URL with each ID so a human or a separate verifier can inspect that support. The task and evidence are still interpreted by the same model, so separation, labels, and citation checks do not guarantee that an embedded instruction will be ignored. ### 3. Give tools the least privilege needed A research agent should have access only to tools and permissions needed for research. If its job is to retrieve and summarize public information, avoid giving it unrelated capabilities such as sending messages, changing account settings, or executing consequential operations. Review tool behavior and possible side effects—not just tool names. Tool descriptions or annotations may help communicate intended behavior, but should not be treated as proof that a tool is harmless or that the runtime enforces the intended policy. The [MCP tools specification](https://modelcontextprotocol.io/specification/2025-06-18/server/tools) notes that tools can interact with external systems and says clients must treat tool annotations as untrusted unless they come from trusted servers. The [MCP security best practices](https://modelcontextprotocol.io/docs/tutorials/security/security_best_practices) provide additional security guidance. Require an explicit confirmation step before any consequential action that the application allows. Better still, keep actions outside the research agent’s tool set unless they are genuinely required. ### 4. Keep the agent’s task and boundaries explicit State the research goal, the distinction between trusted instructions and untrusted retrieved material, and the allowed tools. Tell the agent to treat directions found in retrieved content as content to assess, not commands to execute. Do not rely on wording alone. A model instruction can clarify the intended behavior, but it cannot guarantee resistance to prompt injection. Pair it with narrow permissions, validation, and review. ### 5. Validate outputs before using them Check that an answer follows the expected structure and stays within the requested task. For machine-consumed results, use a defined schema and reject or route for review outputs that do not meet it. Validate consequential fields and actions in application code rather than assuming that a well-formed answer is safe or correct. Structured output can make validation easier; it does not establish that the model’s claims are true, that source text was handled safely, or that an answer contains no sensitive information. ### 6. Monitor and include human review Log enough information to investigate failures, such as the task, relevant source URLs, tool calls, validation outcomes, and whether a reviewer intervened. Handle logs carefully: they may contain user or retrieved content and should not become an unnecessary exposure path. Use human review where the consequences of an incorrect or manipulated answer justify it. Review is especially important before outputs are used for decisions or passed to another system with broader permissions. Monitoring and review can help detect problems; neither guarantees that every attack will be found. ## What a read-only boundary does—and does not—do A read-only retrieval boundary can limit the agent’s ability to mutate external systems through that boundary. That is useful for reducing the scope of possible side effects. It does **not** make retrieved text safe. It cannot guarantee that the model’s output will be accurate, prevent the model from exposing information available in its context, or neutralize an instruction embedded in a page. Read-only access is one layer in the design, not a prompt-injection detector or a complete security control. ReplyNodes is a read-only public-data retrieval boundary. It does not claim to detect prompt injection or protect against misleading output or data exposure. See the [security documentation](/security/) and [API documentation](/api/) for relevant product details. For a broader research workflow, see [How to Build an AI Web Research Agent](/blog/build-ai-web-research-agent/) and [How to Debug AI Agent Web Research](/blog/debug-ai-agent-web-research/). ## FAQ ### Is text on a web page an instruction to the research agent? No. The agent may analyze page text as evidence, but should not treat directions found in retrieved content as policy or commands. Keep retrieved material separate from trusted instructions and preserve its source. ### Does read-only web access prevent prompt injection? No. Read-only access can limit mutation side effects through that boundary, but it does not guarantee safe or accurate output, prevent data exposure, or neutralize malicious page content. ### Should a research agent be allowed to take actions based on a retrieved page? Only if those actions are genuinely needed and the agent has appropriate safeguards. Limit tool permissions, validate proposed actions, and require confirmation for consequential operations. Tool descriptions alone should not be treated as enforcement.