A comprehensive AI safety platform that provides real-time risk analysis of AI-generated content using machine learning and heuristic-based detection.
This system analyzes AI-generated text for multiple risk factors:
- Hallucination Risk: Detects potentially false or unverified information
- Bias Risk: Identifies biased language or perspectives
- Toxicity Risk: Flags harmful or offensive content
- PII Leak: Detects personally identifiable information
- Fraud Risk: Identifies suspicious or fraudulent patterns
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β React βββββββΆβ Node.js βββββββΆβ FastAPI β
β Frontend ββββββββ Backend ββββββββ ML Service β
β (Port 5173)β β (Port 3000) β β (Port 8000) β
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β
βΌ
ββββββββββββββββ
β OpenAI β
β GPT-4o β
ββββββββββββββββ
- User enters a prompt in the React frontend
- Frontend sends prompt to Node.js backend
- Backend calls OpenAI API to generate response
- Backend sends AI response to ML Service for risk analysis
- ML Service returns comprehensive risk flags
- Backend combines AI response + risk flags
- Frontend displays response with risk indicators
- Node.js 22.16.0+
- Python 3.12+
- OpenAI API Key
- Clone the repository
git clone https://github.com/jiya2401/AI-RISK-MITIGATION-SYSTEM.git
cd AI-RISK-MITIGATION-SYSTEM- Install Python dependencies
pip install -r requirements.txt- Install Backend dependencies
cd mitigation/BaatGPT/Backend
npm install- Install Frontend dependencies
cd ../frontend
npm install- Set up environment variables
Create a .env file in the Backend directory:
OPENAI_API_KEY=your_openai_api_key_here
OPENAI_MODEL=gpt-4o-mini
ML_SERVICE_URL=http://localhost:8000
PORT=3000
You need to start three services:
cd mitigation/BaatGPT/Backend
python3 ml_service_fastapi.py
# Service runs on http://localhost:8000cd mitigation/BaatGPT/Backend
npm start
# Or: node server.js
# Service runs on http://localhost:3000cd mitigation/BaatGPT/frontend
npm run dev
# Service runs on http://localhost:5173Now open http://localhost:5173 in your browser!
Detects absolutist language patterns that may indicate false certainty:
- Keywords: "definitely", "absolutely", "guaranteed", "without doubt"
- High confidence statements without qualifiers
Identifies potentially biased language:
- Keywords: "always", "never", "all", "none", "everyone"
- Absolutist generalizations
Flags harmful or offensive content:
- Keywords: "hate", "stupid", "idiot", "terrible"
- Negative and aggressive language
Detects suspicious patterns:
- Keywords: "guaranteed", "free money", "limited time", "act now"
- Urgency and pressure tactics
Detects personally identifiable information:
- Email addresses
- Phone numbers
- Social Security Numbers
- Credit card numbers
- Physical addresses
Analyzes text for all risk factors.
Request:
{
"text": "Your AI-generated content here"
}Response:
{
"hallucination_risk": "MEDIUM",
"bias_risk": "LOW",
"toxicity_risk": "LOW",
"pii_leak": false,
"fraud_risk": "LOW",
"confidence_score": 0.75,
"ml_prediction": "medium risk",
"processing_time_ms": 12.34
}Health check endpoint.
Response:
{
"status": "healthy",
"model_loaded": true,
"device": "cpu",
"timestamp": 1767677556.389
}- Real-time Risk Analysis: See risk flags as they're generated
- Professional UI: Clean, enterprise-grade design
- Dark/Light Theme: Seamless theme switching
- Mobile Responsive: Works on all devices
- Streaming Support: Optional streaming mode for faster responses
- Risk Visualization: Color-coded risk indicators (π’ Low, π‘ Medium, π΄ High)
- ML service runs locally - no data sent to third parties
- PII detection prevents accidental data leaks
- Timeout protection prevents service blocking
- Graceful fallback when ML service unavailable
- Fine-tune MedBERT model on domain-specific data
- Add more sophisticated NLP analysis
- Implement user feedback loop for model improvement
- Add batch analysis API
- Export risk reports as PDF
- Add custom risk threshold configuration
- Implement advanced toxicity detection (Perspective API)
- Add multilingual support
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.
- MedBERT model by Emily Alsentzer
- FastAPI framework
- React and Vite
- OpenAI GPT-4o-mini
- Transformers library by Hugging Face