Skip to main content
When an agent handles data that may contain PII, there are two distinct egress points to protect:
  1. The prompt itself leaving the agent process and going to the LLM — OpenAI sees whatever you send it. Use PIIHandler.anonymize to strip PII before the call and PIIHandler.deanonymize to reconstruct the original values on the way back.
  2. Outbound HTTP from the sandbox when the agent’s tool code calls external APIs — enforced by SecurityPolicy.pii at the sandbox’s edge proxy; the LLM-generated code never gets a chance to leak PII through a curl or requests.post.
Both paths use declaw’s guardrails service under the hood; this cookbook shows them working together.

What you’ll learn

  • Anonymizing a user goal with PIIHandler before it goes to the LLM
  • Setting PIIConfig(action="redact", rehydrate_response=True) so the sandbox-side guardrails redact in transit and rehydrate on the return path
  • Rehydrating the model’s final output back to the original PII

Prerequisites

Code

What happens under the hood

Why both layers?

Layer 1 alone isn’t enough if the agent’s code is allowed to call external APIs from inside the sandbox — the model might reconstruct PII or emit new PII in its generated code. Layer 2 catches that at the network edge regardless of what the model produced. Layer 2 alone isn’t enough if you don’t want OpenAI’s servers to see customer PII in the prompt. Running them together gives full coverage.