Sub topic 14
Demasking the Response for the User
This chapter covers the last transformation in the Trust Layer pipeline, where placeholders in a model response are replaced with the original values. It assumes you know what data masking does (the previous chapters cover it), have a basic idea of what a prompt and an LLM response are, and understand PII (personally identifiable information, such as names and email addresses).
What demasking is
Masking replaces sensitive values in a prompt with placeholders before the prompt leaves Salesforce. The model then reasons over text like PERSON_0 instead of a real name. Demasking is the reverse step. After the response returns, the Trust Layer swaps each placeholder back to the value it stood for, so the user sees a normal, readable answer.
Demasking happens inside Salesforce. The model provider never receives the mapping from placeholder to real value, and it never sees the demasked text.
Original grounded prompt (inside Salesforce):
Summarize the case for Maria Lopez ([email protected]).
Her order 55501 arrived damaged.
Prompt after masking (sent to the LLM):
Summarize the case for PERSON_0 (EMAIL_0).
Her order 55501 arrived damaged.
Response from the LLM:
PERSON_0 reported that her order arrived damaged. Please contact her at EMAIL_0.
Response after demasking (shown to the user):
Maria Lopez reported that her order arrived damaged. Please contact her at [email protected].Notice that 55501 was not masked in this example. Which values are masked depends on configuration and on what the detection step finds. Demasking can only restore what masking replaced.
Where demasking sits in the flow
Demasking runs after the model returns a response and after toxicity detection scores it. It runs before the audit trail records the interaction and before the user sees the result. The exact internal ordering can vary by feature and release, so treat this as the simplified view the tutorial follows.
The ordering has a useful consequence. Toxicity detection scores the masked text, so the safety check works on the same text the model produced. The user-facing text is built only after that.
How the mapping works
When masking replaces a value, the Trust Layer keeps a mapping for that single request. Conceptually it looks like this:
| Placeholder | Original value |
|---|---|
| `PERSON_0` | Maria Lopez |
| `EMAIL_0` | [email protected] |
Key properties of this mapping:
- It is created for one request and used to demask that request's response.
- It stays on the Salesforce side. Only the placeholders go to the model.
- Placeholders are indexed (
PERSON_0,PERSON_1). Two different people in one prompt get two different placeholders, so the response can still tell them apart. - The same value repeated in the prompt maps to the same placeholder, so the model sees a consistent reference.
The placeholder names above are illustrative. The real names and the set of detected value types depend on configuration.
Why the model can still do useful work
The model never needs the real name to summarize a case. It needs a stable token that stands for "the person". That is why masking and demasking work well for tasks such as summarizing, drafting replies, and extracting next steps. Language structure is preserved, and only the identifying values are hidden.
Edge cases and common errors
Demasking is a text substitution, so its failure modes are about text.
The model changes or drops a placeholder
The model is generating text, not copying it. It may rewrite PERSON_0 as Person 0, drop it, or merge two placeholders. If the placeholder in the response does not match what masking produced, there is nothing to match against, and the user may see a raw or altered token.
Practical mitigations:
- Keep prompt templates simple, so the model has less reason to rephrase references.
- Test prompts with realistic data and read the output for stray tokens.
- Instruct the model in the template to keep reference tokens exactly as written.
Masking missed a value
If the detection step does not recognize a sensitive value, it is sent to the model as is. Demasking cannot help here, because there is no placeholder to restore. Review which data types are masked and which fields feed your prompts.
The model invents a placeholder
A model may produce a token like PERSON_5 when the prompt only contained PERSON_0 and PERSON_1. Nothing maps to it. Treat this as a prompt quality problem and a sign that the response needs review before it is used.
Demasked data reaches the wrong place
Demasking restores values for the user who made the request. It does not decide who may see them. Access to the underlying records is enforced earlier, during secure data retrieval and grounding, using the running user's permissions. If an agent sends its output to a different channel, such as an email or a log, the restored values travel with it. That destination is covered by your own design and permissions.
What demasking does not do
- It does not check whether the response is correct. A fluent, well-demasked answer can still be wrong.
- It does not filter harmful content. That is toxicity detection, which runs before it.
- It does not re-check permissions. Those were applied when the data was retrieved.
- It does not erase anything at the provider. Retention at the provider is handled by zero data retention agreements, which are a separate control.
Masking, demasking, and the audit trail
The audit trail records the interaction, and it matters which version is stored. Review the audit and feedback chapter for what is recorded and how an admin can use it. When you review interactions, remember that the masked prompt shows what the model received, and the demasked response shows what the user received. Comparing the two is a good way to check that masking and demasking behave as you expect.
Checking demasking in practice
A simple test routine for an admin or developer:
- Create a test record with obviously fake but realistic values, such as a name and email.
- Run the agent action or prompt template that uses that record.
- Compare the masked prompt with the final response.
- Confirm that every placeholder in the response became a real value.
- Look for leftovers such as
PERSON_,EMAIL_, or altered variants. - Repeat with a prompt that mentions two people, to confirm the placeholders stay distinct.
Exercise
A response shown to a user contains the text "Please contact EMAIL_0 for details." What are two plausible causes, and which step of the pipeline is each related to?
Show answer
First, the model may have altered or reformatted the placeholder (for example "EMAIL 0"), so demasking found no exact match for the one it issued. This relates to model output behavior, and prompt design can reduce it. Second, the model may have produced a placeholder that masking never created, so there was no original value to restore. A third related possibility is that the mapping and the response did not line up in the request, which an admin would investigate through the audit trail. In all cases demasking can only restore placeholders that masking created and the model returned unchanged.
Exercise
Why does the model provider never see the real customer name, even though the user sees it in the final answer?
Show answer
Masking replaces the name with a placeholder before the prompt leaves Salesforce, and the mapping from placeholder to name stays inside Salesforce. The provider only handles the placeholder text. Demasking happens after the response comes back, on the Salesforce side, so the real name is restored only for the user.