Chapter 3 · Practice 3 of 5
Escape and validate model output before it reaches a browser, shell or database
Why it matters
Improper output handling, LLM10 in the 2026 list, is ordinary injection with a model in the middle. Model text is attacker-influenced input to whatever consumes it next.
| Where the output goes | What can go wrong | What to do |
|---|---|---|
| Browser, as HTML | XSS | Render as text or through a sanitiser |
| SQL | Injected queries | Parameterized queries |
Shell or eval | Commands run | Never pass model output there |
| Markdown images and links | Data leaks to an attacker's URL | Restrict allowed domains |
Treat every string the model returns the way you would treat a form field from an unknown user.
Avoid
- Rendering raw model output with innerHTML
- Building SQL or shell commands from model text