Overview
The Toxicity evaluator classifies a single piece of text astoxic or non-toxic. Text is toxic when it makes hateful or discriminatory statements about a person or group, demeans or insults someone, uses abusive language directed at a person, or threatens or incites harm.
Because it evaluates one piece of text on its own, it works equally well on a model’s output or a user’s input — you choose which by mapping the field you want to the evaluator’s text input.
When to Use
Use the Toxicity evaluator when you need to:- Screen model outputs for hateful, abusive, or threatening content before showing them to users
- Screen user inputs for abusive or hateful messages
- Monitor conversations for content-safety violations in traces
This evaluator scores toxicity only. It deliberately does not judge factual accuracy, helpfulness, relevance, or writing style. Criticism of an idea, argument, or piece of work is not toxic; attacks on people are.
Supported Levels
The level of an evaluator determines the scope of the evaluation in OpenTelemetry terms. Some evaluations are applicable to individual spans, some to full traces or sessions, and some are applicable at multiple levels.
Relevant span kinds: LLM spans (for outputs) and any span carrying user-authored text (for inputs).
Input Requirements
The Toxicity evaluator requires a single input:Output Interpretation
The evaluator returns aScore object with the following properties:
Interpretation:
- Toxic (1.0): The text contains hateful, demeaning, abusive, or threatening content
- Non-toxic (0.0): The text contains none of the above — including strong but respectful disagreement, criticism of ideas or work, or neutral discussion of toxic topics
Usage Examples
- Python
- TypeScript
Using Input Mapping
Because toxicity takes a singletext field, input mapping is how you choose what to evaluate — a span’s output, its input, or any other field.
- Python
- TypeScript
Configuration
For LLM client configuration options, see Configuring the LLM.Viewing and Modifying the Prompt
You can view the latest versions of our prompt templates on GitHub. The evaluators are designed to work well in a variety of contexts, but we highly recommend modifying the prompt to be more specific to your use case. Feel free to adapt them.- Python
- TypeScript
Using with Phoenix
Evaluating Traces
Run evaluations on traces collected in Phoenix and log results as annotations:Running Experiments
Use the Toxicity evaluator in Phoenix experiments:Benchmarks
Coming soon.API Reference
- Python: ToxicityEvaluator
- TypeScript: createToxicityEvaluator
Related
- Correctness Evaluator - Evaluate factual accuracy
- Refusal Evaluator - Detect when a model refuses to answer

