PII Handling and Data-Leakage Prevention
CorePrevent PII exposure and data leakage · Difficulty 2/5
Explanation
A Claude application is still an ordinary system that happens to include a model, and it must uphold ordinary data-protection discipline around that model rather than treating the LLM as exempt from it.
PII Handling
Minimize what personal data is sent to the model at all, and where possible, redact or tokenize sensitive identifiers before they reach the model. Only send data that policy actually permits sending -- "the model can handle it securely" is not a substitute for not sending unnecessary PII in the first place.
Data-Leakage Prevention
Guard against the model or its tools exposing:
- Secrets (API keys, credentials)
- Other users' data
- Internal system details (system prompts, internal tool schemas, infrastructure specifics)
The key architectural control is scoping: tool access should be restricted so the agent cannot read data the current user shouldn't see in the first place -- this prevents leakage structurally rather than relying on the model to decline to repeat something it was never supposed to have access to. Secrets must never be placed in prompts or logs, since anything in a prompt or log is a leakage surface.
The Confused-Deputy Mechanism Behind Most Leakage
A huge share of real-world data-leakage incidents share one underlying mechanism, worth naming precisely: the confused-deputy problem. A confused-deputy vulnerability occurs when an agent that legitimately holds *broader* privilege than the end user acts on an instruction that came from a *lower*-privilege or untrusted source -- injected content in a fetched web page, a tool result, or a request from a user who shouldn't have access to a given resource in the first place. The agent is "confused" into spending its own higher privilege on behalf of a party who never actually had that privilege themselves.
Concretely: a support agent runs with a service account that can read any customer's billing record (broad privilege, needed so it can serve whichever customer asks). A request -- or an injected instruction hidden in content the agent reads -- asks it to pull *a different* customer's billing history. If the agent has no check tying the privilege it's about to exercise back to what the actual requester is entitled to, it happily uses its own broad service-account privilege on behalf of a party who has no right to that data. The agent didn't lack a credential; it had exactly the credential the attack needed, and nothing stopped it from applying that credential on the wrong party's behalf.
This is the precise mechanism that connects prompt injection (7.1) to over-broad tool access (7.2's least-privilege material): an agent with narrowly-scoped tools has far less to be "confused" into misusing than one with broad access, even when both face the identical injected instruction or the identical illegitimate request. Narrow scoping doesn't make the agent smarter about which instructions to trust -- it simply leaves less privilege sitting around for a successful deception to spend. The fix is the same one least privilege always prescribes: scope the agent's effective privilege to what the *specific caller* is entitled to, not to what the *service account* is capable of, so the agent can never do more on a user's behalf than that user could do directly.
The CIA + Privacy Framing
End to end, a Claude system must maintain authentication, authorization, confidentiality, privacy, and integrity -- the same five properties any secure system must maintain. The LLM is one component inside an otherwise ordinary secure system; it does not replace or override the need for standard access control, encryption, and integrity checks elsewhere in the pipeline.
Common exam traps
- Assuming that keeping PII out of the final visible answer is sufficient. Leakage can occur through logs, intermediate tool calls, or over-scoped data access, not just through the model's final response text.
- Treating the model as a security boundary. Scoping data access at the tool/API layer -- before the model ever sees the data -- is the reliable control; hoping the model declines to leak data it was needlessly given is not.
- Assuming a confused-deputy failure means the agent's credentials were stolen or misconfigured. The credentials are exactly right for the agent's normal job -- the failure is that the agent applied them on behalf of a party who was never entitled to that privilege in the first place.
Key Takeaways
- Minimize PII sent to the model; redact or tokenize sensitive identifiers before they reach it
- Scope tool and data access per user so the agent structurally cannot read data it shouldn't see
- Never put secrets in prompts or logs -- both are leakage surfaces
- CIA + privacy (authentication, authorization, confidentiality, privacy, integrity) must hold end to end; the LLM is one component, not a replacement for ordinary security practice
- A confused-deputy vulnerability is an agent with broad privilege acting on an instruction from a lower-privilege or untrusted source, spending its own privilege on behalf of a party who never had it
- Confused-deputy is the mechanism connecting prompt injection to over-broad tool access -- narrowly-scoped tools leave less privilege available to be misused even facing an identical attack
Glossary Terms
A security risk pattern in which an agent acting with broad service credentials on behalf of a low-privilege user can leak or change data the user should not be able to touch. The fix is to scope tool permissions to the calling user's entitlements rather than the service account's broader credentials, so the agent can never do more on the user's behalf than the user could do directly.
The EU General Data Protection Regulation, governing the protection of personal data for EU data subjects. Design implications include data minimization, establishing a lawful basis for processing, honoring data-subject rights, and respecting data-residency requirements.
The US Health Insurance Portability and Accountability Act, governing the protection of protected health information (PHI). Design implications include using HIPAA-eligible services and business associate agreements, and restricting or redacting PHI across the pipeline rather than assuming the model alone is compliant. Compliance is a property of the whole system -- data handling, access, retention, and contracts -- not of the model in isolation.
A security principle applied to agent tool design: give each agent and subagent only the minimum tools required to complete its specific task. Reduces blast radius if an agent is compromised or makes an error. Implemented via AgentDefinition tool lists and skill allowed-tools.
Related Concepts
Secrets, Identity, and Access Management
API keys/secrets belong in environment variables or a secrets manager -- never hard-coded, committed, or pasted into prompts/logs
Prompt Injection Mitigations: Isolation and Least Privilege
Core mitigations: isolate/delimit untrusted content, apply least privilege to tools, back both with guardrails/hooks, and validate input/output