How to secure a LangChain agent before your first enterprise demo
In-depth analyses of real-world cyber incidents and emerging threat trends, authored exclusively by our analysts.
You have built a LangChain agent, it works, and an enterprise prospect wants a demo. Before you put it in front of a buyer whose security team will eventually probe it, there are specific weaknesses worth closing, because LangChain's flexibility, the very thing that made it fast to build with, is also where the security risks live. This guide walks through the real attack vectors that affect LangChain agents and the concrete mitigations for each, written for the engineer who has to harden the thing, not just read about it in the abstract.
A note on scope. This is about the practical hardening you can do before a demo, focused on the issues that actually matter for an agent that uses tools and touches data. It is not a substitute for a full security review, but it will close the gaps most likely to embarrass you in front of a serious buyer.
Why LangChain agents have a distinctive attack surface
A LangChain agent is not just an LLM call. It is glue code, an LLM that makes decisions, and a set of tools the LLM can choose to invoke, often with real permissions to query databases, call APIs, run code, or touch the file system. That combination creates a hybrid attack surface. You have the normal risks of application code, plus the LLM layer where prompt injection lives, plus tools that can do real damage if the LLM is manipulated into misusing them.
The single most important mental shift is this. Your agent will, at some point, process text that an attacker controls, whether through user input or through content it retrieves. You must design so that when that happens, the worst case is contained. Everything below follows from that principle.
Attack vector one, direct prompt injection
The most familiar risk. A user inputs something like instructions to ignore the agent's real purpose and do something else instead, attempting to override your system prompt. For an agent with tools, the danger is not just a rude response, it is the agent being talked into invoking a tool it should not.
The mitigations that genuinely help, layered together. Separate instructions from data clearly in your prompt construction, for example by enclosing user supplied content in delimiters and instructing the model to treat anything inside them strictly as content to be processed, never as instructions to follow. Do not rely on this alone, because prompt level defences are not absolute, but it raises the bar. The more important mitigation is downstream. Even if the model is manipulated, the tools it can reach should be so tightly scoped that a successful injection cannot cause real harm, which is the least privilege principle covered below.
Attack vector two, indirect prompt injection
This is the one that catches teams out, and it is more dangerous than direct injection because it does not require the user to be malicious. Indirect injection happens when your agent processes external content that contains hidden instructions. A classic example is an agent that summarises a web page or retrieves a document in a RAG pipeline, where the page or document contains text crafted to hijack the agent, such as content that reads as a new instruction rather than data to summarise.
Because the malicious instruction arrives through a data source the agent trusts, the agent may treat it as a legitimate command. The mitigations. Treat all retrieved and external content as untrusted, exactly as you would treat raw user input. Apply the same instruction and data separation to tool outputs and retrieved documents, not just to the user's message. And critically, never let content fetched from an external source flow straight into a tool invocation without constraints, because that is the path from a poisoned document to a real action.
Attack vector three, excessive agency and over-permissioned tools
This is the highest impact risk and the one most worth fixing before a demo. Excessive agency means your agent has tools that can do more than the task requires. If your agent only needs to read from a database, but the tool you gave it can also write or delete, then a single successful injection turns a minor manipulation into a serious breach.
The mitigation is least privilege, applied ruthlessly to every tool. Each tool an agent can call should have the minimum permission necessary and nothing more. A tool that answers questions from a product database should have read only access scoped to that database, never write access and never the ability to run arbitrary queries or commands. Be especially wary of the powerful, flexible components that make LangChain convenient but dangerous, the ones that can execute code or run arbitrary database statements. These have been the source of real disclosed vulnerabilities, and they should be avoided in anything customer facing, or sandboxed heavily if genuinely required. If you remember one thing from this article, make it this. Constrain what the tools can do, so that being injected is survivable.
Attack vector four, unsafe tool implementations
Beyond permissions, the tools themselves can be insecure in classic ways. A tool that builds a database query from model output can be vulnerable to injection in the traditional sense. A tool that takes a file path from the agent can be tricked into reading files it should not. A tool that executes code is a remote code execution risk if the agent can be steered into abusing it.
The mitigations are familiar application security, applied at the tool boundary. Validate and constrain every input a tool accepts, ideally with strict typed validation so the tool only ever receives well formed, expected parameters. Never pass model output directly into a sensitive operation without checking it. Treat the boundary between the agent and each tool as a trust boundary, where the tool defends itself rather than assuming the agent will only ever send safe input.
Attack vector five, memory and context poisoning
Agents that retain memory across a conversation or session introduce another vector. If an attacker can get malicious content into the agent's memory, it can influence later actions, even after the original input is gone. This is subtle because the harm can surface turns later.
The mitigations. Be deliberate about what goes into persistent memory, and do not blindly store raw inputs or tool outputs that could carry instructions. Where memory persists across users or sessions, ensure it is properly isolated so one user cannot poison another's context, which is the agent specific version of tenant isolation. And avoid insecure serialisation formats for persisting state, because unsafe deserialisation has been a real source of vulnerabilities, prefer safe, structured formats over anything that can execute on load.
Attack vector six, no human checkpoint on consequential actions
Finally, the question of what happens when the agent wants to do something irreversible. Sending an email, writing to a database, making a payment, deleting something. The risk here is not only attack, it is also the agent simply getting it wrong, fixating on a goal and taking a destructive path to it.
The mitigation is a deliberate checkpoint before irreversible actions. For the high stakes, hard to undo operations, require an explicit approval step rather than letting the agent execute autonomously, at least until you have strong confidence in the constraints around it. The distinction that matters is reversibility. Reads and draft generation can run freely. Anything that leaves the system or cannot be undone deserves a gate. This is more nuanced than a blanket human in the loop on everything, which tends to fail because reviewers stop paying attention, so reserve the checkpoint for the actions where it genuinely matters.
A pre-demo hardening checklist
Pulling it together, here is what to run through before you put the agent in front of an enterprise prospect.
- Every tool is scoped to least privilege, read only where possible, with no tool able to do more than its task requires.
- The dangerous, arbitrary-execution components are removed from anything customer facing, or heavily sandboxed if unavoidable.
- User input and external or retrieved content are both treated as untrusted, with instructions and data clearly separated.
- Every tool validates its own inputs strictly, rather than trusting model output.
- Persistent memory is deliberate, isolated between users, and uses safe serialisation.
- Irreversible actions require an explicit approval checkpoint.
- You log what the agent did and what tools it called, so you can answer a buyer's questions about auditability.
If you can tick those, you have closed the gaps most likely to be found in a security review, and you can demo with far more confidence.
The honest takeaway
Securing a LangChain agent is less about any single clever defence and more about a layered posture. Assume the model can be manipulated, and make sure that when it is, the tools are too constrained for it to matter. Treat all external content as untrusted, validate at every tool boundary, isolate memory, and gate the irreversible actions. The flexibility that made LangChain fast to build with is exactly what you are reining in, and doing so deliberately before a demo is what separates an agent that survives enterprise scrutiny from one that quietly loses the deal.
None of this is a one time exercise, since both your agent and the attacks against it will evolve, but getting these fundamentals right before your first enterprise demo puts you in a genuinely strong position.
Want an expert check of your AI agent before the demo?
Book a free review and we'll probe your agent for these exact risks, and show you what a buyer's security team would find.
AI Security Insights
AI agent threat modelling: how to map attack surfaces before enterprise procurement asks
Most AI startups discover their attack surface the hard way, when an enterprise buyer's security team maps it for them…
Read articleHow to prevent PII leaking into your LLM API calls (a practical guide for AI startups)
Every AI startup building on a hosted model has the same quiet problem. On every API call, your product sends data to a…
Read articleHow to secure a LangChain agent before your first enterprise demo
You have built a LangChain agent, it works, and an enterprise prospect wants a demo. Before you put it in front of a bu…
Read articleAI security tools for startups compared. Mindgard, Noma, Giskard, and CYBNODE.
If you are an AI startup searching for an AI security tool, you have probably come across names like Mindgard, Noma, an…
Read articleMore insights, delivered monthly
Get the latest insights on AI security and compliance.

