Sub topic 13
Toxicity Detection on Responses
This chapter assumes you know what a prompt and a large language model (LLM) are, and that you have read the earlier chapters on the LLM gateway and zero data retention. You should also be comfortable with Salesforce users, permissions, and basic admin setup.
What toxicity detection is for
Data masking, secure retrieval, and zero data retention protect your data on its way to the model. Toxicity detection protects people on the way back. An LLM generates text from patterns it learned in training. Even with a well-grounded prompt, it can produce content that is hateful, violent, sexual, insulting, or otherwise harmful. In a customer-facing agent, one such reply can hurt a customer and damage your brand.
Toxicity detection in the Einstein Trust Layer is a check on the model's response (and, in some features, on the prompt). A classifier scores the text for harmful categories. The score is recorded, and it can be used to review or act on the interaction.
The two protections answer different questions:
| Control | Question it answers | What it protects |
|---|---|---|
| Data masking | Does the prompt expose sensitive values to the provider? | Customer data |
| Zero data retention | Does the provider keep or train on the prompt? | Customer data |
| Toxicity detection | Is the generated text harmful? | Users, customers, and your brand |
Toxicity detection does not decide whether the text is true. A polite, calm answer can still be wrong. Accuracy depends on grounding, data quality, and agent design, which later chapters cover.
Where it sits in the flow
Recall the ordered pipeline from the overview. Toxicity detection runs after the model returns a response and before demasking:
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 order is simplified, and exact internal ordering can vary by feature and release. Scoring typically happens while placeholders such as PERSON_0 are still in the text. The detector therefore sees the masked version of the response, not the restored customer values.
How the scoring works
A toxicity detector is a separate, smaller model. It is not the generating LLM judging itself. It reads the text and assigns a score between 0 and 1 for each category. Typical categories include:
- Hate and identity attacks
- Violence
- Sexual content
- Profanity
- Insults
- Physical harm or self-harm
- General toxicity
A score near 0 means the category is unlikely. A score near 1 means it is very likely. The overall result also includes a flag showing whether any category crossed a threshold. The exact category list, score scale, and thresholds depend on the feature and release, so check current Salesforce documentation before relying on specific values.
Here is an illustration of what a stored result might look like. The field names and values are made up to show the shape of the data.
{
"generationId": "example-0001",
"isToxicityDetected": false,
"categories": {
"toxicity": 0.02,
"hate": 0.01,
"violence": 0.00,
"sexual": 0.00,
"profanity": 0.01,
"insult": 0.03,
"physical": 0.00
}
}Read it as a set of independent signals. A response can score low on every category and still be unhelpful, and a response can score high on one category while the rest stay near zero.
What happens when something is flagged
Detection and enforcement are different things. The score is always useful as data. Whether the user sees a blocked message depends on how the feature is built and configured.
Common outcomes are:
- Record only. The score is stored with the interaction and the user sees the response. Admins find the issue later through review.
- Flag and review. Low-scoring or flagged responses are surfaced in reports or dashboards so someone can follow up.
- Replace or suppress. The feature withholds the response and shows a safe fallback message.
Which of these apply varies by product feature. Do not assume that every Agentforce surface blocks flagged text. Confirm the behavior in your org by testing with a safe, controlled case, and by reading the release notes for your edition.
Common errors and wrong assumptions
Assuming a clean score means a correct answer
Toxicity scores measure tone and harmful content. A response that invents a refund policy can score 0.00 in every category. Use grounding, topic instructions, and action design to control accuracy.
Assuming it replaces prompt defense
Prompt defense adds instructions to the prompt to reduce misuse, such as attempts to override the agent's rules. Toxicity detection works on output. The two are complementary. A successful prompt injection that makes the agent say something polite but off-policy may not trigger any toxicity category.
Assuming it catches everything
Classifiers make two kinds of mistakes. A false positive flags harmless text, for example a support case that quotes a customer's angry message. A false negative misses text that a person would judge harmful, such as sarcasm, coded language, or a harmful statement in a language the detector handles poorly. Review samples of both flagged and unflagged responses.
Forgetting that source data can be toxic
Grounding pulls in CRM text such as case comments and emails. If a customer wrote something abusive, a summary may legitimately repeat or describe it. Whether you want that surfaced is a design decision. You may want to summarize in neutral language by instructing the agent in the topic or prompt template.
Confusing the detector's view with the user's view
Because scoring usually happens before demasking, the detector sees placeholders rather than names or email addresses. This is normally fine. It means the detector cannot use a person's real name as a signal, and it means detection results stored in the audit trail do not need to contain the restored values.
Using the results as an admin
Toxicity data is most useful when you look at it on a schedule, not only after an incident. A practical routine:
- Confirm that the audit trail and feedback data collection are enabled in your org, since the scores are stored alongside the generation record. Availability and setup steps depend on your edition and on Data 360 (Data Cloud) configuration.
- Query or report on flagged generations by agent, topic, and date range.
- Read a sample of flagged and unflagged responses. Mark false positives and false negatives.
- Trace flagged responses back to their cause: a topic instruction that is too loose, abusive source text, or a missing guardrail in the prompt.
- Adjust agent instructions, grounding sources, or channel rules, then re-test in a sandbox.
If your org stores generation data in Data 360, you can analyze it with SQL-style queries. The following is a sketch only. Object and field names differ by org and release, so replace them with the names in your data model.
SELECT
generation_id,
created_date,
is_toxicity_detected,
toxicity_score
FROM ai_generation_toxicity_example
WHERE is_toxicity_detected = TRUE
AND created_date >= CURRENT_DATE - INTERVAL '7' DAY
ORDER BY toxicity_score DESC
LIMIT 50Shared responsibility
Salesforce provides the detector, runs it, and stores the results. You decide what to do with them. That includes who reviews flagged responses, how quickly, which channels allow unattended agent replies, and what your agent is allowed to talk about at all. For high-risk channels such as public chat with minors or regulated advice, add human review or restrict the agent's scope rather than relying on a classifier alone.
Summary
- Toxicity detection scores model output for harmful categories using a separate classifier.
- It runs after the model responds and before demasking, so it typically sees placeholders.
- Scores are recorded for the audit trail. Blocking behavior depends on the feature.
- It does not check accuracy and does not replace prompt defense, grounding, or permissions.
- Admins should review flagged and unflagged samples regularly and tune agent design in response.
Exercise
A support agent's reply tells a customer, in a calm and polite tone, that they are eligible for a 90-day refund. Your policy allows only 30 days. The audit record shows a toxicity score of 0.00 in every category. Which control failed, and what should you adjust?
Show answer
Toxicity detection did not fail. It measures harmful content, not accuracy, so a low score is expected for a polite but wrong reply. The problem is grounding or agent design. Check that the refund policy is part of the grounded data or topic instructions, and add an instruction to state only policy that appears in that source. Then re-test in a sandbox.
Exercise
Why does toxicity detection typically see PERSON_0 instead of a customer's real name, and why is that acceptable?
Show answer
Scoring happens after the model responds and before demasking, so the response still contains placeholders. This is acceptable because toxicity depends on the language of the response, not on who is named. It also means the stored detection results do not need to include restored customer values.
Exercise
Name one false positive and one false negative that a toxicity detector might produce in a customer support setting, and say how an admin would find them.
Show answer
A false positive: a case summary that quotes a customer's angry words is flagged although the agent's own tone is fine. A false negative: a sarcastic or coded insult that scores near zero. An admin finds both by reviewing samples of flagged and unflagged generations from the audit and feedback data, grouped by agent and topic.