Slide 8 of 27
Part 1 · What Is It?Slide 8
Slide 8 · The Core Rule
One principle. Every LLM application needs it.
Part 1 closes here. Part 2 shows the four ways this goes wrong.
The Rule

Treat LLM output exactly as you treat user input: untrusted until proven safe for its context.

If you HTML-encode user-submitted text before rendering it, HTML-encode LLM output too. If you use parameterized queries for user-supplied database values, do the same for LLM-generated ones. If you don’t let users run arbitrary shell commands, don’t let the LLM do it either.

Why Context Matters

There’s no single sanitization that covers every case. The right fix depends on where the output goes:

HTML context: encode <, >, &, "
SQL context: parameterized queries, never string concatenation
Shell context: avoid passing LLM text to exec(); use sandboxes
URL context: validate scheme; block javascript: and internal IPs
File path context: allowlist directories; reject traversal patterns

Coming Up

Part 2 walks through four real-world attack patterns — each anchored to a confirmed CVE or incident. You’ll see exactly what breaks and what the attacker achieves.

← BackNext → The four attack patterns