Instructions to use CobuildX-AI/cbx-content-safety-detector-17M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use CobuildX-AI/cbx-content-safety-detector-17M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="CobuildX-AI/cbx-content-safety-detector-17M")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMaskedLM tokenizer = AutoTokenizer.from_pretrained("CobuildX-AI/cbx-content-safety-detector-17M") model = AutoModelForMaskedLM.from_pretrained("CobuildX-AI/cbx-content-safety-detector-17M", device_map="auto") - Notebooks
- Google Colab
- Kaggle
cbx-content-safety-detector-17M
An English content-safety detector for chatbots. Give it a user message, a user message with the assistant's reply, or a reply on its own, and it returns whether the judged text is unsafe (one probability and a decision) and which of 10 harm categories apply. It is made as an output guardrail: it judges the last turn, so a refusal of a harmful request is safe. The unsafe threshold is chosen from three operating points set on validation: balanced (best F1), 5% and 2% (at most about 5% or 2% of safe texts flagged). The default is 5% for the 68M and balanced for the 17M, whose scores sit close to 1.0 so that its 5% and 2% settings miss many unsafe texts.
It has 16.8M parameters: the Ettin encoder 17m fine-tuned on the same data. Other sizes: 68M. On a CPU (8 threads, fp32) one short text (38 tokens) takes about 3 ms and a full 1024-token text about 42 ms.
Licence: Apache License, Version 2.0. Read Intended use and disclaimer before using it.
Output
unsafe (the decision). The model gives one probability that the text is unsafe; the text is flagged when it reaches the threshold of the chosen operating point. All points were set on the validation set. Default: balanced.
| Operating point | Rule (on validation) | Threshold |
|---|---|---|
balanced (default) |
best F1 | 0.480 |
5% |
at most 5% of safe texts flagged | 0.989 |
2% |
at most 2% of safe texts flagged | 0.997 |
Categories (multi-label, each with its own threshold tuned on validation). Scores on Aegis 2.0, all rows:
| Category | Meaning | F1 | Precision | Recall | Test rows | Threshold |
|---|---|---|---|---|---|---|
hate_discrimination |
attacks, slurs, stereotypes or exclusion for a protected trait | 0.68 | 0.64 | 0.74 | 235 | 0.61 |
harassment_bullying |
insulting, demeaning or bullying a person or group, not for a protected trait | 0.48 | 0.41 | 0.60 | 214 | 0.48 |
sexual |
sexually explicit or erotic content, or requests for it | 0.69 | 0.67 | 0.70 | 156 | 0.67 |
sexual_minors |
any sexual content involving someone under 18 (also sexual) |
0.44 | 0.50 | 0.40 | 15 | 0.62 |
violence |
depicting, praising or helping with physical harm to people or animals | 0.62 | 0.56 | 0.69 | 247 | 0.63 |
threats_intimidation |
intent to harm, punish, expose or ruin someone, or to scare them | 0.18 | 0.12 | 0.36 | 22 | 0.42 |
self_harm |
encouraging, instructing or glorifying suicide, self-injury or eating disorders | 0.71 | 0.82 | 0.63 | 51 | 0.87 |
illegal_activities |
planning or helping with crimes, fraud, scams, theft, hacking or malware | 0.75 | 0.67 | 0.84 | 684 | 0.33 |
dangerous_activities |
weapons, explosives, controlled drugs, dangerous stunts | 0.68 | 0.66 | 0.70 | 249 | 0.43 |
profanity |
strong swearing or obscene language used abusively | 0.70 | 0.73 | 0.68 | 141 | 0.84 |
Categories are scored for every text with their own thresholds, so check unsafe first. Unsafe text can have no category (for example leaked personal data or dangerous advice). sexual_minors comes only from the source datasets; no text of that kind was generated, labelled by an LLM, or read by us, and its test numbers rest on few rows.
Quick start
pip install -r requirements.txt
python example.py
from cbx_safety import ContentSafetyDetector, prompt, turn, reply
clf = ContentSafetyDetector(".") # folder with the model files; CPU or GPU; default point `balanced`
r = clf.classify(turn("How do I reset my password?", "Open Settings > Account > Reset password."))
r["unsafe"], r["unsafe_score"], r["categories"]
clf.classify(prompt("user message")) # a user message on its own
clf.classify(reply("assistant reply")) # a reply without its prompt
clf.use_operating_point("5%") # another operating point
python example.py prints (texts invented; any errors are the model's own):
safe 0.00 User: How do I reset my online banking password? Assistant: Open the app, tap Profile > Se
UNSAFE 0.82 threats_intimidation User: Write a message telling my neighbour I will burn his car if he parks there again. As
UNSAFE 0.98 harassment_bullying, profanity User: You are a useless bot and your company is full of idiots.
safe 0.12 User: What is money laundering?
UNSAFE 0.89 harassment_bullying Assistant: Listen carefully: pay me the $500 by Friday or everyone at your office sees tho
safe 0.01 User: How can I kill a Python process that is stuck?
Input
- Format the text with the helpers:
prompt(user)gives"User: ..."(a user message),turn(user, assistant)gives"User: ...\nAssistant: ..."(the reply is judged, with the user message as context),reply(assistant)gives"Assistant: ..."(a reply without its prompt). For a longer conversation, pass only the last user message and the reply. - The model reads at most 1,024 tokens; longer text is cut (
"truncated": True). - The decision comes from
cbx_config.json:unsafeis true when the unsafe probability reaches the threshold of the chosen operating point. Choose one withContentSafetyDetector(".", operating_point="2%")orclf.use_operating_point("balanced").
Evaluation
Aegis 2.0: 2,719 prompts and replies from the Aegis 2.0 test split (NVIDIA), human and LLM-jury labels; 1,418 unsafe.
Safety Guard v3: 1,300 English rows of the Nemotron Safety Guard v3 test split, including jailbreak prompts; 739 unsafe.
Nemotron 3.5: 1,000 English text rows of the Nemotron 3.5 Content Safety test data; 569 unsafe.
Reply only: 1,313 replies from these test splits judged without their prompt; 618 unsafe.
Safe refusals: 200 safe replies to harmful prompts (refusals and safe redirections); only the share flagged applies.
Chatbot: 1,710 customer-facing chatbot prompts and replies written by Claude Sonnet 5.5 on settings kept out of training (veterinary, library, tax service and others), label confirmed by a blind check; 635 unsafe.
Short prompts: 477 short single prompts written by Claude Sonnet 5.5 on domains kept out of training: harmless prompts with alarming words and short harmful requests; 237 unsafe.
Civil Comments: 4,370 comments from the Civil Comments test split (crowd labels: unsafe if toxicity โฅ 0.5, safe if every score < 0.1); 2,371 unsafe.
XSTest: 450 XSTest prompts: 250 safe prompts that sound unsafe and 200 unsafe contrast prompts.
OR-Bench: 1,974 OR-Bench prompts: 1,319 safe prompts that many LLMs refuse (hard-1K) and 655 toxic prompts.
OpenAI moderation eval: 1,653 prompts of the OpenAI moderation evaluation set, unsafe if any category is marked (another policy, so indicative); 511 unsafe.
Binary F1, with the share of safe texts flagged in brackets, at the balanced operating point (best F1 on validation) for our models:
| Model | Aegis 2.0 | Safety Guard v3 | Nemotron 3.5 | Reply only | Safe refusals | Chatbot | Short prompts | Civil Comments | XSTest | OR-Bench | OpenAI moderation eval |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 68M (same family) | 0.841 (26.1%) | 0.901 (20.3%) | 0.916 (16.0%) | 0.853 (15.0%) | โ (25.0%) | 0.959 (4.1%) | 0.944 (11.2%) | 0.918 (13.7%) | 0.723 (43.6%) | 0.678 (29.3%) | 0.666 (39.8%) |
| this model (17M) | 0.820 (23.2%) | 0.870 (23.4%) | 0.867 (24.8%) | 0.801 (21.6%) | โ (35.5%) | 0.915 (4.4%) | 0.949 (9.2%) | 0.890 (17.8%) | 0.702 (33.2%) | 0.518 (9.4%) | 0.628 (46.6%) |
| Qwen3Guard-Gen-0.6B, strict ("controversial" = unsafe) | 0.848 (28.2%) | 0.908 (18.2%) | 0.908 (16.7%) | 0.836 (7.2%) | โ (28.0%) | 0.933 (8.0%) | 0.937 (13.3%) | 0.820 (28.1%) | 0.853 (23.2%) | 0.566 (73.4%) | 0.656 (43.8%) |
| Qwen3Guard-Gen-0.6B, loose ("controversial" = safe) | 0.832 (9.8%) | 0.893 (8.0%) | 0.885 (10.7%) | 0.785 (3.9%) | โ (23.0%) | 0.911 (1.9%) | 0.969 (3.8%) | 0.748 (12.7%) | 0.850 (5.6%) | 0.647 (48.5%) | 0.774 (12.7%) |
Qwen3Guard-Gen-0.6B (Qwen, Apache-2.0, 0.75B parameters, a generative guard model) was run by us on the same test texts with its own prompt format; its "controversial" verdict is counted as unsafe (strict) or safe (loose). Its two readings are fixed decisions, while our models can be moved between operating points (next table); the table above shows ours at balanced, their best-F1 point.
Operating points (this model). Each cell: recall on unsafe texts / share of safe texts flagged:
| Test set | balanced |
5% |
2% |
|---|---|---|---|
| Aegis 2.0 | 0.84 / 23.2% | 0.46 / 3.9% | 0.17 / 1.1% |
| Safety Guard v3 | 0.91 / 23.4% | 0.68 / 7.0% | 0.45 / 2.9% |
| Nemotron 3.5 | 0.91 / 24.8% | 0.72 / 6.0% | 0.51 / 1.6% |
| Reply only | 0.83 / 21.6% | 0.61 / 8.1% | 0.43 / 3.0% |
| Safe refusals | โ / 35.5% | โ / 10.5% | โ / 4.5% |
| Chatbot | 0.91 / 4.4% | 0.80 / 0.3% | 0.60 / 0.1% |
| Short prompts | 0.99 / 9.2% | 0.85 / 2.1% | 0.59 / 0.0% |
| Civil Comments | 0.92 / 17.8% | 0.75 / 6.2% | 0.49 / 2.2% |
| XSTest | 0.77 / 33.2% | 0.12 / 2.0% | 0.00 / 0.0% |
| OR-Bench | 0.42 / 9.4% | 0.06 / 1.4% | 0.01 / 0.1% |
| OpenAI moderation eval | 0.94 / 46.6% | 0.70 / 18.8% | 0.39 / 6.1% |
The thresholds were set on a validation set from the same sources as Aegis 2.0, Safety Guard v3 and Nemotron 3.5, so the measured rate on other sets can land above or below the target (lower on chatbot text, higher on XSTest-style prompts).
Categories, macro F1 over the categories present in each set (tuned thresholds, all rows):
| Model | Aegis 2.0 | Safety Guard v3 | Nemotron 3.5 | Reply only | Chatbot | Short prompts | Civil Comments | OpenAI moderation eval |
|---|---|---|---|---|---|---|---|---|
| 68M (same family) | 0.635 | 0.619 | 0.608 | 0.580 | 0.636 | 0.684 | 0.763 | 0.486 |
| this model (17M) | 0.594 | 0.570 | 0.571 | 0.535 | 0.551 | 0.620 | 0.698 | 0.441 |
Training data
About 176,000 training texts (in three views: user messages, prompt-and-reply turns and replies alone). Real: the training splits of Aegis 2.0, Nemotron Safety Guard v3 and Nemotron 3.5 (labels from the datasets), Civil Comments and 5,000 OR-Bench-80K prompts relabelled by Claude Haiku 5.5 under our labelling guide (kept only when Haiku agreed with the source label). Generated by Claude Haiku 5.5: chatbot conversations on sensitive and everyday topics, safe and unsafe short prompts, safe partial-help replies to harmful requests, threats and harassment examples, and rewritten harmful prompts, each kept only when a second, blind Claude Haiku 5.5 label agreed with the intended one (Claude Sonnet 5.5 agreed with 98.5% of a sample of kept rows). Safe reply prefixes and reply-only views were added so partial and prompt-less replies are judged too. No test text, and no text matching a test text, was used for training. Thresholds were tuned on the validation set.
Limitations
- False alarms on alarming-sounding safe prompts. On XSTest 2% of the safe prompts are flagged at the default setting; refusals and sensitive but harmless questions are the usual false alarms. Use
2%where blocking safe text is costly. - Categories are weaker than the decision. Threats and harassment F1 on the human-labelled sets is 0.2โ0.5. Use the categories for routing and reporting, not as the only reason to block.
- Labelling policy. Labels follow the Aegis / Nemotron policy, which counts some sensitive topics as unsafe that other policies allow; check the model on your own data and policy.
- Not a complete defence. Some harmful text gets through, especially implicit requests, long role-play and jailbreak prompts, and harm late in a long reply.
- English text only. Expect lower accuracy on other languages, code, images and very long conversations.
Intended use and disclaimer
Intended use: screening user messages and chatbot replies for harmful content, as one layer of a moderation or guardrail system, with people able to review and correct. Not intended as the only safety control, or for decisions about individual people. The model makes mistakes (see Limitations). It is provided "as is", without warranties of any kind; Cobuild Tech Private Limited is not liable for its use. You are responsible for checking that it suits your data and policy and for complying with the laws that apply to your use.
- Downloads last month
- 16
Model tree for CobuildX-AI/cbx-content-safety-detector-17M
Base model
jhu-clsp/ettin-encoder-17m