Gemma-3-4b-it LoRA for Prompt Injection Defense
2 min readupdated
This QLoRA fine-tune of the google/gemma-3-4b-it base model serves as a security layer to check incoming requests for AI agents and crypto wallets. The model classifies incoming text into two categories: safe request (SAFE) or injection attempt (INJECTION). Built for the White Circle Halo contest, this solution continues the AgentShield concept. It is designed for AI developers who need to filter malicious instructions before execution.
Key features
- Fine-tuned using QLoRA (r=16, alpha=32, 4-bit base in NF4, and bf16 computations)
- Trained on the deepset/prompt-injections dataset for 3 epochs
- Significant classification accuracy boost compared to the original base model
- Zero false positive rate (FPR 0.000) on the test split
What you can do
- Integrate the classifier as a security shield before executing your AI agent's instructions
- Use the model alongside deterministic filters for secure Agent ID wallet operations
- Test your own system's resistance to prompt injections using the ready-to-use checkpoint
Example
Use the model for preemptive input text filtering in your agent pipeline: if the classifier returns INJECTION, the request is blocked before reaching core tools.
Read more
DetailsTest set metrics (n=116): accuracy increased from 0.783 to 0.966, F1-score from 0.757 to 0.966.
Hardware requirements: training ran on a single NVIDIA A10 GPU with 24GB VRAM.
Limitations: this is a demonstration run on a small dataset; pairing it with strict software rules is recommended.










Comments