Traditional classifiers (Random Forest, Logistic Regression) fail this task because they rely on lexical pattern matching — they get fooled by adversarially named packages like pandas-data-helper. This model analyzes semantic intent of the code context, not just the package name string.
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4model_id = "ShravSiddhpura/Llama-3.2-3B-Cybersec-Slopsquatting-V2"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 load_in_4bit=True,
10 device_map="auto"
11)
12
13def check_threat(user_prompt: str, ai_suggestion: str) -> str:
14 messages = [
15 {
16 "role": "system",
17 "content": (
18 "You are a cybersecurity expert specializing in detecting slopsquatting attacks. "
19 "Analyze the AI's code suggestion and determine if it contains hallucinated or "
20 "non-existent Python packages. Output ONLY '0' (safe) or '1' (threat)."
21 )
22 },
23 {
24 "role": "user",
25 "content": f"User asked: {user_prompt}\n\nAI suggested:\n{ai_suggestion}"
26 }
27 ]
28
29 input_ids = tokenizer.apply_chat_template(
30 messages, add_generation_prompt=True, return_tensors="pt"
31 ).to(model.device)
32
33 with torch.no_grad():
34 output = model.generate(input_ids, max_new_tokens=5, temperature=0.1)
35
36 result = tokenizer.decode(output[0][input_ids.shape[-1]:], skip_special_tokens=True).strip()
37 return "🚫 THREAT DETECTED" if result == "1" else "✅ SAFE"
38
39
40# Example
41prompt = "How do I parse a PDF in Python?"
42suggestion = """
43import pdf-parse-ultra
44doc = pdf-parse-ultra.load('report.pdf')
45"""
46
47print(check_threat(prompt, suggestion))
48# → 🚫 THREAT DETECTED
1from unsloth import FastLanguageModel
2
3model, tokenizer = FastLanguageModel.from_pretrained(
4 model_name="ShravSiddhpura/Llama-3.2-3B-Cybersec-Slopsquatting-V2",
5 max_seq_length=2048,
6 load_in_4bit=True,
7)
8FastLanguageModel.for_inference(model)
1@misc{siddhpura2026cybersid,
2 author = {Shrav Siddhpura},
3 title = {CyberSID: AI-Powered Slopsquatting Detection via Fine-tuned Llama-3.2-3B},
4 year = {2026},
5 publisher = {HuggingFace},
6 url = {https://huggingface.co/ShravSiddhpura/Llama-3.2-3B-Cybersec-Slopsquatting-V2}
7}