How to Redact Customer Data from Tool Outputs Before They Reach the OpenAI Responses API
Redact in your own execution path, after the tool returns and before the result is submitted as a function call output item. Inventory each tool's output schema, combine field-level allowlists with entity detection for free text, replace values with typed placeholders, decide in advance whether failure blocks or passes, and record the policy, action and data categories for every call.
Where customer data enters the model context
- Model emits a function call with a tool name and arguments
- Application validates and executes the tool
- Tool returns a raw result containing customer data
- Redaction step inspects, transforms or blocks the result
- Application submits the function call output item and the model continues
What to record for each tool call
- Tool name, call identifier and timestamp
- Policy and rule version applied
- Action taken: allowed, redacted, blocked or failed
- Data categories affected and counts, not values
- Failure mode triggered, if any, and the resulting behavior
- Any reversal of placeholders, with requester and purpose
Comparing implementation approaches
There are three common places to implement the control. The supplied evidence does not rank them, so judge each on coverage across tools, consistency of rules and quality of the evidence it produces.
In-application filters are the fastest to build and the easiest to tune to one tool's schema. Their weakness is drift. Each team writes its own rules, new tools ship without them, and evidence is whatever each developer chose to log.
Wrapper middleware centralizes the logic in a shared library or service that every tool call passes through. Consistency improves, but it only covers code that adopts the wrapper, and MCP servers or third-party tools may bypass it.
Policy enforcement in the execution path applies rules to tool calls and outputs wherever they run, with the action decided at runtime and evidence produced as a by-product. It reduces per-application work but adds a component to operate and to include in latency budgets.
- In-application filters: Best for a single tool or team. Weak on coverage, consistency and uniform evidence.
- Wrapper middleware: Shared logic and better consistency. Limited to code that uses the wrapper.
- Policy enforcement in the execution path: Covers tools and MCP servers under one policy set. Adds an operational component.
Designing redaction rules for structured and unstructured output
Start with an inventory. For each tool, list the output schema and classify every field as a direct identifier, a possible quasi-identifier or safe for the task. NIST's de-identification guidance follows the same order: determine direct identifiers, threat-model re-identification through quasi-identifiers and other values, and set the minimum data accuracy the intended use requires. NIST also notes that finding quasi-identifiers takes domain knowledge, so removing names and account numbers alone may not be enough.
For structured JSON, a field-level allowlist is the strongest default. Return only the fields the task needs and drop the rest. It fails closed by design, because a new field added upstream is excluded until someone approves it. Its limit is that it says nothing about what sits inside the fields you keep.
Free-text fields need separate treatment. NIST flags unstructured text inside tabular data as needing special attention, which describes ticket comments and CRM notes well. Pattern matching catches well-formed values such as email addresses and card numbers. Entity detection catches names and addresses that have no fixed format. Both miss things, and aggressive settings over-redact. NIST states that redaction alone gives no formal privacy guarantee and that selective redaction can reduce accuracy.
Replace detected values with typed placeholders, such as a customer name token or an account identifier token, rather than deleting them. The model can still reason about which entity is which, and your test suite can check whether the task still succeeds. Measure missed entities and over-redaction against samples of your own data, and measure latency in your own environment.
Reversibility, stored state and failure behavior
Reversibility is a design choice with a cost. Suppression is irreversible and simplest to reason about. Replacement with surrogate values or keyed tokens is a pseudonymization technique that NIST's draft guidance describes, alongside encryption and keyed hashing, and it says the technique used should be documented. If you keep a token map so that a final answer can be restored for the user, treat that map as sensitive data. Keep it inside your boundary, limit who and what can reverse it, and log every reversal.
Because the redacted output becomes part of context that may be stored or chained, redact before submission, not after. Data minimization in FTC guidance, collecting only what you need and keeping it safe, supports returning the smallest useful result. A provider's privacy commitments may be enforceable under FTC-enforced laws, but that does not remove your own safeguard duties. For organizations covered by 16 CFR Part 314, that includes reasonable technical safeguards for customer information.
Decide failure behavior before launch. If detection errors or times out, fail-open returns the raw output and keeps the agent working, at the risk of leakage. Fail-closed withholds the output or returns a fixed error message, which protects data but interrupts the task. A common split is fail-closed for tools that return regulated records and fail-open, with an alert, for low-risk lookups. Whatever you choose, make it explicit per tool and test it.
Where Trussed fits
Trussed enforces policy in the execution path across models, agents, tools and MCP servers. For tool call outputs, it can allow, redact or block at runtime, so the decision is enforced at runtime, not reviewed after the fact. Each action produces audit-ready evidence, mapped to frameworks including HIPAA, NIST and the EU AI Act. It can be deployed self-managed in the customer cloud, with configurable retention and data residency, which matters when the evidence itself describes sensitive activity.
The approach above works without it. Trussed is one way to apply the same rules consistently across tools you do not all control.
Tool-calling loop with the redaction point marked
1. Model emits function call
The model names a tool and supplies arguments.
2. Application executes the tool
Records are pulled from a database, CRM, ticketing system or MCP server.
3. Redaction point
Inspect and transform the raw result before it leaves your boundary.
4. Function call output submitted
Only the redacted result enters model context and conversation state.
Put the redaction point in the execution path
See how policy enforcement can allow, redact or block tool call outputs at runtime and produce audit-ready evidence for each action.
Request a Demo