Text Classification
MLX
Safetensors
Chinese
English
tinyguard
safety
guardrail
prompt-injection
security
Instructions to use QuanxinLi/TinyGuard-Injection with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use QuanxinLi/TinyGuard-Injection with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download QuanxinLi/TinyGuard-Injection --local-dir TinyGuard-Injection
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
File size: 2,586 Bytes
3a19248 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | ---
license: apache-2.0
language:
- zh
- en
tags:
- safety
- guardrail
- prompt-injection
- security
- text-classification
- mlx
metrics:
- f1
- accuracy
---
# TinyGuard-Injection (base + fine-tuned)
**Bilingual prompt-injection detector (incl. indirect injection) trained completely from scratch** · 9.1M parameters · MLX/Metal · Apache-2.0 (code) · fully synthetic training data
[中文说明](MODEL_CARD-injections.zh.md)
## Model description
A 3-way guardrail deployed at LLM-app input gates and RAG retrieval gates: `benign / direct injection / indirect injection`. Complements Meta Llama Prompt Guard 2 (22M/86M, **no Chinese support**): this model is trained bilingual with equal weight.
- Backbone: shared TinyGuard-Encoder (same pretrained base as TinyGuard-Command)
- Fine-tune: 12,330 bilingual labeled examples across six carriers (code & collaboration platforms, emails & web pages, long RAG chunks, tickets & customer-service dialogs, benign hard negatives, hidden-character & encoded payloads), with "minimal-difference pairs" and anti-overrefusal design
## Results (held-out data only, never seen in training)
| Benchmark | Metric | Value |
|---|---|---|
| Validation set, 616 rows | acc / macro-F1 | **99.0% / 0.990** |
| Adversarial set, 40 rows (zero-width chars / JSON rules / Japanese carriers / quoted disclaimers) | intervention recall / precision / F1 | 75% / 88% / 0.81 |
Reference: Llama Prompt Guard 2-86M reports EN injection F1 ≈ 0.98 with no Chinese. This model provides first-tier Chinese capability; its English adversarial numbers are below Meta's home turf (expected at 9.1M vs 86M).
## Usage
Weights: [`QuanxinLi/TinyGuard-Injection`](https://huggingface.co/QuanxinLi/TinyGuard-Injection) ·
Code & training pipeline: [`Quanxin-Lee/TinyGuard`](https://github.com/Quanxin-Lee/TinyGuard)
```python
# quickstart (transformers/MLX dual format) — see the GitHub repo for the full walkthrough
```
## Limitations
- 5/40 misses on the adversarial set: JSON-encoded rules, URL-less "prioritize this" phrasing, direct asks inside authorized framing (red-team wording) — all weak-signal forms.
- English training volume is lower than Chinese; English adversarial generalization needs strengthening.
- Recommended to stack with a regex layer: this model handles semantics, regex handles known fingerprints.
## Training details & data statement
All data is synthetic/hand-written — no real user data. The full training pipeline, four audit scripts (three deep-scan rounds) and every dataset ship with the repository.
|