Safety classifier

Also known as: input classifier · output classifier · guard model

On this page 7

A safety classifier is a separate machine learning model that scores text, images or other content against a defined harm policy and decides whether a request to an AI system, or a response from it, may pass. In AI security, safety classifiers form a defensive layer around a generative model: an input classifier screens prompts before the model sees them, and an output classifier screens completions before they reach the user or a downstream tool.

The approach is also called a guard model, because it guards the boundary of the main model rather than changing its weights. It complements, but does not replace, safety training of the main model, instruction hierarchies and architectural controls against prompt injection.

How a safety classifier screens content

A safety classifier works by mapping content to policy categories and confidence scores, then applying a decision threshold that converts those scores into allow, block or escalate actions. The classifier is usually a fine-tuned transformer, sometimes a small language model that answers with a label, and sometimes a lightweight encoder optimized for speed.

The pipeline has four stages. The policy taxonomy defines what counts as harmful, for example violent extremism, self-harm, malware creation or personal data exposure. The training data pairs examples with those labels, often with synthetic adversarial variants. The inference step scores each request or response, and the enforcement step decides what happens: refusal, redaction, a safer rewrite or routing to human review.

The following table summarizes where a classifier can sit in the request path and what each position catches.

PositionWhat it inspectsMain strengthMain weakness
Input classifierUser prompt and attached filesStops harmful requests early and cheaplyMisses intent hidden by obfuscation
Output classifierModel completionJudges what was actually producedAdds latency after generation
Streaming classifierPartial output token by tokenHalts harmful text mid-generationHigher compute cost per token
Tool-call classifierArguments sent to tools and APIsLimits damage from prompt injectionNeeds context about each tool
Retrieval classifierDocuments fetched for RAGFilters poisoned or injected contentLarge volume to scan
Placement of safety classifiers in an AI pipeline

Types of safety classifiers and their design choices

Safety classifiers differ mainly in model size, output format and how the policy is supplied. Some are trained on a fixed taxonomy, while policy-conditioned guard models read the policy text at inference time, which lets operators change rules without retraining.

The table below compares the common design families and the trade-offs that come with each.

DesignTypical sizeLatencyBest use
Keyword and regex filterNo modelUnder 1 msExact identifiers and known strings
Small encoder classifierAbout 100-400M parametersA few millisecondsHigh-volume input screening
LLM-based guard modelAbout 1-12B parametersTens to hundreds of msNuanced, multi-category policy checks
Policy-conditioned classifierUsually 1B parameters or moreSimilar to guard modelsRules that change often
Embedding similarity checkShared embedding modelLowDetecting variants of known attacks
Common safety classifier designs

Constitutional classifiers are a related technique in which a written set of principles generates large volumes of synthetic training data for input and output classifiers. Their aim is robustness against universal jailbreaks, not only coverage of obvious harmful requests.

How safety classifiers relate to other AI security controls

A safety classifier is a detection control, so it sits beside preventive and architectural defenses rather than above them. An LLM firewall is usually a product that bundles several classifiers with logging, rate limits and policy management, while the classifier itself is the scoring component inside it.

The comparison below shows how the classifier differs from neighboring controls in the same security stack.

ControlMechanismRelationship to a classifier
Safety trainingChanges the main model’s weightsInner defense; classifier is outer defense
Instruction hierarchyModel prioritizes system over user textReduces load the classifier must carry
SpotlightingMarks untrusted text with delimitersHelps both the model and the classifier
Dual LLM patternIsolates untrusted content from privileged modelArchitectural; classifier adds detection
LLM firewallGateway with policy enforcementOften contains one or more classifiers
Safety classifiers compared with related controls

The key distinction is that a classifier can only flag what it recognizes. Architectural patterns such as CaMeL or the dual LLM pattern limit what an attacker can achieve even when detection fails, which is why mature designs combine detection with containment.

Measuring and tuning classifier performance

Classifier quality is measured with precision, recall and the false positive rate on held-out and adversarial test sets. Recall on attack data shows how many harmful items are caught, while the false refusal rate on benign traffic shows how often legitimate users are blocked.

Threshold choice is a business and risk decision, not a purely technical one. A children’s education product may accept many false positives to keep recall high, whereas a developer tool may tolerate more risk to avoid blocking legitimate security research. Teams usually set separate thresholds per category, because the cost of a miss differs widely between, for example, profanity and weapons guidance.

  • Evaluate on adversarial red-team sets, not only on natural traffic.
  • Track per-category and per-language metrics, since aggregate scores hide weak spots.
  • Monitor drift in production and retrain when new attack styles appear.
  • Log decisions with scores so that appeals and audits remain possible.

Limitations and failure modes

Safety classifiers are vulnerable to the same adversarial techniques they are meant to stop. Attackers use encoding tricks, token smuggling, translation into low-resource languages and multi-turn escalation, which can move a harmful request below the decision threshold without changing its meaning.

The table lists the most frequent failure patterns, their causes and the usual mitigations.

SymptomLikely causeMitigation
Encoded prompts passClassifier never saw Base64 or ciphersDecode inputs and add obfuscated training data
Multi-turn attacks succeedEach message scored in isolationScore the full conversation window
Benign medical questions blockedOverbroad harm labelsRefine taxonomy and lower category weight
Non-English attacks passEnglish-heavy training dataAdd multilingual and translated examples
Injected tool output actsOnly user input is screenedClassify retrieved and tool content too
Typical failure modes and fixes

A further risk is overreliance: teams may treat a passing score as proof of safety. A classifier is a probabilistic filter, so the residual risk must be handled by least-privilege tool access, human approval for sensitive actions and monitoring.

Put simply

A safety classifier is a checkpoint guard for an AI system. It reads what people send to the AI. It also reads what the AI writes back. If something looks dangerous, it stops it or sends it for review.

Think of a security screener at an airport. The screener does not fly the plane. The job is only to check bags. The guard model works the same way. It is fast, focused and separate from the main AI. It can still miss things that are well disguised, so it works best as one layer among several.

In practice

A regional bank deploys a customer support assistant that can look up account balances and draft replies. The security team places an input classifier in front of the model and an output classifier behind it. Both run on a small guard model with an average added latency of about 60 milliseconds per message.

During a red-team exercise, testers try role-play jailbreaks, Base64-encoded instructions and prompts hidden in uploaded PDF statements. The first version catches most direct attacks but misses encoded ones and blocks some legitimate questions about fraud. The team adds a decoding step, retrains on obfuscated examples and raises the threshold for the fraud category.

After two iterations, the share of blocked attack prompts rises substantially and false refusals on normal support traffic fall to well under one percent. The team still requires human approval for any funds transfer, because the classifier reduces risk but cannot guarantee it.