Sub topic 13
Privacy, compliance and access control
This chapter assumes you have read the chapters on data sources, tool use and the agent loop. You should know that an agent calls tools and that the model sees whatever those tools return.
Why agents raise the stakes
A dashboard shows data to a person who has already logged in. An agent is different. It reads data, sends it to a model provider, and writes it into a report that others may read. Customer records in a CRM (customer relationship management system) can include names, emails and purchase history. If a tool returns those fields, they become part of the model's input and may end up in the output.
Three questions cover most of the risk:
- What data can the agent reach?
- What data leaves your systems?
- Who can see the result?
Personal data and the law
Personal data is any information that identifies a person, directly or in combination with other data. Laws such as GDPR (EU) and CCPA (California) limit how you collect and use it. Common rules include a lawful basis for processing, honoring opt-outs, and deleting data on request.
For reporting, a simple rule helps: most marketing reports need aggregates, not individuals. A report on cost per acquisition does not need a customer's email address. If the agent never receives it, it cannot leak it.
This chapter gives engineering practice, not legal advice. Ask your privacy or legal team which rules apply to your data and regions.
Control points
Least privilege
Give each agent only the tools and data it needs. A reporting agent should have read-only access to campaign metrics. It should not hold a credential that can export the full customer list. Use separate API keys per agent and keep them in environment variables or a secrets manager, never in prompts or code.
Allowlisting tools
The model chooses which tool to call, so the tool layer must enforce permissions. Do not rely on the prompt saying "do not export customers".
Redaction before the model
Remove or mask identifiers before text reaches the model. The example below combines an allowlist with simple redaction.
import re
EMAIL = re.compile(r"[\w.+-]+@[\w-]+\.[\w.]+")
PHONE = re.compile(r"\+?\d[\d\s().-]{7,}\d")
def redact(text):
text = EMAIL.sub("[EMAIL]", text)
return PHONE.sub("[PHONE]", text)
ALLOWED_TOOLS = {
"report_agent": {"campaign_metrics", "search_reports"},
}
def call_tool(agent, name, tools, **args):
if name not in ALLOWED_TOOLS.get(agent, set()):
return {"error": "not permitted: " + name}
return tools[name](**args)
print(redact("Contact [email protected] or +1 555 123 4567 about the lead."))
print(call_tool("report_agent", "export_crm", {}))The first line prints Contact [EMAIL] or [PHONE] about the lead. The second prints an error, because export_crm is not on the agent's list.
Common errors
- Trusting the prompt as a control. Instructions can be ignored or overridden by text inside retrieved documents. Enforce rules in code.
- Regex-only redaction. Patterns miss names and free-text details. Treat redaction as one layer, and prefer not fetching sensitive fields at all.
- Logging everything. Logs of prompts and tool results can hold the same personal data you redacted elsewhere. Redact logs and set a retention period.
- Ignoring provider terms. Check whether your model provider stores inputs or trains on them, and where data is processed.
- Shared credentials. One key for every agent makes it impossible to tell who did what. Per-agent keys give you an audit trail.
Exercise
A reporting agent needs cost per acquisition by campaign. A teammate proposes giving it the full CRM export so it can "find patterns". Name two controls that reduce the risk, and say where each one is enforced.
Show answer
First, least privilege: give the agent only the aggregated conversion and spend data, enforced by the tool allowlist and a read-only credential in the tool layer. Second, redaction or field removal: strip names, emails and phone numbers before any text reaches the model, enforced in code between the data source and the model call. Prompt instructions alone are not enough.