Concepts / Prompt Injection Fundamentals

Prompt Injection Fundamentals

Manual prompt hacking changes the surface of a request, through spelling, format, or framing, to get past a safety filter.

  • Programming

A Gatekeeper That Reads Only Words

Imagine a gatekeeper who reads every request before it reaches a language model and turns away anything on a forbidden list. The gatekeeper is simple and fast, but it only sees the words it was built to notice. Prompt injection and jailbreaking study the gap between what the gatekeeper checks and what the model will actually do with the request.

An attacker's goal, in this picture, 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 underneath has not changed. Only its surface has. Understanding this one idea explains almost everything else in this article: why simple filters are fragile, why manual tricks work at all, and why automated search can be so effective.

Tracing One Request Through a Keyword Gate

Follow a single request from the user to the model. In the simplest design, a keyword filter sits between the user's input and the language model. Every prompt passes through the filter first. If the prompt contains a forbidden term in the exact form the filter expects, the prompt is blocked. If it does not, the prompt reaches the model, which then reads it with full language understanding.

User promptoriginal wordingKeyword filterexact-match listBlockedexact match foundReworded promptsame intent, new surfaceLanguage modelunderstands typos andrelated formsResponseevery promptno exact matchforbidden term matchedno matchanswers
Where does the keyword filter sit between the user input and the model, and at which point does a reworded or obfuscated prompt slip past it?

The diagram shows the weakness. The filter decides using the characters it sees, while the model decides using meaning. Anything that changes the characters but keeps the meaning sits in the gap between those two checks. The filter is not wrong about what it saw; it simply saw the wrong thing to block.

What do you think happens?

A filter blocks the exact word password. A user sends the misspelled word p4ssword with the same request. What happens at the filter?

  • It is blocked, because the meaning is the same

  • It passes the filter, because it does not exactly match the forbidden word

  • The filter rewrites it to the correct spelling first

Reveal answer
Answer:

It passes the filter, because it does not exactly match the forbidden word.

An exact-match filter compares characters. The misspelled form is a different string, so the filter finds no match. The model, however, understands typos and related forms, so the request can still reach its meaning. This is the gap that obfuscation exploits.

Worked example

Tracing a misspelled request through an exact-match filter

A keyword filter forbids the exact word password. Trace two prompts that ask for the same underlying thing: one uses the forbidden word and one uses a misspelled variant.

  1. 1
    Step 1: Identify the forbidden term

    The filter's list contains the exact string password. Its check is a match against that string.

  2. 2
    Step 2: Check the original prompt

    The prompt contains password exactly as written. The filter finds a match and blocks the prompt before it reaches the model.

  3. 3
    Step 3: Check the misspelled prompt

    The prompt contains p4ssword. No exact string in the list matches it, so the filter lets it through.

  4. 4
    Step 4: Consider what the model sees

    The model receives the misspelled prompt and, as a language model, can recognize that it refers to the same concept. The surface changed; the intent did not.

Result

The exact-match filter blocked the first prompt and passed the second. Nothing about the underlying request changed, which is why a filter that checks surface form alone can be bypassed.

Same Intent, Different Surface

The three manual techniques covered next share one pattern: the surface of the prompt changes while the request underneath stays the same. Before looking at each technique, it helps to see this pattern directly. The diagram below sets an exact wording next to a changed wording. Notice which part is constant and which part the filter is actually reading.

Request intentsame goalExact wordingmatches the forbidden listRequest intentsame goalMisspelled wordingno exact matchexpressed asexpressed as
How does the same underlying request look before and after surface changes, and which part stays constant while the text the filter sees changes?

In the before state, the wording and the forbidden list agree, so the filter acts. In the after state, the intent node is unchanged, but the wording node has changed to something the filter does not recognize. The attack lives entirely in the changed wording, while the goal stays fixed. This is why the three techniques are best understood as different ways of changing the surface of a request.

Three Manual Prompt Hacking Techniques

Manual prompt hacking is 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 technique is usually discussed in three named forms, and each one works on a different part of the gatekeeper's picture of the request.

  • Obfuscation: changes how a forbidden term is spelled or encoded
  • Output formatting manipulation: changes the shape of the requested answer so the intent is wrapped in an unexpected form
  • Roleplaying: asks the model to take on a character or scenario

Manual Hacking Versus Automated Attacks

Manual techniques depend on a person trying variations by hand. Prompt hacking can also be partially or fully automated by algorithms. The two families differ mainly in who does the searching and how fast the search can run. The table below puts them side by side using the features the source emphasizes.

FeatureManual prompt hackingAutomated attacks
Who generates attemptsA person writing prompts by handAn algorithm or an AI model
How variations are producedA person tries changes one at a timeAlgorithms substitute parts of a prompt, or a model proposes new candidates
How many iterationsLimited by how fast a person can workCan run mechanically until a variant succeeds
How feedback is usedThe person judges the response and adjustsThe algorithm detects success, or the attacker model revises its prompt from the response
Example from the sourceObfuscation, output formatting manipulation, roleplayingRandomized substitution search, and PAIR

