Topic 2 of 5 · 5 min read
Data minimization in prompts and context
Goal: Change a prompt builder or tool output so it passes only an allowlist of fields to the model.
Send the model only the fields the task needs, chosen by an allowlist in code, so a field you forgot about can never leak by default. Redaction cleans text after the fact. Minimization avoids putting the data there in the first place.
Check yourself · 1 of 3
Why is an allowlist of fields safer than a denylist for building a prompt?
Why it matters
The usual leak is not a user typing a secret. It is a developer writing JSON.stringify(user) into a prompt, or a tool that returns a whole database row. The model gets the home address, birth date and internal notes, and your logs, traces and provider records get them too. GDPR Article 5 states the principle: personal data must be adequate, relevant and limited to what is necessary. NIST SP 800-122 gives the same advice: collect and keep the least PII that works.
How to do it
- Write down what the task needs. "Draft a delivery-delay email" needs first name, order id, new date. It does not need the street address or phone.
- Build prompts from named fields, not whole objects. Use a small function that picks keys. An allowlist fails safe: new columns added to the table stay out until someone chooses them. A denylist fails open.
- Apply the same rule to tools. A
get_customertool should return a trimmed view, not the row. Models read everything a tool returns. - Apply it to retrieval. Strip personal fields from chunks before they enter the context, or filter by metadata so one user's documents never appear in another user's query.
- Prefer coarse values. Send
age_band: "30-39"orcityinstead of a birth date and street.
Before and after
- const prompt = `Write a delay notice for this customer:\n${JSON.stringify(customer)}`;
+ const view = {
+ firstName: customer.firstName,
+ orderId: order.id,
+ newDate: order.newDeliveryDate,
+ };
+ const prompt = `Write a delay notice using only these fields:\n${JSON.stringify(view)}`;
The first version also sends email, phone, address and any note field the table gains later. The second sends three values, and a reviewer can read the full list in one place.
What goes wrong
- Allowlist drift. Someone adds
address"just for this case" and it stays. Review the list in code review like an API contract. - Hidden fields in tool output. The tool was trimmed, but its error message prints the SQL row.
- Whole-conversation history. Resending all earlier turns carries every earlier secret into each new call. Trim or summarize history.
- Retrieval across users. A shared index without per-user filters can return someone else's chunk.
Examples
A trimmed tool result
The get_order tool returned the full row, including shipping_address and payment_last4. The fix is a toModelView(order) function returning { id, status, eta }. The full row stays available to the app code, not to the model.
Conversation history trimmed
A chat app resent every earlier message on each call, including a pasted passport number from turn two. The change keeps the last six turns and replaces older ones with a short summary that contains no identifiers.
Key points
- Allowlist the fields a prompt builder may send; new data stays out until someone adds it deliberately.
- Tool outputs and retrieved chunks go to the model too, so trim them with the same rule.
- Coarse values such as an age band or a city often serve the task as well as exact ones.
- Review the allowlist in code review like a public API, and keep it small.
- Filter retrieval by user or tenant so one person's data cannot appear in another's context.
Common mistakes
- Using a denylist of 'sensitive' columns, so every new column is sent by default.
- Serializing a whole user or order object into the prompt for convenience.
- Trimming the prompt but leaving the tool output and retrieval chunks untouched.
- Resending the full chat history forever.
Check yourself · 2 of 3
A get_customer tool returns the whole database row to the model for a task that only needs the first name. What is the best fix?
Check yourself · 3 of 3
A chat app resends the full history on every call, and a user pasted a passport number early on. Which change helps most?
Practice items, not counted towards your mastery.
Start here
- Microsoft Presidio: PII detection and anonymization (opens in a new tab)ToolFree
The open-source analyzer and anonymizer used in the redaction examples, with recognizers and operators.
- LLM02:2025 Sensitive Information Disclosure (OWASP GenAI) (opens in a new tab)StandardFree
Names how LLM apps leak personal data and lists sanitization and access-control mitigations.
- Your data (OpenAI API guide) (opens in a new tab)DocsFree
Shows what an API provider stores, for how long, and which controls (retention, storage flags) you can change.
More for this topic
- Art. 5 GDPR: Principles relating to processing of personal data (opens in a new tab)StandardFree
The legal text behind data minimisation and storage limitation, in plain reading order.
- NIST SP 800-122: Protecting the Confidentiality of PII (opens in a new tab)StandardFree
A federal guide to identifying PII and choosing safeguards such as minimization and retention limits.