TL;DR
Prompt injection has no foolproof fix. Plant a canary token in your LLM's context and catch the leak the moment it happens.
Prompt injection is the one LLM vulnerability nobody has solved. OWASP's Top 10 for LLM Applications (2025, v2.0) keeps it at number one — LLM01 — and OWASP is blunt about why: it is unclear whether foolproof prevention exists. The attack surface is the model's own behavior. Crafted input, typed by a user or hidden inside content the model retrieves later, can push it to ignore its instructions, hand data to the wrong place, or act outside its guardrails.
The short version: you cannot reliably stop prompt injection at the input, so stop betting everything on stopping it. Plant tripwires instead — canary tokens, unique strings hidden in your system's context that no legitimate user would ever type — and scan every response for them. When one shows up in output, you have a confirmed leak, not a suspicion. This article covers the two canary families — classic honeytokens and prompt canaries — where to plant each, what they cost, and the limits that make them one layer of a defense, not the defense.
Why prevention alone fails
Injection comes in two forms, and only one of them looks like an attack. Direct injection is a user typing an override attempt into the chat box. Indirect injection is the dangerous one: the attacker never touches the model. They plant instructions in an email, a shared document, or a web page, and the agent retrieves that content as part of its normal work. The user sees a normal summary. The agent sees a command.
The clearest public case is EchoLeak. In June 2025, researchers at Aim Labs disclosed CVE-2025-32711, a zero-click prompt injection in Microsoft 365 Copilot: a crafted email carried hidden instructions, Copilot pulled the email in as context and followed them, and the stolen data left through crafted links and auto-fetched images. The attack chained bypasses of Microsoft's cross-prompt-injection (XPIA) classifier and its link redaction. Microsoft rated it CVSS 9.3, patched it in June 2025, and reported no confirmed in-the-wild exploitation. The lesson is not that Microsoft's defenses were weak — they were layered and serious. The lesson is that a classifier is a probability score, and a determined attacker only needs one phrasing it scores wrong.
That is the structural problem. The model reads natural language, so attackers have infinite phrasings. Filters and classifiers reduce the rate of successful attacks; they cannot reduce it to zero, and OWASP's LLM01 guidance says so plainly. So the honest posture is layered: prevent what you can, and make sure you find out — fast, and with certainty — when something gets through. That second half is what canaries are for.
The options
Option 1: Classic canary tokens
The older idea, from network security. A canary token is a decoy asset — a fake AWS key, a fake document, a fake URL, a kubeconfig — planted somewhere nobody legitimate should ever touch. The moment something accesses or uses it, you get an alert. Thinkst's Canarytokens is the reference implementation: a free service at canarytokens.org, open source, self-hostable with Docker, alerting by email or SMS when a token fires. Token types include web bugs, DNS names, AWS keys, kubeconfig files, Word and Excel documents, PDFs, WireGuard configs, and MCP server configs. The operating philosophy is "drop and forget": plant the trap, and wait for the notification that someone poked where they should not.
Applied to LLM apps, the planting sites are the places the model can reach. Put a fake AWS key in a tool description, so an agent that gets talked into dumping its tools hands you the alert instead of a real credential. Put a canary URL in a knowledge-base document, so a retrieval corpus being reconstructed through the model announces itself. Run a honeypot MCP server whose config is a canary, so a poisoned tool description that points agents at it fires the moment one connects.
Pick this when your model can reach tools, credentials, or documents, and you want a high-confidence, near-zero-false-positive signal. A fake key has exactly zero legitimate uses, so any use of it is an event worth paging about. The attribution is built in: each token is unique to where you planted it, so the token that fires tells you which asset leaked and through which path.
Option 2: Prompt canaries
The same trick, pointed at the model's context. Plant a high-entropy string — sixteen random bytes, far more entropy than any human would type — in the system prompt, a tool description, or a retrieved chunk, then scan every response for it on the way out. OWASP's LLM01 guidance lists canary tokens as a recommended tripwire for exactly this, and the mechanics are why practitioners trust them: real users never type random hex, and a model cannot hallucinate 128 random bits. If the string shows up in output, the prompt context leaked. Full stop.
import secrets
def make_canary() -> str:
# Prefixed so it is greppable in logs, plus 128 bits of entropy.
return "CANARY_" + secrets.token_hex(16)
def scan_output(output: str, canary: str) -> bool:
# One substring check, run on every response before delivery.
return canary in outputPlant different canaries in different regions, and a yes/no alarm becomes a map. A canary in the system prompt catches straight "show me your instructions" leaks. One in a tool description catches the reconnaissance step where an attacker lists tools before poisoning one. One per RAG chunk fires when an attacker reconstructs your retrieval corpus one query at a time. The token that comes back tells you which door got kicked in.
There is a stricter variant worth knowing: the sentinel canary. Instruct the model to append a token to the end of every single response, then strip it before the response reaches the user. If the token is missing, the model stopped following a basic instruction — its own signal that something upstream hijacked its behavior, even if no marked text ever leaked. The passive canary tells you when the system prompt got dumped. The sentinel tells you when the model stopped obeying at all. Different failure mode, same trick. The pattern is documented in OWASP's own LLM Top 10 tracker and in practitioner write-ups of multi-region canary traps.
Pick this when you need to know the moment a prompt or document leaves the boundary, and you can act on the alert. It costs one string and one substring check per response.
Option 3: Classifiers, guardrails, and least privilege
The prevention layer, and still necessary. Input classifiers score prompts for injection patterns before they reach the model. Output filters catch responses that look like leaked system-prompt text. Delimiters — strict XML boundaries around retrieved content — separate instructions from data the model should treat as untrusted. Least privilege on tools means a compromised agent cannot take consequential actions, and human approval gates sit in front of the ones that matter. These are the core mitigations in OWASP's LLM01 guidance: constrain model behavior, define and validate expected output formats, treat external content as untrusted, limit permissions, and monitor the full interaction — system prompt, user input, model response, and downstream actions in one view.
Pick this as the layer that reduces the rate of successful attacks. Do not pick it as the layer that tells you whether an attack succeeded — that is what it cannot do. Every classifier has published bypasses, and EchoLeak beat a production one. Prevention lowers the odds; canaries tell you the outcome.
The comparison
| Option | What it catches | False positives | Cost to run | Stops the attack? |
|---|---|---|---|---|
| Classic canary tokens | Credential or document use after the fact | Near zero — fake assets have no legitimate use | ~Free (Canarytokens.org) | No — detects |
| Prompt canaries | Prompt or document exfiltration, the moment it happens | Near zero — 128 random bits don't occur by chance | One substring check per response | No — detects (sentinel variant also detects hijacked behavior) |
| Classifiers / guardrails | Known injection patterns at the input | Moderate — needs tuning, and tuning never ends | Per-request inference | Sometimes |
| Delimiters + least privilege | Blast radius of a successful injection | Low | Design cost, paid once | Reduces harm, doesn't prevent |
Trade-offs
The trade-off to internalize first: a canary detects, it never prevents. A canary hit means data already left the boundary. The value is speed and certainty — a timestamped, attributable event instead of a silent breach discovered months later — not blocking. One nuance: when the scan sits in the output path, you can drop the response before it reaches the user, so the interactive leak is stopped at the door. But a model that already emitted a URL to a tool has already triggered the fetch; the scan cannot un-fetch it. Treat canaries as detection with a blocking bonus, not as a firewall.
The second trade-off is rotation. Once a canary is burned — the attacker learns its value — it stops being a tripwire and becomes a string the attacker can strip. Rotate after every hit, and per session or per deployment where the risk justifies it. Keep canary state where every replica reads it, so rotating actually rotates everywhere instead of only on the instance that caught the fire.
The third is obfuscation. An attacker who knows a canary exists can ask for it base64-encoded, or spelled out with dashes and spaces between characters. A naive substring check misses both. Normalize the output and the canary the same way before comparing: check the base64 form, and strip common separators from both sides. The check stays cheap; it just stops being naive.
The fourth is a rule, not a trade-off: never plant a real secret as a canary. Canary credentials must be fake. A real key sitting in the system prompt is a leak waiting for the first successful injection, and no tripwire fixes that. If your canary strategy needs a key the model can reach, generate a fake one — which is exactly what Canarytokens.org hands you. For how real secrets end up in AI tooling in the first place, and the gates that stop them, see our secrets hygiene field guide.
And the coverage gap teams forget: canaries only catch leaks that touch marked context. A pure tool-hijacking attack that never repeats marked text — an injected instruction that calls a delete tool, for example — will not trip a prompt canary. That is what the sentinel variant, least privilege, and approval gates are for. Canaries prove a leak happened; proving what an agent actually did needs a different mechanism — see our piece on verifying AI-agent actions.
Recommendation
For any LLM app with tools, retrieval, or secrets in context: layer all three options, in this order. Delimiters and least privilege first — they shrink the blast radius of every injection, including the ones no detector will ever see. Human approval gates on consequential actions next. Then canaries: one in the system prompt, one per tool description that matters, one per RAG corpus, plus a classic token for every credential or document class the model can reach. Wire every hit to something that pages, not a log file nobody tails. A canary that only writes to a log is a canary that already failed.
Start small: one canary in the system prompt and an output scan is an afternoon's work, and it converts your most common leak — prompt dumping — from silent to loud. Add the sentinel variant once the passive canary is alerting reliably.
When not to use canaries
Do not plant canaries in a chat-only toy with no tools, no retrieval, and no secrets in context. There is nothing to leak, and the tripwire buys nothing.
Do not plant them if nobody will act on the alert. A canary nobody watches is worse than no canary, because it manufactures confidence — the team believes leaks are being caught while the alerts pile up unread.
And do not use them as your only control. A team that plants canaries and skips input validation, least privilege, and sandboxing has a very accurate record of its own breaches. Canaries belong in a defense-in-depth posture: prevention reduces the rate of breaches, canaries guarantee the ones that slip through are detected fast. For the sandboxing half of that posture, read our guide to securing AI agents.
What to do next
This week, generate one canary, plant it in the system prompt, add the output scan, and wire the alert to a channel someone actually reads. Then test it: ask the model to repeat its instructions and watch the tripwire fire. When it does, add one canary per RAG corpus and one fake credential in your most sensitive tool description — and rotate the burned one. The whole setup is an afternoon; the alternative is finding out about a leak from someone else's blog post.
Why This Matters
Understanding the business and technical context helps you make informed decisions rather than blindly following patterns.
Trade-offs to Consider
Every architectural decision involves trade-offs. Consider your specific requirements, team expertise, and scale when evaluating options.
When NOT to Use This
Knowing when a solution doesn't apply is as valuable as knowing when it does. Consider alternatives for your specific situation.
Decision Framework
Use this framework to evaluate whether this approach is right for your use case based on your specific constraints and requirements.