Skip to main content

How to Test Your LLM App for Prompt Injection

· By Natalie Walls

The simplest prompt injection test is a canary: an instruction that asks the model to print a marker word it would never print on its own.

1. List every place the model reads text

Chat input is the obvious one. Also list uploaded files, retrieved documents, web pages the app browses, tool results and email.

2. Plant a canary in each one

Use the payloads on the home page. Each one asks for a different marker, like CANARY-1, so you can tell which test fired.

3. Check the output and the actions

A test fails if the marker appears in the reply, or if the app takes an action nobody asked for, like calling a tool or loading an image from an outside URL.

4. Repeat after every change

Models, prompts and tools change. Run the same canaries again whenever they do, and keep a log of what passed.