Sub topic 2
Where Personal Data Travels in an LLM App
This chapter assumes you know basic Python, have called a chat model API at least once, and know what a prompt, a response, and a log are. Later chapters cover detection and redaction. Before you write a detector, you need to know where it should run, and this chapter builds that map.
A typical LLM app copies the same text into many places. A user types one sentence, and that sentence can end up in a provider's servers, your logs, a vector database, a trace dashboard, and a test dataset. A detector placed at only one of those points leaves the others exposed.
The request path
Start with the simplest chat request and add pieces one at a time.
- The user types a message in a client (browser, mobile app, or chat integration).
- Your backend receives it and builds a prompt. The prompt usually holds a system instruction, earlier turns of the conversation, and the new message.
- The backend may add retrieved documents (RAG, retrieval-augmented generation) or results from tools such as a CRM lookup or a SQL query.
- The backend sends the assembled prompt to a model provider.
- The model returns a response. It may include tool calls that your code executes, which produce more data and trigger another model call.
- Your backend returns the response to the user and records parts of the exchange.
Personal data can be present at every numbered step. The prompt you send in step 4 often holds more personal data than the user typed in step 1, because steps 2 and 3 add to it.
Entry points
Entry points are where personal data first reaches your system or joins a prompt.
- User messages. Users paste emails, support tickets, résumés, and medical details into a chat box, whether or not you expected it. Do not assume a "recipe assistant" only receives recipes.
- Uploaded files. PDFs, spreadsheets, and screenshots carry names, addresses, and account numbers. Text extracted from them (including OCR output, which is text recognized from images) can contain errors that break exact patterns. A card number read from a photo may have a misread digit.
- Retrieved documents. A RAG system pulls chunks from an index. If the index was built from HR files, support tickets, or chat transcripts, every query can pull personal data about people who never talked to your app.
- Tool results. A tool that looks up an order returns a name, a shipping address, and a phone number. The model needs only the order status, but the whole record often goes into the prompt.
- System prompts and configuration. Developers sometimes paste real customer examples into few-shot prompts, or a user's profile into the system prompt. That data is then sent with every request.
- Conversation history. Most chat APIs are stateless. Your app re-sends earlier turns with each new request. A name given in turn 2 is sent again in turn 20, to the provider and into your logs each time.
Storage points
Storage points are places where personal data stays after the request ends. These are often the larger risk, because they accumulate data for months.
- Application logs. Request logging, debug output, and error handlers often print the full prompt. An exception that includes the request body writes personal data to a stack trace.
- Traces and observability tools. LLM tracing tools capture every prompt, response, and tool call so you can debug them. They are often hosted by a third party and keep data for a long time.
- Conversation stores. Databases that hold chat history for "resume your conversation" features.
- Vector stores. Documents are split into chunks, converted to embeddings (lists of numbers that represent meaning), and stored with the original chunk text. The text is plainly readable. The embeddings are not safe either: research has shown that embeddings can be partly inverted to recover the source text, so treat them as personal data when the source was.
- Caches. Response caches and prompt caches keep exact copies of text keyed by the prompt. A semantic cache can return one user's cached answer to another user whose question is similar.
- Evaluation and fine-tuning datasets. Teams copy real production conversations into test sets or training data. Once there, the data is hard to delete, and a fine-tuned model may reproduce it.
- Provider-side retention. Model providers may keep prompts for a period, for abuse monitoring or other purposes, depending on contract and settings. Check your provider's current terms. You do not control this storage, so reducing what you send is your main lever.
- Backups and analytics exports. Database snapshots and product analytics copy the same data again, and a deletion request must reach them too.
Leak points
A leak is personal data reaching someone who should not see it. Some leaks go through the pipeline's normal channels.
- Model output. The model repeats data from its prompt. If retrieval pulled another customer's record, the response can show it to the wrong user. This is an access-control failure, and redaction alone does not fix it.
- Prompt injection. Text in a retrieved web page or document can instruct the model to reveal context. A known pattern asks the model to place private data inside a link or image URL, such as a Markdown image whose address points to an attacker's server. When the client renders it, the data is sent out.
- Third-party tools and plugins. When the model calls a search API, an email sender, or a webhook, the arguments leave your system. They are chosen by the model and may contain personal data it picked up from context.
- Error messages and client-side telemetry. A frontend crash report that includes the last chat message sends personal data to an error-tracking service.
- Shared infrastructure. Multi-tenant caches, shared vector indexes without per-user filters, and shared evaluation sets mix data across users.
Summary table
| Flow point | Direction | Typical personal data | Frequent mistake |
|---|---|---|---|
| User message | Inbound | Names, emails, health details | Assuming users stay on topic |
| Conversation history | Re-sent each turn | Everything said so far | Redacting only the newest message |
| Retrieved chunks | Inbound | Third-party records | Indexing raw HR or support data |
| Tool results | Inbound | Full database rows | Returning all fields when two are needed |
| Provider call | Outbound | The entire prompt | Treating the provider as an internal system |
| Model response | Outbound | Echoed or inferred data | Skipping output checks |
| Logs and traces | Stored | Prompts and responses | Logging full request bodies |
| Vector store | Stored | Chunk text and embeddings | Considering embeddings anonymous |
| Eval datasets | Stored | Copied conversations | Exporting production data unreviewed |
Writing the inventory down
A data-flow inventory is a short list of every point above that exists in your app. For each point, you record whether personal data can be present, whether it is already protected, and who can read it. Keeping it in code lets you check it in tests and review it in pull requests.
from dataclasses import dataclass
@dataclass
class FlowPoint:
name: str
holds_personal_data: bool
protected: bool # redacted or otherwise controlled
third_party: bool # data leaves your own systems
FLOW_POINTS = [
FlowPoint("user_message", True, False, False),
FlowPoint("conversation_history", True, False, False),
FlowPoint("retrieved_chunks", True, False, False),
FlowPoint("tool_results", True, False, False),
FlowPoint("provider_request", True, False, True),
FlowPoint("app_logs", True, False, False),
FlowPoint("trace_service", True, False, True),
FlowPoint("vector_store", True, False, False),
]
def unprotected_external(points):
return [p.name for p in points
if p.holds_personal_data and not p.protected and p.third_party]
def unprotected_internal(points):
return [p.name for p in points
if p.holds_personal_data and not p.protected and not p.third_party]
print("Fix first (leaves your systems):", unprotected_external(FLOW_POINTS))
print("Fix next (stays inside):", unprotected_internal(FLOW_POINTS))Running it prints the two lists. Points that send data to a third party, such as the provider request and the trace service, come first. Once data leaves your systems you cannot easily pull it back. As you add redaction in later chapters, flip protected to True for each point you cover.
Edge cases that surprise people
- Re-sent history multiplies exposure. One personal detail in turn 2 appears in every later request. If you redact only new messages but send stored raw history, the raw text still goes out. Store the redacted history or redact the whole prompt as you assemble it.
- Retries and streaming duplicate data. A retry sends the prompt again, and some gateways log each attempt. Streaming responses are often logged in pieces, so a value split across chunks can escape a detector that reads one chunk at a time.
- The model can produce personal data you never sent. It may guess a name, or reproduce a memorized public figure's details. Output handling needs its own check.
- Data about the user's contacts counts too. A message that says "my sister Ana lives at ..." contains personal data about Ana, who never used your app.
- Metadata is personal data. User IDs, IP addresses, device identifiers, and session tokens travel next to the text in headers, logs, and traces. A trace tool that stores a user ID next to a prompt links the content to a person.
- Derived data keeps the link. A summary of a conversation, a stored "user profile" produced by the model, or a title generated for a chat still describes the person.
- Where a log line is written matters less than who can read it. Logs sent to a shared dashboard may be visible to many engineers and contractors.
What comes next
With the map in hand, the following chapters build the tools in order. You will write detectors for structured identifiers first, add name detection, and then decide what to replace each match with. The final chapters return to this map and place the detectors at the right points: before the provider call, on retrieved documents, on tool results, and in logs.
Exercise
A support chatbot keeps the last 10 turns of conversation in a database and re-sends all of them to the model provider on every request. The team adds a redaction step that runs only on the newest user message before it is appended to history. Name two ways personal data can still reach the provider or storage, and say which flow points from this chapter are involved.
Show answer
First, the stored history is unredacted if redaction runs after the message is appended, or if older turns saved before the change are still raw. Those raw turns are re-sent to the provider on every request, so the conversation history and provider request flow points still carry personal data. Second, tool results or retrieved documents added to the prompt (for example a customer record from a CRM lookup) are not covered by a step that touches only the user message, and neither are logs or traces that capture the assembled prompt. The fix is to apply protection where the full prompt is assembled and to redact data before it is written to the history store, logs, and traces.