Skip to content

Interview question · LLM Application Security

How must model output be handled before it reaches a browser, SQL engine, shell or other interpreter?

Product security's favourite AI question, because the answer is mostly classic AppSec. The scored part is matching each sink to its control and preferring structured data over generated code.

mediumEssentialNewPreparation tags: Microsoft, Google, AmazonUpdated Nov 2026

TL;DR: As untrusted input, because anyone who can influence the model's context can shape it. Apply the control each sink needs: context-aware encoding and safe markdown rendering for browsers, parameterised queries on a least-privilege role for databases, no shell at all (named operations with validated arguments instead), schema validation and backend authorization for tool calls, destination allowlists for URLs. Best of all, have the model produce validated data and let code build the query or command.

How to approach it

State the principle in one sentence, then go sink by sink with the vulnerability class and its control. Finish with the design move that removes most of the risk: asking the model for structured data rather than executable text.

A strong answer

FIG · MODEL OUTPUT · UNTRUSTED INPUT TO EVERY SINK
Each interpreter gets the control it needs

Influenced context

users, documents, web

Model output

attacker-shapeable

Sinks

browser, SQL, shell, tools

Per-sink control

Encode, safe markdown

  • No raw HTML, allowlisted links

Parameterised, least privilege

  • Read-only role where possible

No shell at all

  • Named operations, validated args

Schema + backend authz

  • URLs against an allowlist

Principle. Model output depends on the user's input and on any retrieved or tool content, so it has the same trust level as the least trusted text in the context. OWASP lists the failure as Improper Output Handling (LLM10 in the 2026 list, LLM05 in 2025).

Sink by sink.

SinkClassControl
Browser (HTML, markdown)XSS; exfiltration via images and linksEncode for context; sanitise rendered HTML with an allowlist; strict CSP; external images blocked or proxied
SQLSQL injectionModel emits parameters, code builds a parameterised query; read-only role; views scoped to the user
Shell, eval, interpretersCode executionNever pass output to them; offer named operations with typed arguments; sandbox if code execution is the product
Template enginesServer-side template injectionOutput is data in a template, never template source
URL fetchingSSRFAllowlist destinations; egress proxy; block private and metadata addresses
File pathsPath traversalCanonicalise and confine to a directory
Tool callsUnauthorised actionsSchema validation, authorization with the user's identity, policy limits

The structural move. Most of these risks disappear when the model never writes code. For an analytics assistant, have it produce {metric: "revenue", range: "last_quarter", group_by: "region"}, validated against an enum, and compile that into SQL yourself. For a DevOps assistant, expose restart_service(name) with an allowlist rather than a terminal.

Where to enforce. At the sink, in code that runs after the model, so that it applies however the output was produced.

What interviewers probe next

  • "Can't we ask the model to only output safe HTML?" That is an instruction to a component the attacker can influence. Encode at the sink.
  • "What if generated SQL is a core feature?" Validate the statement (parse, allow only SELECT on approved views), run with a read-only role scoped to the user, enforce timeouts and row limits, and log every query.
  • "Which sink is most often missed?" Markdown rendering, because teams think of it as display rather than as an interpreter that makes network requests.

What if?

What if · interview follow-ups

Hold your answer as the constraints change

A developer pipes model output straight into a SQL query, an HTML page and a shell command in different features of the same product.

  1. Start here

    Why is model output untrusted even when your own prompt produced it?

How it's scored

Weak: Suggests prompting the model to produce safe output or filtering for bad keywords.

Hire: Maps each sink to its classic vulnerability class and control.

Strong Hire: Adds markdown exfiltration and SSRF, proposes structured outputs instead of generated code, and limits blast radius at each sink with least privilege.

Common mistakes

  • Treating output from "our own model" as trusted.
  • Sanitising markdown syntax instead of the rendered HTML.
  • Giving generated SQL a read-write role.
  • Validating tool calls in the client or in the prompt.
You just read a free answer. Every topic opens its first 5 answers to anyone. Sign in and the count per topic goes to 10, and we keep track of how far you get in every topic.Google sign-in · free · no payment details
HOW DID IT GO?
0
READING SIGNED OUT

Signing in doubles your free answers, from 5 to 10 per topic, and the site starts remembering you: mastery per topic, bookmarks, and a next-focus recommendation. Free, no card.

Sign in free
UP NEXT ON YOUR JOURNEY
DISCUSSION · 0

No comments yet. Share a correction or a different way to answer it.