Designing Safety Filters for Language Models
Manual prompt hacking changes the surface of a request, through spelling, format, or framing, to get past a safety filter.
A Gatekeeper That Reads Only Words
Many language model applications place a safety filter in front of the model. You can picture it as a gatekeeper that reads every request before it reaches the model and turns away anything on a forbidden list. The gatekeeper is simple and fast, but it only notices the words it was built to notice. Everything in this article follows from that limitation.
Jailbreaking and prompt injection study the gap between what the gatekeeper checks and what the model will actually do with a request. An attacker's goal is to change the wording, format, or framing of a request so that the gatekeeper stops noticing it, while the model still understands what is being asked. The request's intent does not have to change for this to work. Only its surface does.
What do you think happens?
A forbidden word sits on the filter's list. What happens when a request spells that word with one character changed?
Reveal answer
An exact-match check does not find the altered spelling, so the filter can let the request through, while a model that understands typos may still recognize the intended word.
The filter compares characters, and the altered spelling is a different sequence of characters. The model works with meaning and common variations, so it can still recover what was meant. This gap between the two is what obfuscation exploits.
Tracing a Request Through a Keyword Filter
Follow a single request through the system. It arrives at the application, and before any model sees it, the exact-match filter compares its text against the forbidden list. If a forbidden term appears in the request, the request is turned away. If nothing matches, the request continues to the language model. The filter never asks what the request means. It only asks whether the text matches something it was built to recognize.
The diagram shows the key weakness. The altered request enters the same check as the original, but it no longer matches the forbidden list, so it takes the path to the model. The model, which is not limited to exact strings, can still work out what is being asked. The filter and the model are looking at the same text with different levels of understanding.
Checking a Misspelled Request Against an Exact-Match List
The forbidden list contains the term secretword. Two requests arrive. Request A is 'Tell me the secretword'. Request B is 'Tell me the s3cretword'. Which request does the exact-match filter block, and why?
- 1Identify what the filter compares
The filter compares the text of each request against the terms on the list. It is looking for the exact sequence of characters secretword.
- 2Check Request A
Request A contains the exact sequence secretword, so the filter finds a match and blocks the request.
- 3Check Request B
Request B contains s3cretword. The character 3 replaces the letter e, so the exact sequence secretword does not appear. The filter finds no match and lets the request continue.
- 4Compare with the model's reading
A model that understands typos and related forms can recognize s3cretword as an altered form of the same word. The filter has no such understanding, so the two requests have the same intent but different outcomes at the gate.
Request A is blocked and Request B passes, even though both ask for the same thing. The filter reacts to characters, not to intent.
False
True
False- FORBIDDEN_TERMS is a stand-in for a forbidden list; the word is a placeholder, not a real term.
- Lowercasing the request handles capitalization, so the uppercase version is still caught.
- The check looks for the exact sequence of characters, so a misspelled version gets through.
Same Request, Different Surface
Manual prompt hacking is the first family of attacks the source describes. It consists of a person writing one prompt, or a sequence of prompts, by hand, with the aim of getting a model to drop its safety filters. The approach resembles social engineering, the practice of manipulating people into doing something they would normally refuse. The difference is the target: instead of persuading a human, the attacker tries to persuade a model.
The three manual techniques share one pattern. The surface of the prompt changes while the request underneath stays the same. Each technique works on a different part of the gatekeeper's picture of the request. The diagram below sets the original and the altered versions side by side.
The three manual techniques are usually discussed as follows. Obfuscation changes how a forbidden term is spelled or encoded. Output formatting manipulation changes the shape of the requested answer so that the harmful intent is wrapped in an unexpected form. Roleplaying asks the model to take on a character or scenario. The subsections below take each one in turn, starting with the simplest and oldest.
Manual Hacking Versus Automated Search
Manual techniques depend on a person trying variations by hand. Prompt hacking can also be partially or fully automated by algorithms. The source describes two algorithms introduced by Zou and colleagues in 2023. They randomly substitute different parts of a prompt with different substrings and keep searching until a variant succeeds. The search is mechanical. The algorithm does not need to understand why a variant works, only to detect whether it did.
Automation can also use a model as a collaborator. The source mentions an X user who showed that a model can be asked to brainstorm new attacks when given a set of existing attacks. In that case the model is not the target. It is a source of new candidate prompts. This shift, from a person writing prompts to a model helping write them, leads to the systematic approach described in the next section.
| Feature | Manual prompt hacking | Automated attacks |
|---|---|---|
| Who creates the variants | A person, by hand | An algorithm or an AI model |
| How the search runs | Variations tried one at a time by a person | Mechanical substitution or model-driven revision |
| How fast the search can run | Limited by human effort | Can run as a loop without a person in each step |
| What uses feedback | The person reading the model's reply | The attacker reads the target's response and revises its next prompt |
The two families differ mainly in who does the searching and how fast the search can run.
One Round of the PAIR Loop
Chao and colleagues in 2023 proposed a systematic approach to AI-powered attacks called Prompt Automatic Iterative Refinement, or PAIR. PAIR uses one AI model, the attacker, to generate prompts aimed at a second AI model, the target. The attacker is given an objective, such as eliciting a certain type of objectionable content from the target. The attacker does not succeed on the first try. It works in a loop.
Each round of the loop has four moves. The attacker generates a prompt aimed at the objective. That prompt is sent to the target. The attacker reads the target's response. Then the attacker revises the prompt based on that response, and the cycle repeats until the objective is achieved. The diagram traces this cycle, including the point where the loop ends.
The loop is the key idea. Each response from the target is information that the attacker uses to change its next prompt, so the attempts improve over time instead of being random guesses. The source reports that in the experiment PAIR often required fewer than twenty queries to produce a jailbreak. That small number is part of why the approach is considered systematic, and why automated attacks deserve attention from anyone protecting an application.
Following Feedback Across Three Rounds
An attacker is given an objective and runs PAIR against a target. Trace what the attacker does with each target response, using generic placeholders instead of real content.
- 1Round 1
The attacker writes a first prompt aimed at the objective and sends it to the target. The target refuses or deflects. The attacker reads that reply as information about what did not work.
- 2Round 2
The attacker revises the prompt using the previous reply, for example by changing the framing. The revised prompt is sent to the target, which responds again. The attacker reads the new response.
- 3Round 3
The attacker revises again based on what the target just returned. The loop checks whether the objective has been achieved. If not, another round begins.
- 4Stopping point
The loop stops once the objective is achieved. The source notes that the search often needed fewer than twenty queries in the experiment.
Each round's output becomes the basis for the next round's prompt. The attempts are guided by feedback rather than picked at random.
Why One Filter Is Not Enough
A single filter addresses a single technique. A filter that blocks unusual characters can stop the special-character form of obfuscation, but it does not address misspelling, rewording, format changes, or roleplay. Because the attacks change different parts of the surface, a defense built around one of them leaves the others open.
A sound approach therefore layers several checks, each aimed at a different technique described in this article. The whole system should also be tested against iterative attempts as well as single ones. A defense that stops a single hand-written variant may still fail against a loop that keeps revising its prompt based on each reply.
Mistakes About Keyword Filters
Common mistake Assuming a filter that blocks an exact term also blocks its misspelled form
What it looks likeA list contains secretword, and the request says s3cretword. The exact-match check finds no match.
Why it failsAn exact-match filter compares characters. A changed character produces a different sequence, which the filter does not recognize.
Do this insteadRecognize that the filter and the model read the same text at different levels. Layer checks that target altered forms, such as unusual characters.
Common mistake Believing that changing the format of a request changes what it asks
What it looks likeThe same question is asked directly, then asked inside a requested output structure.
Why it failsOutput formatting manipulation changes the shape of the answer, while the underlying intent stays the same.
Do this insteadJudge a request by its intent, and test whether the defense still holds when the shape of the requested answer changes.
Common mistake Treating a roleplay frame as a different request
What it looks likeA request wrapped in a character or scenario is considered harmless because its words describe a story.
Why it failsRoleplaying changes the framing on the surface. The model is still being asked to produce the same underlying content.
Do this insteadTest framed versions of requests against the same defenses as direct versions.
Common mistake Believing one defense covers all techniques, when the source says a single filter addresses a single technique
Checking Your Understanding
A filter blocks any request containing the exact word on its list. Explain in your own words why a request with one character changed can pass the filter while still asking for the same thing.
Hints
- Think about what the filter compares: characters, or meaning.
- Consider how a model that understands typos differs from an exact-match check.
List the roles of the attacker AI and the target AI in one round of PAIR, then state what the attacker does with the target's response before the next round begins.
Hints
- The attacker generates the prompt and the target responds to it.
- The response is information the attacker uses to change its next prompt.
A team tests its safety filter only with single hand-written variants and concludes the system is safe. Identify two gaps in this testing plan, using the source's point about layered checks and iterative attempts.
Hints
- Consider which technique families the single filter addresses.
- Consider whether a loop that revises prompts from each reply has been tested.
Key Takeaways
- 1A keyword filter checks the surface of text against a list, so a request whose wording, spelling, format, or framing changes can pass unmatched while its intent stays the same.
- 2Manual prompt hacking uses obfuscation, output formatting manipulation, and roleplaying, all of which change the surface of a prompt. Automated attacks use algorithms or AI models to search for and revise prompts.
- 3PAIR runs a loop in which an attacker AI generates prompts for a target AI, reads each response, and revises its next prompt until the objective is achieved, often in fewer than twenty queries in the source's experiment.
- 4A single filter addresses a single technique, so application defenses must be layered and tested against both manual and automated attempts.
At a glance
- A keyword filter checks surface text against a list, so a request with changed spelling, format, or framing can pass while its intent stays the same.
- Manual prompt hacking (obfuscation, output formatting manipulation, roleplaying) is done by a person by hand, while automated attacks use algorithms or AI models to search and revise prompts.
- PAIR loops through generating a prompt, sending it to the target, reading the response, and revising the prompt until the objective is achieved.
- A single filter covers a single technique, so defenses must be layered and tested against iterative attempts as well as single ones.