MCApple Guard v1.0 Flash
source code and artifacts of prompt injection detector
2 min readupdated
This repository provides the source code and public model artifacts for detecting prompt injections, jailbreaks, and system instruction overrides in text. The tool classifies input text as either safe or an attack without executing the submitted string. It relies on a ready-to-use ONNX artifact for inference, a standalone native training checkpoint based on DeBERTa-v2, and an included FastAPI service. This solution is useful for developers of AI agents and system gateways to filter incoming requests before processing.
Key features
- Includes a ready-to-use FastAPI service for deploying a local detection API
- Supports fast local CPU ONNX inference via prediction scripts
- Contains a portable trainer for fine-tuning and export with parity checking
- Supports a sliding text processing window with a limit of up to 3584 tokens
What you can do
- Launch your own local attack detection API service via Uvicorn
- Screen text for prompt injection attempts using the ONNX prediction script
- Perform local fine-tuning of the model on your own annotated JSONL datasets
- Export trained checkpoints to ONNX format with result parity verification
Example
Running the local FastAPI service via the command line with API key generation:
export API_KEY="$(python -c 'import secrets; print(secrets.token_urlsafe(32))')"
python -m uvicorn app:app --host 127.0.0.1 --port 8000Read more
DetailsClassification threshold: 0.067598
Architecture: DeBERTa-v2 with six encoder layers
Limitations: maximum text length of 32768 characters, up to 16 windows of 256 tokens
Requirements: Python 3.12, PyTorch 2.8+, Transformers 4.57.6










Comments