chrisjcc's picture
Update README.md
7001442
|
Raw
History Blame Contribute Delete
9.99 kB
---
title: Fraud Model Explainability Assistant
emoji: πŸ‘€
colorFrom: gray
colorTo: indigo
sdk: docker
sdk_version: 7.1.0
secrets:
- GITHUB_TOKEN
app_file: app.py
pinned: false
license: apache-2.0
short_description: Fraud Model Explainability Assistant using Strands Agents
---
# πŸ” Fraud Model Explainability Assistant
An AI-powered assistant built with **Amazon Strands Agents SDK** that helps fraud analysts, data scientists, and executives understand fraud model decisions and ensure fair lending compliance.
## 🎯 Use Case
**Target Role:** VP, Fraud Model Data Science
**Industry:** Credit Card / Consumer Finance (e.g., Synchrony Financial)
This tool addresses critical needs in fraud model governance:
- **Executive Communication**: Translate complex model outputs for C-suite presentations
- **Fair Lending Compliance**: Document model decisions for regulatory examinations
- **Analyst Efficiency**: Reduce time spent answering "why was this flagged?" questions
- **Audit Readiness**: Provide consistent, thorough explanations for model decisions
## ✨ Features
| Tool | Description |
|------|-------------|
| `get_application_summary` | Basic application info, fraud score, and decision |
| `explain_fraud_score` | SHAP-style feature attribution showing why an app was flagged |
| `compare_to_population` | Statistical comparison to approved/denied populations |
| `check_fair_lending_flags` | Fair lending compliance review and documentation |
| `get_identity_network` | Analyze linked applications (device, phone, address, etc.) |
| `get_model_performance` | Model metrics, KPIs, and financial impact |
## πŸš€ Quick Start
### Installation
```bash
# Clone or download the repository
cd fraud_explainability_agent
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
```
## Environment Variables
Required environment variables:
```
OPENAI_API_KEY=your-openai-key
CONFLUENCE_URL=https://your-domain.atlassian.net/wiki
CONFLUENCE_EMAIL=your-email@example.com
CONFLUENCE_API_TOKEN=your-api-token
### Configuration
Set your OpenAI API key:
```bash
export OPENAI_API_KEY="your-api-key-here"
```
Or use AWS credentials for Amazon Bedrock (default):
```bash
export AWS_ACCESS_KEY_ID="your-access-key"
export AWS_SECRET_ACCESS_KEY="your-secret-key"
export AWS_DEFAULT_REGION="us-west-2"
```
### Run the App
```bash
python app.py
```
Open http://localhost:7860 in your browser.
## πŸ’¬ Example Conversations
### Basic Investigation
> **User:** "Why was application APP-78432 flagged as high risk?"
>
> **Agent:** *[calls get_application_summary, explain_fraud_score]*
>
> Returns detailed breakdown of the fraud score with top contributing factors.
### Executive Briefing
> **User:** "I need to present APP-99999 to the CCO. Give me a complete risk summary with compliance review."
>
> **Agent:** *[calls multiple tools: summary, explanation, population comparison, fair lending check]*
>
> Returns comprehensive analysis suitable for executive presentation.
### Compliance Documentation
> **User:** "Check fair lending compliance for application APP-55555"
>
> **Agent:** *[calls check_fair_lending_flags]*
>
> Returns protected class proxy analysis, disparate impact testing results, and adverse action reason codes.
### Synthetic ID Investigation
> **User:** "Show me the identity network analysis for APP-78432"
>
> **Agent:** *[calls get_identity_network]*
>
> Returns linked applications, connection types, network risk score, and ring pattern detection.
## πŸ—οΈ Architecture
- **Backend**: FastAPI + uvicorn
- **Agent Framework**: Strands Agents
- **LLM**: OpenAI GPT-4o
- **Vector Store**: ChromaDB with HuggingFace embeddings
- **Scheduling**: APScheduler for daily data refresh
```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Gradio Web Interface β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Strands Agent β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ System Prompt β”‚ β”‚
β”‚ β”‚ "You are a Fraud Model Explainability Assistant..."β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚ β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ Tools β”‚ β”‚
β”‚ β”‚ β€’ get_application_summary β”‚ β”‚
β”‚ β”‚ β€’ explain_fraud_score β”‚ β”‚
β”‚ β”‚ β€’ compare_to_population β”‚ β”‚
β”‚ β”‚ β€’ check_fair_lending_flags β”‚ β”‚
β”‚ β”‚ β€’ get_identity_network β”‚ β”‚
β”‚ β”‚ β€’ get_model_performance β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ LLM (GPT-4o / Bedrock) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```
The app will be available at `http://localhost:7860`
## API Endpoints
- `GET /` - Main UI
- `POST /api/ask` - Submit a question
- `GET /api/metrics` - Get performance metrics
- `GET /api/health` - Health check
## πŸ”§ Production Integration
In production, the mock data generators would be replaced with real integrations:
```python
@tool
def explain_fraud_score(application_id: str) -> str:
"""Get SHAP explanation for fraud score."""
# Production implementation:
# 1. Query feature store for application features
features = feature_store.get_features(application_id)
# 2. Get SHAP values from model serving
shap_values = model_service.explain(application_id)
# 3. Query data warehouse for context
app_data = snowflake.query(f"SELECT * FROM applications WHERE id = '{application_id}'")
# 4. Format and return explanation
return format_explanation(features, shap_values, app_data)
```
### Suggested Integrations
| System | Purpose |
|--------|---------|
| **Snowflake / Redshift** | Application data, fraud outcomes |
| **Feature Store** (Feast, Tecton) | Real-time feature retrieval |
| **MLflow / SageMaker** | Model registry, SHAP computation |
| **Elasticsearch** | Identity linkage network queries |
| **Compliance DB** | Fair lending test results, documentation |
## πŸ“Š Mock Data
The demo generates realistic mock data based on the application ID (deterministic seeding). This allows for:
- Consistent demos with specific application IDs
- Realistic distribution of risk levels
- Representative feature values for high/low risk cases
**Sample High-Risk Features:**
- SSN/Credit age mismatch: 70-95%
- Device velocity: 5-15 applications in 30 days
- Address type: CMRA, PO Box, Vacant
- Synthetic ID score: 75-98%
**Sample Low-Risk Features:**
- SSN/Credit age mismatch: 0-20%
- Device velocity: 1-2 applications
- Address type: Residential
- Synthetic ID score: 5-25%
## πŸ›‘οΈ Compliance Considerations
This tool is designed with regulatory compliance in mind:
- **ECOA Compliance**: Fair lending checks for protected class proxies
- **SR 11-7**: Model risk management documentation support
- **Adverse Action**: Automated reason code generation
- **Audit Trail**: Consistent, reproducible explanations
## πŸ“ Project Structure
```
fraud_explainability_agent/
β”œβ”€β”€ app.py # Main application with tools and Gradio UI
β”œβ”€β”€ requirements.txt # Python dependencies
└── README.md # This file
```
## πŸ§ͺ Demo Mode
Run demo queries without the web interface:
```bash
python app.py --demo
```
## πŸ“š Resources
- [Strands Agents Documentation](https://strandsagents.com)
- [Strands Agents GitHub](https://github.com/strands-agents/sdk-python)
- [SHAP (SHapley Additive exPlanations)](https://shap.readthedocs.io/)
- [SR 11-7: Guidance on Model Risk Management](https://www.federalreserve.gov/supervisionreg/srletters/sr1107.htm)
## πŸ“„ License
MIT License
---
*Built for fraud model data science teams who need to explain complex model decisions to stakeholders across the organization.*
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference