Lesson 02 How LLMs Process Input
Theme:

How LLMs Process Input

Lesson 02 — AI Prompting Security

Understanding the architecture that makes prompt injection possible

Tokenization: Text to Numbers

LLMs do not see text. They see sequences of tokens — integer IDs from a fixed vocabulary.

"Hello world" → [15339, 1917]
"Ignore previous instructions" → [23182, 3766, 11470]

The Context Window

Everything the model sees is one flat sequence of tokens:

┌─────────────────────────────────────────────────┐
│ [SYS] System prompt tokens                      │
│ [USR] User message tokens                       │
│ [AST] Assistant response tokens (generated)     │
└─────────────────────────────────────────────────┘

Attention: Every Token Sees Every Token

The transformer's self-attention mechanism allows each token to "attend to" (look at, be influenced by) every other token in the sequence.

Security implication: Attention treats system and user tokens identically. An injection in user tokens can influence the output just as strongly as the system prompt.

No Privilege Separation

In traditional computing:

In LLMs:

Temperature and Sampling

After processing, the model outputs a probability distribution over the vocabulary for the next token.

For attackers: Higher temperature = more variability = sometimes the injection "slips through" even if it usually fails. Lower temperature = more predictable, but if the injection shifts the top probability, it works every time.

How Injections Shift Probabilities

Consider a model deciding what to output next. Without injection:

P("I cannot share") = 0.85
P("The price is")    = 0.10
P("Sure, here")      = 0.05

With a carefully crafted injection payload in the context:

P("I cannot share") = 0.30
P("The price is")    = 0.45  ← shifted to top
P("Sure, here")      = 0.25

The injection does not "override" anything — it shifts the probability landscape so that the compliant response becomes more likely than the refusal.

The "Instruction Hierarchy" Is Just Convention

Key insight: Instruction-following is a behavior learned during training, not a constraint enforced by the architecture. This is the fundamental reason prompt injection cannot be "patched."

Why Fine-Tuning Helps But Doesn't Solve It

Summary

Next lesson: Direct Prompt Injection — a comprehensive taxonomy of attack techniques.
1 / ?