Skip to content
mentoor

Topic 2 of 5 · 5 min read

Trust boundaries in LLM app data flows

Goal: Draw the trust boundaries of an LLM app and mark every point where untrusted text reaches the model or a tool.

Draw the data flow of your app, mark every place where text from outside enters, and treat the model itself as an untrusted component. A trust boundary is a line where data moves between parts that deserve different levels of trust.

Check yourself · 1 of 3

In an LLM app, what should be marked as untrusted in the data-flow diagram?

Choose one answer

Why it matters

In a classic web app, input goes through validation and a parser, and code does the rest. In an LLM app, the model reads instructions and data in the same stream and cannot reliably tell them apart. So any text it reads can act as an instruction. If a web page, a PDF or a support ticket reaches the model, its author has a way to influence what your tools do.

How to do it

  1. Draw the boxes. User, app server, model API, retrieval store, each tool, each external site, memory, logs.
  2. Draw the arrows with the content on each. "User message", "retrieved chunk", "tool result", "model output".
  3. Mark untrusted sources. User input, web pages, emails, uploaded files, other users' documents, output of other agents. Mark which of them an outsider can write.
  4. Draw a boundary around the model. Its output is not trusted. Anything it produces, such as a SQL string, a URL, a shell command or an email body, passes the checks you would apply to user input.
  5. Mark every tool call that crosses a boundary. For each, write who authorizes it, what it can touch and whether a human confirms it.

Before and after

Weak: "User -> LLM -> database." Fixed:

user msg (untrusted) --> app --> model <-- retrieved page (untrusted, outsider-writable)
model output (untrusted) --> policy check --> tool: read_orders (user's own rows only)
model output (untrusted) --> human confirm --> tool: send_email (external)

The fixed version shows where checks go and which flows need confirmation.

What goes wrong

  • Trusting the model's output. A generated query or URL runs without checks because "the model wrote it".
  • Missing indirect inputs. The drawing shows the chat box but not the web fetch tool or the shared knowledge base.
  • Checking in the prompt. "Never reveal X" is a request, not a boundary. Put limits in code, permissions and network rules.
  • Forgetting the return path. A tool that renders markdown images can leak data by URL when the model's output is displayed.

Examples

The shared knowledge base

A help bot retrieves from a wiki that all employees can edit. One page contains hidden text telling the bot to include a link to an outside site. The wiki is an outsider-writable input in the data flow, so retrieved chunks are marked untrusted.

Output as a boundary

A model writes a SQL query that the app runs. The drawing has a line between 'model output' and 'database'. Across it sit a read-only role, a table allow-list and a row limit, not a sentence in the prompt.

Key points

  • A trust boundary is a line where data moves between parts that deserve different levels of trust.
  • Treat the model as an untrusted component: whatever it reads can influence what it outputs.
  • Mark every source an outsider can write, including web pages, emails, files and shared documents.
  • Apply checks to model output the way you would to user input, in code and permissions rather than in the prompt.
  • Every tool call that crosses a boundary needs a named authorizer, a scope and a decision about human confirmation.

Common mistakes

  • Drawing only the chat box and skipping retrieval, web fetch and memory.
  • Assuming the system prompt separates instructions from data.
  • Passing model output straight into a shell, query or URL fetch.
  • Marking boundaries but not saying which tool calls need human confirmation.

Check yourself · 2 of 3

A model's output is run as a shell command. Where does the missing control belong?

Choose one answer

Check yourself · 3 of 3

Why mark each tool call on the diagram?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic