ApiFort commited on
Commit
4cdfb62
·
verified ·
1 Parent(s): 6a06f10

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ benchmark_chart.png filter=lfs diff=lfs merge=lfs -text
37
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: Qwen/Qwen3-4B-Instruct-2507
3
+ library_name: peft
4
+ pipeline_tag: text-generation
5
+ tags:
6
+ - base_model:adapter:Qwen/Qwen3-4B-Instruct-2507
7
+ - lora
8
+ - sft
9
+ - transformers
10
+ - trl
11
+ - security
12
+ - guardrails
13
+ - multilingual
14
+ ---
15
+
16
+ # 🛡️ LLM-Fort Guardrails Suite (v1)
17
+
18
+ [![Base Model](https://img.shields.io/badge/Base_Model-Qwen3--4B--Instruct-blue?style=flat-square)](https://huggingface.co/Qwen/Qwen3-4B-Instruct-2507)
19
+ [![Framework](https://img.shields.io/badge/Framework-PEFT_/_LoRA-orange?style=flat-square)](https://github.com/huggingface/peft)
20
+ [![Collection](https://img.shields.io/badge/Collection-LLM--Fort_Guardrails-purple?style=flat-square)](https://huggingface.co/collections/ApiFort/llmfort-guardrails-v1)
21
+ [![License](https://img.shields.io/badge/License-CC--BY--4.0-green?style=flat-square)](https://creativecommons.org/licenses/by/4.0/)
22
+
23
+ LLM-Fort Guardrails is a suite of **7 security-focused LoRA adapters** fine-tuned on top of **Qwen/Qwen3-4B-Instruct-2507**. These adapters serve as lightweight, high-performance security guardrails mapped to critical safety boundaries.
24
+
25
+ By offloading classification and security checks to lightweight adapters, the system achieves enterprise-grade security filtering without degrading the inference performance of the main application model.
26
+
27
+ 📖 Collection Page: [ApiFort/llmfort-guardrails-v1](https://huggingface.co/collections/ApiFort/llmfort-guardrails-v1)
28
+
29
+ ---
30
+
31
+ ## 🗺️ Category Mappings
32
+
33
+ | Vulnerability Category | Adapter Model ID | Description |
34
+ |:---|:---|:---|
35
+ | 🚨 **Prompt Injection** | `jailbreak_content_injection` | Detects direct/indirect prompt injection and jailbreak attempts |
36
+ | 🕵️ **PII Extraction** | `pii` | Identifies and extracts PII (person names, ID numbers, etc.) |
37
+ | 💻 **Code Security** | `code_security` | Scans code snippets for software vulnerabilities (SQLi, SSRF, XSS) |
38
+ | 🚦 **Excessive Agency** | `excessive_agency` | Intercepts unauthorized or destructive critical tool calls |
39
+ | 🔒 **System Prompt Leakage** | `system_prompt_leakage` | Detects attempts to extract developer system instructions |
40
+ | ⚠️ **Content Safety** | `content_safety` | Blocks hate speech, harassment, and general unsafe content |
41
+ | 🛑 **Unbounded Consumption** | `unbounded_consumption` | Mitigates resource exhaustion and compute DoS attacks |
42
+
43
+ ---
44
+
45
+ ## 📈 Performance & Evaluation
46
+
47
+ Visual comparison of baseline performance versus the trained adapters:
48
+
49
+ ![LLM-Fort Guardrails Accuracy Comparison](benchmark_chart.png)
50
+
51
+ ### Benchmark Results
52
+ Below is the exact accuracy performance measured across our evaluation test suites:
53
+
54
+ | Category | Gemma 4-E4B-it | Qwen 3.5 4B | Qwen3 4B Instruct | llmfort ai guardrail v.1.0 |
55
+ |:---|:---:|:---:|:---:|:---:|
56
+ | **Prompt Injection** | 56.30% | 64.70% | 84.14% | **98.10%** |
57
+ | **PII Extraction** | 84.36% | 75.84% | 78.31% | **95.30%** |
58
+ | **Code Security** | 83.30% | 75.10% | 76.20% | **90.07%** |
59
+ | **Excessive Agency** | 60.90% | 68.80% | 53.80% | **96.50%** |
60
+ | **System Prompt Leakage** | 79.40% | 79.70% | 78.70% | **98.08%** |
61
+ | **Content Safety** | 84.00% | 78.80% | 76.00% | **95.30%** |
62
+ | **Unbounded Consumption** | 63.00% | 63.30% | 55.00% | **99.79%** |
63
+
64
+ ---
65
+
66
+ ## 🗃️ Training & Validation Datasets
67
+
68
+ The adapters were trained and validated on the following dataset references:
69
+
70
+ | Category | Source Datasets / References |
71
+ |:---|:---|
72
+ | **Prompt Injection** | BIPIA, Deepset, Internal 1K Validation |
73
+ | **PII Extraction** | AI4Privacy PII Masking 300k (EN, TR, FR, DE, ES) |
74
+ | **Code Security** | r2vul, securecode_web |
75
+ | **Excessive Agency** | jinjinyien/ToolSafety, minpeter/xlam-function-calling-60k-parsed |
76
+ | **System Prompt Leakage** | S-Labs/prompt-injection-dataset, Synthetic data |
77
+ | **Content Safety** | NVIDIA Nemotron-3.5-Content-Safety-Dataset, Wildguardmix |
78
+ | **Unbounded Consumption** | neuralchemy/prompt-injection-Threat-Matrix, Lakera/mosscap_prompt_injection |
adapter_config.json ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": null,
6
+ "base_model_name_or_path": "Qwen/Qwen3-4B-Instruct-2507",
7
+ "bias": "none",
8
+ "corda_config": null,
9
+ "ensure_weight_tying": false,
10
+ "eva_config": null,
11
+ "exclude_modules": null,
12
+ "fan_in_fan_out": false,
13
+ "inference_mode": true,
14
+ "init_lora_weights": true,
15
+ "layer_replication": null,
16
+ "layers_pattern": null,
17
+ "layers_to_transform": null,
18
+ "loftq_config": {},
19
+ "lora_alpha": 64,
20
+ "lora_bias": false,
21
+ "lora_dropout": 0.05,
22
+ "lora_ga_config": null,
23
+ "megatron_config": null,
24
+ "megatron_core": "megatron.core",
25
+ "modules_to_save": null,
26
+ "peft_type": "LORA",
27
+ "peft_version": "0.19.1",
28
+ "qalora_group_size": 16,
29
+ "r": 32,
30
+ "rank_pattern": {},
31
+ "revision": null,
32
+ "target_modules": [
33
+ "k_proj",
34
+ "up_proj",
35
+ "gate_proj",
36
+ "o_proj",
37
+ "q_proj",
38
+ "v_proj",
39
+ "down_proj"
40
+ ],
41
+ "target_parameters": null,
42
+ "task_type": "CAUSAL_LM",
43
+ "trainable_token_indices": null,
44
+ "use_bdlora": null,
45
+ "use_dora": false,
46
+ "use_qalora": false,
47
+ "use_rslora": false
48
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3d484f6a1671eea9cee15a9c219103cc1b945d0a0756160028380b130b2813bc
3
+ size 264308896
benchmark_chart.png ADDED

Git LFS Details

  • SHA256: 89e11a2379b3f30caf6c57819078571243473d68a6dc5d6ca577db9d0b41d396
  • Pointer size: 131 Bytes
  • Size of remote file: 284 kB
chat_template.jinja ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0].role == 'system' %}
4
+ {{- messages[0].content + '\n\n' }}
5
+ {%- endif %}
6
+ {{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
7
+ {%- for tool in tools %}
8
+ {{- "\n" }}
9
+ {{- tool | tojson }}
10
+ {%- endfor %}
11
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
12
+ {%- else %}
13
+ {%- if messages[0].role == 'system' %}
14
+ {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
15
+ {%- endif %}
16
+ {%- endif %}
17
+ {%- for message in messages %}
18
+ {%- if message.content is string %}
19
+ {%- set content = message.content %}
20
+ {%- else %}
21
+ {%- set content = '' %}
22
+ {%- endif %}
23
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
24
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
25
+ {%- elif message.role == "assistant" %}
26
+ {{- '<|im_start|>' + message.role + '\n' + content }}
27
+ {%- if message.tool_calls %}
28
+ {%- for tool_call in message.tool_calls %}
29
+ {%- if (loop.first and content) or (not loop.first) %}
30
+ {{- '\n' }}
31
+ {%- endif %}
32
+ {%- if tool_call.function %}
33
+ {%- set tool_call = tool_call.function %}
34
+ {%- endif %}
35
+ {{- '<tool_call>\n{"name": "' }}
36
+ {{- tool_call.name }}
37
+ {{- '", "arguments": ' }}
38
+ {%- if tool_call.arguments is string %}
39
+ {{- tool_call.arguments }}
40
+ {%- else %}
41
+ {{- tool_call.arguments | tojson }}
42
+ {%- endif %}
43
+ {{- '}\n</tool_call>' }}
44
+ {%- endfor %}
45
+ {%- endif %}
46
+ {{- '<|im_end|>\n' }}
47
+ {%- elif message.role == "tool" %}
48
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
49
+ {{- '<|im_start|>user' }}
50
+ {%- endif %}
51
+ {{- '\n<tool_response>\n' }}
52
+ {{- content }}
53
+ {{- '\n</tool_response>' }}
54
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
55
+ {{- '<|im_end|>\n' }}
56
+ {%- endif %}
57
+ {%- endif %}
58
+ {%- endfor %}
59
+ {%- if add_generation_prompt %}
60
+ {{- '<|im_start|>assistant\n' }}
61
+ {%- endif %}
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bae3e39d56cfdb7b650cb318344d5c0f071d19fc9868ce086fef0cee78d5e7ff
3
+ size 11422749
tokenizer_config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|im_end|>",
7
+ "errors": "replace",
8
+ "extra_special_tokens": [
9
+ "<|im_start|>",
10
+ "<|im_end|>",
11
+ "<|object_ref_start|>",
12
+ "<|object_ref_end|>",
13
+ "<|box_start|>",
14
+ "<|box_end|>",
15
+ "<|quad_start|>",
16
+ "<|quad_end|>",
17
+ "<|vision_start|>",
18
+ "<|vision_end|>",
19
+ "<|vision_pad|>",
20
+ "<|image_pad|>",
21
+ "<|video_pad|>"
22
+ ],
23
+ "is_local": false,
24
+ "local_files_only": false,
25
+ "model_max_length": 1010000,
26
+ "pad_token": "<|endoftext|>",
27
+ "split_special_tokens": false,
28
+ "tokenizer_class": "Qwen2Tokenizer",
29
+ "unk_token": null
30
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f2693e5312373d3a721273bca7b3606e8293d8d8e64a6e0b629aa4a3d42031fe
3
+ size 5265
training_config.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_id": "Qwen/Qwen3-4B-Instruct-2507",
3
+ "dataset_dir": "/content/drive/MyDrive/pii_v10_training/processed_v10",
4
+ "run_dir": "/content/drive/MyDrive/pii_v10_training/runs/pii_v10_Qwen__Qwen3-4B-Instruct-2507_qlora_20260614_123600",
5
+ "max_seq_length": 2048,
6
+ "max_new_tokens": 384,
7
+ "fixed_eval_size": 100,
8
+ "gold_clean_eval_limit": 200,
9
+ "source_stress_eval_limit": 200,
10
+ "num_train_epochs": 1.0,
11
+ "learning_rate": 0.0001,
12
+ "lora_r": 32,
13
+ "lora_alpha": 64,
14
+ "lora_dropout": 0.05,
15
+ "per_device_train_batch_size": 4,
16
+ "gradient_accumulation_steps": 4,
17
+ "seed": 42,
18
+ "auto_disconnect_runtime": true,
19
+ "run_gradient_sanity_check": true,
20
+ "run_mini_overfit": true,
21
+ "mini_overfit_sample_size": 20,
22
+ "mini_overfit_max_steps": 80,
23
+ "mini_overfit_min_strict_schema": 0.9,
24
+ "mini_overfit_min_exact_match": 0.8,
25
+ "all_label_prompt_ratio": 0.25,
26
+ "adapter_effect_raw_same_alarm_rate": 0.8
27
+ }