Safety, Security & Responsible AI·Question 7 of 70Basic

What does "treat all model output as untrusted" mean, and why?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

It means any text the model produces should be handled with the same suspicion as raw user input, because the model's output is transitively attacker-controlled: the model reads inputs (user messages, retrieved docs, tool results) that an attacker may control, so its output can carry an attacker's payload. This is OWASP LLM10:2026 Improper Output Handling (LLM05 in 2025), which now explicitly includes insecure assistant-generated code, and it's where a lot of real CVEs live - the LLM part is just a laundering step for a classic injection.

Full worked answer

It means any text the model produces should be handled with the same suspicion as raw user input, because the model's output is transitively attacker-controlled: the model reads inputs (user messages, retrieved docs, tool results) that an attacker may control, so its output can carry an attacker's payload. This is OWASP LLM10:2026 Improper Output Handling (LLM05 in 2025), which now explicitly includes insecure assistant-generated code, and it's where a lot of real CVEs live - the LLM part is just a laundering step for a classic injection.

Concrete failures:

  • Rendering output as HTML/markdown → stored XSS (the model emits <img onerror=...> or a javascript: link because injected content told it to).
  • Executing generated SQL against your DB → SQL injection, now written by the model.
  • Running generated code without a sandbox → RCE.
  • Passing output into a shell, eval, or a tool call without validation → command injection, SSRF, path traversal.
  • Auto-rendering markdown images → data exfiltration via the image URL.

The defences are the same ones you'd apply to any untrusted string, plus LLM-specific ones: contextual output encoding before rendering, parameterised queries (never string-concatenate model output into SQL), sandboxed execution with no network, schema/type validation on tool arguments, URL allowlists for any fetch or link, and content-security-policy so a leaked script can't run. The principle scales to agents: the output of one model call becomes the input to a tool or another call, so the taint propagates through the whole trajectory unless you sanitise at each boundary.

The one-liner: an LLM is not a trusted component; it's a very sophisticated way of transforming untrusted input into untrusted output.

What a good answer covers

  • It means any text the model produces should be handled with the same suspicion as raw user input,…
  • This is OWASP LLM10:2026 Improper Output Handling (LLM05 in 2025), which now explicitly includes…
  • Rendering output as HTML/markdown → stored XSS (the model emits <img onerror=...> or a javascript
  • Executing generated SQL against your DB → SQL injection, now written by the model
  • Running generated code without a sandbox → RCE

Key terms: transitively attacker-controlled · LLM10:2026 Improper Output Handling · Rendering output as HTML/markdown · Executing generated SQL · Running generated code · Auto-rendering markdown images · contextual output encoding · parameterised queries · sandboxed execution · schema/type validation

Interviewer follow-ups to expect

  1. Your model returns a markdown link the frontend renders - what's the risk and the fix?

  2. How is executing model-generated SQL different from a normal injection bug, and how is it the same?

  3. Where in an agent loop does tainted output cause the most damage?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep