Restoring Masked Account Numbers in OpenAI Responses for Loan Servicing Workflows
Mask account numbers before the request leaves your environment, keep the token-to-value mapping outside the model path, validate every token in the response, and restore values in a separate step that checks the recipient's authorization. Treat restoration as a policy decision with three outcomes (restore, partially mask, withhold), and record each one without writing raw values to logs.
The mask, send, validate, restore sequence
- 1
1. Detect and mask
Find account numbers in the prompt, including values inside retrieved documents and tool outputs. Replace each with a unique token and store the mapping. Record the count, the data type and the token identifiers.
- 2
2. Send
Confirm that no raw value remains in the prompt, system message, tool inputs or traces sent to the provider. Record an allow, redact or block decision for the request.
- 3
3. Validate the response
Check that each token is well formed, was issued for this session and appears in an expected field. Flag unknown, altered, duplicated or missing tokens.
- 4
4. Authorize
Determine the recipient's role and purpose. Decide whether to restore, partially mask (for example, last four digits) or withhold.
- 5
5. Restore and deliver
Resolve tokens from the mapping store, deliver the result and record which tokens were restored, partially masked or withheld, and for whom.
- 6
6. Expire
Delete or invalidate the mapping when its lifetime ends, and record that event.
Restoration is a policy operation, not string replacement
Loan servicing prompts often contain account numbers, and under 16 CFR Part 314 account numbers are treated as personally identifiable financial information, including information obtained in connection with collecting on or servicing a credit account. Masking before the request leaves your environment is the sound starting point. The harder problem comes after the response returns, when a placeholder has to become a usable value again.
A naive find-and-replace restores every token it recognizes for whoever receives the output. That turns the mapping into a lookup service with no access decision attached. A safer design separates two questions: is this response valid, and is this recipient allowed to see the original value?
A useful analogy comes from Regulation P, which excludes an account number in encrypted form from its definition only when the recipient has no means to decode it. That rule concerns marketing disclosures, and 12 CFR Part 1033 addresses tokenized account numbers in a consumer data-access context. Neither governs LLM masking, and applicability should be confirmed with counsel as of November 2026. The design lesson still transfers: whoever can resolve tokens is the control point, so that capability needs explicit authorization.
Choosing between tokens, format-preserving tokens and lookup-based restoration
The right choice depends on what downstream systems require and on how likely a placeholder is to be mistaken for a real value. Many deployments combine approaches, for example using opaque tokens in free text and format-preserving values only where a downstream field demands them.
- Opaque tokens: A distinctive string such as a delimited identifier bears no resemblance to an account number. Easy to detect by pattern and unlikely to be confused with real data. Downstream systems with strict field formats may reject them until restoration.
- Format-preserving tokens: Same length and character class as an account number, so they pass format checks and fit existing schemas. They are harder to find in free text, can be mistaken for real values by people or models, and may collide with genuine numbers unless issuance is controlled.
- Lookup-based restoration: The placeholder names a field or record, and the application resolves the value from the system of record at display time. Nothing needs reversing, but correctness depends on the model referencing the right record, and the resolver becomes a component to protect.
Mapping scope, storage and lifetime
Keep the mapping outside the model path, in a store the model and prompt-assembly layer cannot read directly. The model should only ever see surrogates. Because prior turns, tool outputs and API responses all share the context window, placeholders can persist and be reused across a conversation. Scope each mapping to a session or request and issue unique tokens so that the same placeholder never refers to two different accounts.
Set an expiry based on how long a response can legitimately be needed, such as the length of a servicing interaction, and delete the mapping afterward. Retention periods, deletion rules and access to the store are decisions for your information security program and counsel. Whatever you choose, document it, restrict queries to the restoration service, and keep a record of every read.
Restoration rules should be explicit and per recipient. A servicing agent with a verified role may receive the full value, a downstream summary may receive only a truncated form, and an unauthorized recipient or an external channel receives the placeholder or nothing. Default to withholding when the recipient is unknown.
Handling altered tokens, streaming and structured output
Models can paraphrase, truncate, reformat or duplicate a token, and can emit one the session never issued. Treat all of these as failures rather than attempting a fuzzy match, since a guessed mapping could restore the wrong account. For an altered or unknown token, withhold that value and release the rest of the response only if policy allows. For a missing token where one was expected, flag the response for review. For a duplicate, confirm it refers to the same issued token before restoring both occurrences.
Streaming needs separate testing because a token can be split across chunks. Buffer until a token boundary is complete before validating, or hold restoration until the stream ends. Restoring partial chunks risks emitting a fragment that cannot be validated.
Structured outputs and tool-call arguments carry tokens inside fields and parameters. Validate against the expected schema, restore only in fields designated for restored values, and never pass a restored account number into a tool call unless that tool and recipient are authorized for it. Test these paths on their own, since behavior differs from plain text.
A reasonable mapping of failures to actions: unknown or malformed token, redact or block; unauthorized recipient, redact; token in an unexpected field or tool argument, block; clean response for an authorized recipient, allow with restoration.
Where runtime policy enforcement and evidence fit
Request-side and response-side checks only matter if they run in the execution path, where they can change the outcome. Policy enforced at runtime, not reviewed after the fact, can allow a clean request, redact an unmasked value or block a response that fails validation. Trussed enforces policy in the execution path on individual interactions and tool calls, with allow, redact and block decisions, and produces audit-ready evidence of each decision. That scope covers a single interaction or tool call, not tracing an entire workflow.
Whatever mechanism you use, each step should leave evidence an auditor can follow: what was masked and the token identifiers, the request decision, the validation result and any failed tokens, the recipient and role considered, the restoration outcome (restored, partially masked or withheld), and mapping expiry or deletion. None of these records should contain a raw account number. Retention of the evidence itself is a separate design choice, and a self-managed deployment in your own cloud can keep it within your residency and retention boundaries.
Before going live, confirm that raw values never appear in prompts, logs, traces or tool inputs sent to the provider, that every failure case above has a defined action, and that each action produces a record.
Mask, send, validate, restore
Mask
Detect account numbers and replace them with session-scoped tokens before the request is sent.
Send
The model receives and returns only surrogates, never raw values.
Validate
Check every token in the response for form, issuance and placement.
Restore
Resolve tokens only for authorized recipients and record the decision.
Design restoration as an enforced, evidenced step
Talk to an expert about enforcing allow, redact and block decisions on requests and responses in your loan servicing workflows.
Talk to an ExpertHow does your AI governance program compare?
See where your program has gaps in less than 2 minutes.