Sub topic 13
Toxicity Detection on Responses
This chapter assumes you know what a prompt and a response are, and that you have read how the LLM gateway sends masked prompts to a model provider. Here you will see what happens to the response before a user sees it.
What toxicity detection does
Toxicity detection checks the text a model returns. A model can produce content that is hateful, violent, sexual, or insulting, even when the prompt looked harmless. The Trust Layer scores the response against these categories so that harmful output can be flagged.
Masking protects what goes out. Prompt defense shapes what the model is told. Toxicity detection protects what comes back. It is the only one of the three that examines the model's own output.
Where it sits in the flow
In the simplified pipeline, the model returns a response (step 6). Toxicity detection scores it (step 7). Demasking restores the original values (step 8). The audit trail then records the interaction (step 9).
The score is also kept for the audit record, shown as the dotted line. Order can vary by feature and release, so treat this as a working model, not a fixed contract.
What the score means
The detector returns a score for each category and an overall score. A higher score means the content is more likely to be toxic. The result is recorded with the interaction. Admins can use the stored scores to find patterns, such as a topic that often produces borderline output.
A score is a probability-style estimate from a classifier. It is not a verdict. Two points follow from this:
- A low score does not prove a response is accurate, fair, or appropriate for your business.
- A high score on a harmless response, a false positive, is possible. Review flagged cases instead of assuming they are all harmful.
Common errors
- Treating toxicity detection as a fact check. It does not detect wrong answers (hallucinations). An agent can state an incorrect refund policy politely, with a score near zero.
- Treating it as a data leak filter. It scores harmful language. Masking and permissions handle sensitive data.
- Assuming it replaces agent design. Clear topics, scoped actions, and good instructions still reduce the chance of off-topic or harmful replies.
- Never reading the results. Scores are only useful if someone reviews them.
Why it matters for review
Because scores are stored with the audit data, you can sample interactions, sort by score, and inspect the highest ones. This turns a vague worry ("could the agent say something bad?") into a concrete review task. It also gives you evidence when you tune agent instructions or restrict an action.
Exercise
An agent replies, politely and with a toxicity score near zero, that a customer qualifies for a refund that company policy does not allow. Did toxicity detection fail? What protects against this problem?
Show answer
No. Toxicity detection scores harmful language, not factual or policy correctness, so a polite wrong answer scores low. Protection comes from grounding in accurate CRM or knowledge data, clear agent topics and instructions, scoped actions, and human review of audit records.
Exercise
Name the step that comes directly before toxicity detection and the step that comes directly after it in the simplified pipeline.
Show answer
The model returning its response comes before it (step 6). Demasking comes after it (step 8).