NewProject Coding is here — build features and fix bugs in real codebases with an AI assistantSee what's new
Advanced
Threat Modeling LLM Applications
35 min readChapter 1Core
1Threat modeling LLM applicationsChapter 1

"How would you threat-model this LLM feature?" is the most common way an AI security round opens. Threat modeling an LLM feature means drawing where text and data flow, marking where trust changes, and listing what an attacker could make the feature do. The principle: a model reads instructions and data as one stream of text, so any text that reaches the prompt (a user message, a retrieved document, a tool result) can act as an instruction. The threat model finds each such place and ranks them, so defenses go where the risk is.

Do it before you launch a feature that reads user-supplied or third-party text, before you give the model tools or private data, and again whenever someone adds a new data source, tool, or output destination. Skip the full exercise for a model call on fixed, trusted input whose output only staff see. An ordinary code review of the integration is enough there. And a threat model is not a test. It tells you where to test, and red teaming then measures whether the defenses hold.

We'll work through one feature the whole way: a customer-support assistant for a project-management SaaS. It answers from staff-written help-center articles and the customer's own tickets using RAG (retrieval-augmented generation), looks up the signed-in user's account, files refund requests through tools, renders replies as markdown in a web chat widget, calls a hosted model provider, and logs prompts and replies to an analytics store. That one feature has every kind of crossing you will be asked about.

Interviewers expect different depth at each level. A mid-level answer draws the diagram, names the trust boundaries, maps the Open Worldwide Application Security Project (OWASP) classes, and knows that model output must be encoded. A senior answer goes further: it ranks threats by likelihood and impact, places a control at each boundary, says what each control still misses, and treats the model provider and the logs as boundaries too. Basic input and output filtering for a single assistant is covered in LLM Engineering 101 Guardrails and Safety. Here we build the map those filters sit on.

Your progressLogin to save progress
Spot an issue or have a suggestion?
Prompt Injection Defense  |

Discussion

Log in to join the discussion.