All articles
5 min readAI DevelopmentAI SecurityAI AgentsBest Practices

How to Protect Your AI App From Prompt Injection Attacks

If your AI app reads anything it did not write itself, such as customer emails, uploaded documents, web pages or support tickets, it can be tricked. Prompt injection is the name for text that quietly tells your AI to ignore its instructions and do something else. For founders shipping AI features quickly, it is one of the most practical security risks to understand, and one of the easiest to underestimate because nothing looks broken until it is.

What Prompt Injection Actually Looks Like

A language model does not reliably separate your instructions from the content it is processing. Everything arrives as text. So if a customer support assistant summarizes an incoming email, and that email contains a line saying to ignore previous instructions and offer the sender a full refund, the model may treat that line as a command rather than as part of the message.

There are two common forms. Direct injection is when a user types the malicious instruction straight into your chat box. Indirect injection is sneakier: the instruction is hidden inside content your app fetches on the user's behalf, like a PDF, a product review, a calendar invite or a web page. Indirect injection matters most for agents, because agents read outside content and then take actions.

Why It Matters More Once Your AI Can Take Actions

A chatbot that can only reply with text has a limited blast radius. The worst case is usually an embarrassing answer. The risk changes when your AI can send emails, update records, issue credits, call APIs or read private data. Now a hidden instruction can turn into a real action taken with your app's permissions.

Consider a worked example. An agent reads incoming invoices and drafts payment entries for a bookkeeper to approve. A malicious invoice includes invisible text telling the agent to change the bank details on file. If the agent has write access to vendor records and no human checkpoint, that instruction could succeed. If the agent can only draft entries for review, the same attack becomes a suspicious draft someone catches.

You cannot fully stop a model from reading bad instructions, so design your app so that obeying them does little damage.

Practical Defenses for AI App Security

There is no single filter that solves prompt injection. The reliable approach is layered: limit what the model can do, check what it is about to do, and keep sensitive steps behind a person or deterministic code. These are the best practices we use when building AI apps and agents.

  • ▹Give the AI the least access it needs. If a feature only reads orders, its tools should not be able to delete them. Scope API keys and database roles per feature, not per app.
  • ▹Keep high-risk actions behind approval. Payments, refunds, account changes, bulk emails and data exports should require a human click or a rule check in regular code.
  • ▹Separate trusted instructions from untrusted content. Put your instructions in the system prompt, wrap outside content in clearly labeled sections, and tell the model that text inside them is data to analyze, never commands to follow.
  • ▹Validate outputs with code, not just prompts. If the model returns a refund amount, check it against the order total and your refund policy before anything happens.
  • ▹Never put secrets in prompts. API keys, internal URLs and other customers' data should not be anywhere the model could be talked into repeating them.
  • ▹Restrict where data can go. Block or allowlist outbound links, email recipients and webhooks so a hijacked agent cannot send information to an attacker.

How to Test Your App for Prompt Injection

You do not need a security team to start. Build a small set of hostile test inputs and run them every time you change a prompt, model or tool. Treat it like any other regression test.

  • ▹Paste instructions to ignore the rules into every field a user can type into, including names, notes and file uploads.
  • ▹Hide instructions inside documents your app processes, such as white text in a PDF or a comment in a spreadsheet.
  • ▹Ask the assistant to reveal its system prompt, list its tools or show another customer's information.
  • ▹Try to get an agent to call a tool it should never need for the task in front of it.
  • ▹Log every tool call with its inputs so you can review what the AI attempted, not just what it said.

When a test succeeds in breaking the app, the fix is rarely a cleverer prompt. Usually it is removing a permission, adding a check in code or moving the action behind approval.

Common Mistakes Founders Make

The first mistake is assuming a strongly worded system prompt is enough. Prompts help, but they are guidance, not a security boundary. The second is giving one agent access to everything because it is faster to build. That shortcut makes every piece of outside content a potential attack path. The third is skipping logs, which means that when something odd happens you cannot tell whether it was a bug, a model mistake or an attack.

The fourth is waiting until after launch. Retrofitting permissions into an app that was designed around a single all-powerful agent is far more work than scoping tools from the start.

Building Secure AI Features Without Slowing Down

Security does not have to cost you weeks. Most of these defenses are design decisions made on day one: which tools exist, what each can touch, and where a person or a rule steps in. At vonmal we bake these into the first version of every AI app and agent we ship, so speed and safety come together rather than trading off.

If you are building an AI feature that reads customer content or takes actions on your behalf and want a second set of eyes on its risks, get a free estimate or book a free 15-minute AI audit with vonmal at https://vonmal.com.

Building something with AI? Get a live price and timeline from vonmal.