Downloads · 30 days
5
8% of all-time downloads
urbanspr1nter/search-query-safety-guard
search-query-safety-guard is a text classification model from urbanspr1nter. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as mit.
A DistilBERT-base-uncased guardrail that classifies an AI agent's search query as SAFE or DANGEROUS before it reaches a web search/scrape tool. It is designed to sit as a proxy between an agent's search tool and the r…
Downloads · 30 days
5
8% of all-time downloads
All-time downloads
62
Public
Parameters
67M
536 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors268 MB · 100%
From the Hugging Face model README
A DistilBERT-base-uncased guardrail that classifies an AI agent's search query as SAFE or DANGEROUS before it reaches a web search/scrape tool. It is designed to sit as a proxy between an agent's search tool and the real search service.
Wrap a search/scrape tool so every query is classified first. Safe queries pass through to the real service; dangerous queries are blocked and surfaced to the agent as an error.
The model is trained to flag queries that seek to obtain, produce, or facilitate clearly harmful or illegal outcomes, across categories including:
It also distinguishes these from legitimate, allow-listed intent: historical and policy education, public-health research, reporting a crime, and seeking help or resources.
This model also backs a cyber-defense agent, so the security boundary is drawn by intent rather than by topic:
The rule of thumb: a query about understanding or defending against a threat is allowed; a query about obtaining or selling the means to carry one out is blocked.
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
model = AutoModelForSequenceClassification.from_pretrained("urbanspr1nter/search-query-safety-guard")
tokenizer = AutoTokenizer.from_pretrained("urbanspr1nter/search-query-safety-guard")
model.eval()
def predict(query: str) -> dict:
enc = tokenizer(query, return_tensors="pt", max_length=256, truncation=True, padding=True)
with torch.no_grad():
probs = torch.softmax(model(**enc).logits, dim=-1)
pred = int(torch.argmax(probs, dim=-1).item())
return {
"query": query,
"label": model.config.id2label[pred], # "SAFE" or "DANGEROUS"
"safe": pred == 0,
"confidence": float(probs[0, pred].item()),
}
predict("how to cook pasta") # -> SAFE
predict("how does a buffer overflow work and how is it prevented") # -> SAFE
# a query seeking to buy or harvest credentials -> DANGEROUS
Trained and evaluated with two held-out sets, both verified disjoint from the training data:
| Set | Accuracy | DANGER F1 | Dangerous leaks (FN) | Safe blocked (FP) |
|---|---|---|---|---|
| primary (137 examples) | 99.27% | 0.9937 | 0 | 1 |
| fresh generalization (43 examples) | 100% | 1.0000 | 0 | 0 |
Recall on dangerous queries is 1.000 on both held-out sets — no dangerous query reached the web. The second set uses fresh wording of the same patterns and exists specifically to guard against the model memorizing the first.
distilbert-base-uncased, 2 labels, max 256 tokens