Manual and automated prompt attacks, compared on the features the source emphasizes

The source describes two algorithms introduced by Zou and colleagues in 2023 that 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, is the step that leads to the systematic approach described next.

Following 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. Instead it runs a loop, and the diagram below traces that loop round by round.

Objectivegiven to the attackerAttacker writespromptattacker AITarget respondstarget AIAttacker readsresponseresponse is feedbackObjective achieved?Jailbreak foundRevise promptbased on the responsestarts loopsends promptreturns responseevaluateyesnonext round
In what order do the attacker AI and target AI pass information, and how does a refused attempt feed into the next round?

Read the diagram as a cycle. The attacker writes a prompt and sends it to the target. The target responds. The attacker reads that response and checks it against the objective. If the objective has not been achieved, the attacker revises its prompt based on what came back and sends the next attempt. The loop repeats until the objective is achieved. A refused attempt is not simply discarded; the refusal is information that shapes the next round.

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.

Roles of the Attacker and Target

Two models do different jobs in PAIR, and the loop connects them. The attacker and the target have distinct inputs and outputs, and the attacker's ability to improve depends on the target's responses.

  • The attacker AI receives the objective, and on later rounds also the target's previous response
  • The attacker AI produces a candidate prompt aimed at the target
  • The target AI receives that prompt and produces a response
  • The target AI hands its response back to the attacker, which is the feedback that drives the next revision

The target is the model being tested; it is the thing the attacker is trying to persuade. The attacker is a second model whose only job, in this framework, is to produce and refine prompts. Because the attacker sees how the target responded, the two models form a feedback relationship rather than a one-way request.

Why One Filter Is Not Enough

The source offers one concrete defense: a simple filter that blocks requests containing unusual characters can stop the special-character form of obfuscation. The defense is narrow. It addresses one technique, and it does not address misspelling, rewording, format changes, or roleplay. A single filter addresses a single technique.

A sound approach therefore layers several checks, each aimed at a different technique described in this article, and tests the whole system against iterative attempts as well as single ones. Testing only with hand-written prompts misses the automated search that PAIR and similar methods run.

Checking Your Understanding

MEDIUM

A team's only defense against prompt injection is a filter that blocks one exact list of forbidden words. Explain, in your own words, why a reworded request with the same intent can get past it, and name one technique from this article that exploits this weakness. Then describe how the PAIR loop would respond to a refused attempt.

Hints
  • Think about what the filter compares: characters or meaning?
  • Consider which of the three manual techniques changes spelling or encoding
  • Trace what the attacker AI receives from the target AI after a refusal

Common Mistakes About Prompt Injection

  • Common mistake

    Believing that a filter which blocks a word also blocks its meaning

    What it looks like

    A filter forbids one exact spelling, and a misspelled version of the same request is not on the list.

    Why it fails

    An exact-match filter compares characters, while the model reads meaning. The two can disagree.

    Do this instead

    Treat a keyword list as one narrow check that covers only the surface form it was built to notice.

  • Common mistake

    Thinking prompt injection is only a human typing tricks by hand

    What it looks like

    An algorithm randomly substitutes parts of a prompt until one variant succeeds.

    Why it fails

    Automated attacks search mechanically and do not need to understand why a variant works.

    Do this instead

    Test applications against automated iterative attempts as well as single hand-written prompts.

  • Common mistake

    Assuming the target's refusals end the attack

    What it looks like

    The target refuses, and the attacker reads that refusal and revises its prompt.

    Why it fails

    In the PAIR loop, each response is feedback that drives the next round.

    Do this instead

    Recognize that a refused attempt is information that the loop uses to improve.

  • Common mistake

    Assuming one defense covers all techniques

    What it looks like

    A filter for unusual characters is added, and the team considers the system protected.

    Why it fails

    The source's example filter addresses only special-character obfuscation, not misspelling, rewording, format changes, or roleplay.

    Do this instead

    Layer several checks, each targeting a different technique, and test the whole system.

Key Takeaways

  • Manual prompt hacking changes the surface of a request, through spelling, format, or framing, while the underlying intent stays the same, so a filter that matches surface form can be bypassed.
  • The three manual techniques are obfuscation, output formatting manipulation, and roleplaying; each alters a different part of the prompt the gatekeeper reads.
  • Automated attacks use algorithms or AI models to search and revise prompts; PAIR runs a loop in which an attacker AI sends prompts to a target AI and revises based on each response.
  • A keyword filter exploits only exact matches, so it misses reworded or misspelled prompts; a single filter addresses a single technique, so defenses must be layered and tested against both manual and automated attempts.

Related concepts

More concepts starting with P