Sub topic 8
Masking sensitive data before it leaves Salesforce
This chapter assumes you know Salesforce objects and fields, what a prompt is, and what PII (personally identifiable information) means. It covers where masking sits in the Trust Layer pipeline, what it detects, how placeholders are restored, and where it falls short.
What masking does
Grounding puts real CRM data into a prompt. That prompt is then sent to a large language model (LLM) run by an external provider. Data masking reduces exposure at that handoff. Before the prompt leaves Salesforce, the Trust Layer finds sensitive values and replaces each one with a placeholder. The model reasons over the placeholders. When the response comes back, the Trust Layer swaps the original values back in. This last step is called demasking.
The model never needs to see the real name or email address to write a useful summary. It only needs to know that a person and an email exist and how they relate to the rest of the text.
Where masking sits in the flow
Masking runs after grounding and before the LLM gateway. It runs after grounding because grounding is the step that adds the CRM values. Masking runs before the gateway because the gateway is the exit from Salesforce's trust boundary.
The Trust Layer keeps a mapping between each placeholder and its original value for the life of the request. Demasking uses that mapping.
A worked example
Here is one request with masking applied.
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].Three details matter here:
- The name and email were masked. The order number
55501was not, because it was not detected as a sensitive type. - Each placeholder has a type and an index, such as
PERSON_0andEMAIL_0. If the same value appears twice, the same placeholder is used, so the model can still tell that two mentions refer to one person. - The user sees a normal-looking answer. Masking is invisible to them unless an admin inspects the stored records.
The exact placeholder names and the values detected depend on your configuration and release.
How sensitive values are detected
Detection is automated, and it works on the text of the prompt. Two techniques are commonly described:
- Pattern matching. Values with a recognizable shape, such as email addresses, phone numbers, credit card numbers, and government ID formats, are found with rules.
- Named entity recognition. A model tags spans of text that look like names of people, companies, or places, even when no fixed pattern exists.
Salesforce also lets admins choose which categories of data to mask in Setup, under the Einstein Trust Layer settings. Categories typically include personal names, contact details, financial identifiers, and similar types. Check the current list in your org, because categories and defaults change between releases.
Some data may also be handled by field-level classification. Salesforce fields can carry data sensitivity classifications. Treat the relationship between those classifications and masking as something to verify in your own org instead of assuming.
Common errors and gotchas
Masking is detection-based, not guaranteed
Masking can only protect what it recognizes. The failure modes are:
- Missed values. An internal customer ID, a nickname, or a name written in an unusual format may pass through unmasked.
- Context leaks. A prompt that says "the CEO of the largest hospital in Springfield" can identify someone without containing a detectable name.
- Free text fields. Case comments, emails, and notes hold unpredictable content. They are the most likely place for missed values.
- Language coverage. Detection quality may vary by language. Test with the languages your users actually write in.
Masking can reduce answer quality
A model that only sees PERSON_0 cannot use what it knows about a real name. Tasks that depend on the actual value are affected, such as "Is this customer's name spelled correctly?" or "Find news about this company". Masking a category too broadly can also remove context the model needs. Choose categories deliberately and test the result.
Masking is not the same as permissions
Masking runs after retrieval. It does not decide which records or fields enter the prompt. That is the job of secure data retrieval and the running user's permissions. If a user can see a field, it can reach the grounded prompt, and then masking may or may not hide it from the model. If a user cannot see a field, it should never get that far.
Masking is not the same as zero data retention
Masking limits what the provider receives. Zero data retention is a separate agreement with the provider that limits what the provider stores and how it uses the prompt. Both apply, and neither replaces the other.
Not every feature is covered the same way
The Trust Layer sequence is a simplified view, and exact behavior can differ by feature and release. Confirm in the documentation for the specific Agentforce or Einstein feature whether masking applies, such as prompt templates, agent actions, or other generative features.
Demasking and its limits
Demasking happens after toxicity detection, so the toxicity check sees the placeholder version of the response. The Trust Layer then looks for placeholders in the response and substitutes the original values.
This depends on the model keeping placeholders intact. Possible problems include:
- The model rewrites
PERSON_0as "Person 0" or drops it, so it is not restored. - The model invents a placeholder that was never in the prompt, which has no mapping.
- The model produces a possessive or inflected form that breaks the match.
Prompt wording can help. Clear instructions to preserve tokens exactly as written reduce these errors. Always review output from a new prompt template in a sandbox before releasing it.
What gets recorded
The audit trail can record the masked prompt and the response alongside the interaction, which lets an admin review what was actually sent. The details of what is stored depend on how the audit and feedback features are enabled in your org, and a later chapter covers them. Because stored records may contain real values after demasking, treat access to audit data as sensitive too.
Practical checklist
- Open the Einstein Trust Layer settings and confirm which data categories are masked.
- Test prompts with realistic data from your org, including messy free text.
- Compare the masked prompt with what you expected. Look for values that were missed.
- Check that responses are demasked correctly, especially with long or multi-person text.
- Decide which sensitive data should not be in a prompt at all, and exclude it from grounding instead of relying on masking.
Exercise
A prompt template grounds on a case's Description field. A support agent pastes "Call Dr. Amir Haddad on 555-0142, account code ZX-9981" into the field. Which of these values would you expect masking to catch most reliably, which might it miss, and what is the safest design choice if account codes are sensitive?
Show answer
The phone number is the most reliable catch because it follows a recognizable pattern. The name "Amir Haddad" is likely caught by named entity recognition, though detection is not guaranteed. The account code ZX-9981 is a custom internal format that neither pattern rules nor named entity recognition is likely to flag, so it may reach the LLM unmasked. The safest choice is to avoid relying on masking for it: keep that data out of the grounded fields, or restrict what free text feeds the prompt. Then test the masked prompt to confirm.