Skip to content
VITI Security

Why LLM Output Filtering Is Not Enough: Securing What Your Model Says and Does

Output filters are a useful last check, but they cannot reliably catch data leaks, prompt injection or unsafe tool calls. Why, and the layered controls that secure an LLM application.

Why LLM Output Filtering Isn't Enough - A Defender's Stack - VITI Security

Many teams building on large language models add an output filter and consider the job done: a classifier or a list of patterns that blocks harmful or sensitive responses before they reach the user. Filters help, but they are the last and weakest line of defence. They cannot see what the model should not have known in the first place, they are easy to slip past with rephrasing or encoding, and they do nothing about actions the model takes through tools. This guide explains where output filtering falls short and the controls that do the real work.

What output filters do well

A filter is useful for catching clear, recognisable problems: card numbers or ID numbers in a response, obvious toxic content, known secret formats such as API keys, and responses that break your content policy. It also gives you a log of what was blocked, which helps tuning. Keep one. Just do not rely on it alone.

Where output filtering fails

Attackers and accidents get past filters in predictable ways.

  • Rephrasing and encoding: a model asked to answer in base64, another language, a poem or one character per line produces text no pattern matches.
  • Context it should never have had: if the model can read a document the user is not allowed to see, filtering the answer is a guess about what to hide. The real fix is not giving it the document.
  • Partial leaks: a summary, a paraphrase or a yes-or-no answer can reveal confidential facts without matching any sensitive pattern.
  • System prompt leakage: instructions and business rules in the system prompt can be extracted in pieces.
  • Actions, not words: when the model calls tools, the harm is the email sent or the record changed, which an output filter on the chat text never sees.
  • Downstream injection: output rendered as HTML, run as code or passed into a database query can carry cross-site scripting or injection, which OWASP lists as improper output handling.

Why the problem is getting bigger

Early LLM features were chatbots that only produced text. Today the same models summarise inboxes, answer from company knowledge bases, write and run code and call business APIs. Each new capability widens the gap between what an output filter can check and what the model can actually do. A filter on the chat window cannot see an email the model sent, a file it shared or a database row it changed. The more your LLM feature can reach, the more of your security has to sit outside the model, in access control and in the tools themselves.

Control what the model can see

Most data leaks through LLMs are access control problems. Apply the user's permissions at retrieval time, so a knowledge-base chatbot only retrieves documents that user may read. Keep secrets, credentials and internal business rules out of system prompts, and assume anything in the prompt can be extracted. Minimise the personal data you send to the model at all, using redaction or tokenisation where the task allows.

Control what the model can do

If the model can call tools, design for the case where it is tricked by prompt injection. Run tools with the requesting user's permissions, allow only the specific actions the feature needs, validate every tool call against rules written in code rather than in the prompt, and require a person to confirm anything irreversible. Our AI agent security guide covers these controls in more depth.

Treat model output as untrusted input

Wherever model output goes next, handle it as you would input from an anonymous user. Encode it before rendering in a browser. Never pass it straight into a shell, an eval call or a database query. Validate structured output against a schema and reject anything that does not fit. This prevents a manipulated model from becoming an injection route into the rest of your application.

Test and monitor

Test LLM features the way an attacker would, with direct and indirect prompt injection, attempts to extract the system prompt, attempts to read other users' data and attempts to make tools misbehave. Log prompts, retrieved documents, tool calls and filter decisions so you can investigate incidents and tune controls. Repeat testing after model upgrades and prompt changes, because behaviour shifts with each.

An AI and LLM penetration test covers all of this against your real application, including the documents and tools the model can reach. For how data escapes through AI tools more broadly, see our guide to AI data leakage, and for knowledge-base chatbots, our RAG security guide.

Frequently asked questions

Will filtering the model's output stop data leaks?

No. Filters miss leaks that are rephrased, encoded or partial, and they can't help if the model was handed data the user shouldn't see. Control what the model retrieves, and keep filtering as a last check.

What is "improper output handling"?

A risk on the OWASP Top 10 for LLM Applications: model output passed to a browser, shell, database or other system without validation, which lets injection attacks ride through the model.

Can guardrails stop prompt injection?

They reduce it but can't reliably stop it with current models. Limit what the model can reach and do, so a successful injection has little effect.

How do we test an LLM application?

Run a normal application and API test plus LLM-specific checks: prompt injection, pulling out the system prompt, one user reaching another's data through retrieval, and misuse of tools. Retest when the model or prompts change.

Find out what your LLM app will reveal

We test LLM applications for injection, data leaks through retrieval, system prompt extraction and unsafe tool use, with clear fixes for each finding.