Sub topic 4
Following one request through the layer
This chapter traces a single prompt from the moment a user asks an Agentforce agent a question to the moment the answer appears. It assumes you know basic Salesforce objects, fields, and user permissions. It also assumes you know what a large language model (LLM) and a prompt are, and that you know why PII (personally identifiable information) matters. Later chapters cover each step in detail. Here the goal is the order of the steps, what each one hands to the next, and where things commonly go wrong.
Why the order matters
The Einstein Trust Layer is not a single filter. It is a sequence of controls. Each control protects something different, and several depend on the output of an earlier step.
- Masking can only hide values that grounding has already placed in the prompt.
- Demasking can only restore values that masking recorded.
- The audit trail can only describe what the earlier steps actually did.
If you hold the order in your head, you can reason about questions such as "Where was this value hidden?" or "Which step would have blocked this?" without memorizing every setting.
The order below is simplified. Exact internal ordering and behavior can vary by feature and release, so treat it as a working model and not a specification.
1. User asks the agent a question
2. Secure data retrieval and grounding add CRM data the user may access
3. Data masking replaces sensitive values with placeholders
4. Prompt defense adds instructions that guard against misuse
5. LLM gateway sends the prompt to the model provider (zero data retention)
6. Model returns a response
7. Toxicity detection scores the response
8. Demasking restores the original values
9. Audit trail records the interaction
10. Response is shown to the userThe pipeline at a glance
The first half of the flow runs inside Salesforce and prepares the prompt. The middle step crosses the trust boundary to the model provider. The second half runs back inside Salesforce and prepares the response.
Step by step
1. The user asks a question
An Agentforce agent receives a request, for example "Summarize the case for Maria Lopez." The agent decides which topic and action handle it. An action might be a prompt template, a flow, or Apex code. When the action needs the LLM, a prompt is built. The prompt is built on behalf of the running user, which matters in the next step.
2. Retrieval and grounding
Grounding means filling a prompt template with real data from your org, so the model answers from facts and not from guesses. Secure data retrieval gathers that data using the running user's access. Object permissions, field-level security, and sharing rules determine which records and fields are available.
Two consequences follow:
- Two users who ask the same question can produce different prompts.
- A field the user cannot see does not reach the prompt, so it cannot reach the model.
3. Data masking
Before the prompt leaves Salesforce, the layer detects sensitive values and replaces them with placeholders. It keeps a mapping so it can reverse the change later. Detection is pattern-based and depends on configuration, so which values count as sensitive is something you review, not something you can assume.
4. Prompt defense
Prompt defense adds instructions to the prompt that guard against misuse, such as attempts to override the agent's rules or to leak its instructions. It is guidance for the model, so it lowers risk. It does not guarantee the model will comply.
5. LLM gateway and zero data retention
The gateway is the single exit point. It sends the masked, defended prompt to the chosen model provider and receives the reply. For supported providers, agreements with Salesforce specify zero data retention. This means the provider does not store the prompt or response after processing and does not use them for training. This is a contractual and architectural control at the provider. Salesforce does not enforce it inside the model itself.
6. Model response
The model generates text. It may reuse placeholders from the prompt. It sees PERSON_0, not the person's name.
7. Toxicity detection
The response is scored for harmful content, such as hate, violence, or profanity. The scores are recorded so that admins can review them later. Whether a high score changes what the user sees depends on the feature and its configuration.
8. Demasking
The layer swaps placeholders back to the original values using the saved mapping. This happens inside Salesforce, so the real values never go back to the provider.
9. Audit trail and display
The interaction is recorded, including the prompt stages, the response, and the safety scores. Feedback from the user can also be stored. Then the final text is shown.
A worked example
This example follows one prompt through masking and demasking.
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].Note that 55501 was not masked. The placeholder names and the set of detected values are illustrative and depend on configuration. An order number is not a universal PII pattern, so a default detector may leave it alone. If your policy treats it as sensitive, the fix is in configuration, not in the model.
The same idea in code form makes the mechanism concrete. This simplified Python sketch is not Salesforce code. It only shows why demasking needs the mapping that masking created.
import re
def mask(prompt, values):
"""Replace known sensitive values with numbered placeholders."""
mapping = {}
for kind, value in values:
index = sum(1 for key in mapping if key.startswith(kind))
placeholder = f"{kind}_{index}"
mapping[placeholder] = value
prompt = prompt.replace(value, placeholder)
return prompt, mapping
def demask(text, mapping):
"""Restore placeholders using the saved mapping."""
for placeholder, value in mapping.items():
text = re.sub(rf"\b{placeholder}\b", value, text)
return text
prompt = "Summarize the case for Maria Lopez ([email protected])."
masked, mapping = mask(
prompt,
[("PERSON", "Maria Lopez"), ("EMAIL", "[email protected]")],
)
print(masked)
reply = "PERSON_0 reported damage. Contact EMAIL_0."
print(demask(reply, mapping))Running it prints the masked prompt, then the restored reply. If the mapping is lost between the two calls, the placeholders stay in the text.
Common errors and misconceptions
| Misconception | What actually happens |
|---|---|
| "Masking protects fields the user cannot see." | Those fields never reach the prompt. Permissions handle that in step 2, before masking. |
| "Masking hides everything sensitive." | Only values the detectors recognize under your configuration are masked. Other values pass through. |
| "Zero data retention means nothing is stored." | It covers the model provider. Salesforce still records the audit trail. |
| "Prompt defense blocks all attacks." | It adds guard instructions. A model can still follow bad input. |
| "Toxicity detection edits the prompt." | It scores the response, after the model has run. |
| "The model sees the user's real name." | It sees placeholders for detected values. Undetected values are visible. |
Edge cases to keep in mind
- Placeholders in the wrong place. If the model rewrites or drops a placeholder, demasking cannot restore it. The user may see
PERSON_0or a missing name. - Values the user can see but masking misses. Free-text fields such as case descriptions can hold names or numbers in unusual formats. Detection may not catch them.
- Over-broad access. If a profile grants too much access, grounding legitimately includes that data. The layer does not second-guess permissions. Permissions are the customer's responsibility.
- Features outside the standard path. Not every AI feature uses every step in the same way. Check the documentation for the feature you deploy.
Exercises
Exercise
A user without access to the Account.AnnualRevenue field asks an agent to summarize an account. Which step keeps that value away from the model, and why is masking not the right answer?
Show answer
Secure data retrieval and grounding (step 2) keeps it out, because retrieval uses the running user's field-level security, so the field is never added to the prompt. Masking comes later and only replaces sensitive values that are already in the prompt. It is not an access control.
Exercise
The LLM replies "PERSON0 should call EMAIL0," and the user sees "Maria Lopez should call [email protected]." Which step made the change, and where does it get the original values?
Show answer
Demasking made the change. It uses the mapping saved during data masking, which stays inside Salesforce, so the original values were never sent back to the provider.
Exercise
Put these in order: toxicity detection, data masking, LLM gateway, grounding, demasking.
Show answer
Grounding, data masking, LLM gateway, toxicity detection, demasking. Prompt defense falls between masking and the gateway, and the audit trail follows demasking.