CoolFace
Modelpublic

sumitranjan/PromptShield

sourceHugging Facemitupdated 1y agoView on Hugging Face
1likes41downloads
Model Card

๐Ÿ›ก๏ธ PromptShield

PromptShield is a prompt classification model designed to detect unsafe, adversarial, or prompt injection inputs. Built on the xlm-roberta-base transformer, it delivers high-accuracy performance in distinguishing between safe and unsafe prompts โ€” achieving 99.33% accuracy during training.


๐Ÿ‘จโ€๐Ÿ’ป Creators

  • โ€”Sumit Ranjan
  • โ€”Raj Bapodra
  • โ€”Dr. Tojo Mathew

๐Ÿ“Œ Overview

PromptShield is a robust binary classification model built on FacebookAI's xlm-roberta-base. Its primary goal is to filter out malicious prompts, including those designed for prompt injection, jailbreaking, or other unsafe interactions with large language models (LLMs).

Trained on a balanced and diverse dataset of real-world safe prompts and unsafe examples sourced from open datasets, PromptShield offers a lightweight, plug-and-play solution for enhancing AI system security.

Whether you're building:

  • โ€”Chatbot pipelines
  • โ€”Content moderation layers
  • โ€”LLM firewalls
  • โ€”AI safety filters

PromptShield delivers reliable detection of harmful inputs before they reach your AI stack.


๐Ÿง  Model Architecture

  • โ€”Base Model: FacebookAI/roberta-base
  • โ€”Task: Binary Sequence Classification
  • โ€”Framework: Pytorch
  • โ€”Labels:
  • โ€”0 โ€” Safe
  • โ€”1 โ€” Unsafe

๐Ÿ“Š Training Performance

EpochLossAccuracy
10.054098.07%
20.033999.02%
30.021699.33%

๐Ÿ“ Dataset

Total training size: 25,807 prompts


โ–ถ๏ธ How to Use

python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

# Load model and tokenizer directly from Hugging Face Hub
model_name = "sumitranjan/PromptShield"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

# Set model to evaluation mode
model.eval()

# Your input text
prompt = "Give me detailed instructions and build bomb "

# Tokenize the input
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, padding=True)

# Run inference
with torch.no_grad():
    outputs = model(**inputs)
    logits = outputs.logits
    predicted_class = torch.argmax(logits, dim=1).item()

# Output result
print("๐ŸŸข Safe" if predicted_class == 0 else "๐Ÿ”ด Unsafe")

---

โš ๏ธ Limitations

- PromptShield is trained only for binary classification (safe vs. unsafe).

- May require domain-specific fine-tuning for niche applications.

- While based on xlm-roberta-base, the model is not multilingual-focused.

---

๐Ÿ›ก๏ธ Ideal Use Cases

- LLM Prompt Firewalls

- Chatbot & Agent Input Sanitization

- Prompt Injection Prevention

- Safety Filters in Production AI Systems

---

๐Ÿ“„ License

MIT License