An AI-powered causal inference platform that transforms natural-language business questions into statistically valid causal estimates — no statistics PhD required.
** New to CausalBridge?** Check out VERSION_2.0.md for a quick start guide, new features, and user-friendly examples!
- Overview
- Features
- Screenshots
- Project Structure
- Installation
- API Key Setup
- Running the Project
- Using the Dashboard
- API Endpoints
- Supported Causal Methods
- Configuration Reference
- Roadmap
CausalBridge allows anyone to perform causal inference analysis by asking questions in plain English:
- Upload your dataset (CSV, Excel, JSON, or Parquet)
- Ask a question like "Does a discount cause higher customer satisfaction?"
- The AI (Groq/Gemini) identifies what to test and what to control for
- The statistical engine runs a peer-reviewed causal method
- You get a clear result: effect size, confidence interval, p-value, and plain-English interpretation
- Natural Language Questions — Ask in English, get scientific answers
- AI-Powered Parsing — Groq (LLaMA 3.3 70B) or Google Gemini understands your question
- 4 Causal Methods — Backdoor Adjustment, Propensity Score Matching, Difference-in-Differences, Instrumental Variables
- Interactive Dashboard — Upload data, run analysis, view charts — all in the browser
- RESTful API — Integrate CausalBridge into any existing system
- Data Quality Checks — Automatic validation before analysis runs
- Multi-format Support — CSV, Excel (.xlsx), JSON, Parquet
Drop in any CSV or Excel file. CausalBridge instantly reads your columns and prepares them for analysis.
No SQL. No code. Just type what you want to know — like "Does overtime cause employees to quit?"
CausalBridge doesn't just say "yes" or "no". It tells you by how much — a statistically validated percentage change with a 95% confidence interval and p-value.
Example: "Overtime increases the probability of attrition by 18.3 percentage points (p < 0.001, 95% CI: [12.1%, 24.5%])"
📁 More screenshots are stored in the
assets/folder to understand this part better .
Every result comes with the full statistical output: effect size (ATE), confidence interval, standard error, sample sizes, and a plain-English interpretation so anyone can understand it.
CausalBridge/
├── src/
│ ├── main.py # FastAPI application entry point
│ ├── api/
│ │ ├── routes.py # Core API endpoints (/analyze, /health)
│ │ ├── upload_routes.py # File upload endpoints
│ │ ├── visualization_routes.py # Chart/visualization endpoints
│ │ └── dependencies.py # Dependency injection
│ ├── services/
│ │ ├── nlp_service_gemini.py # AI question parsing (Groq + Gemini)
│ │ ├── nlp_service.py # Fallback rule-based parser
│ │ ├── causal_inference_service.py # Statistical estimation engine
│ │ ├── advanced_causal_methods.py # DiD, IV, PSM implementations
│ │ ├── data_quality.py # Pre-analysis data validation
│ │ └── validation_service.py # Request validation
│ ├── models/
│ │ ├── request_models.py # Pydantic request schemas
│ │ └── response_models.py # Pydantic response schemas
│ ├── core/
│ │ ├── config.py # App settings (reads from .env)
│ │ └── exceptions.py # Custom exceptions
│ └── utils/
│ └── __init__.py
├── static/
│ └── dashboard.html # Web dashboard (single-page app)
├── uploads/ # Uploaded dataset files (auto-created)
├── tests/ # Test suite
├── .env # Environment variables (API keys, settings)
├── requirements.txt # Python dependencies
├── start_server.ps1 # One-click server start (PowerShell)
└── README.md # This file
- Python 3.10 or higher
- PowerShell (Windows) or Bash (Mac/Linux)
1. Navigate to the project folder:
cd "d:\DESKTOP\Projects\CausalBridge\CausalBridge\CausalBridge"2. Create a virtual environment:
python -m venv .venv3. Activate the virtual environment:
# Windows (PowerShell)
.venv\Scripts\Activate.ps1
# Windows (Command Prompt)
.venv\Scripts\activate.bat
# Mac / Linux
source .venv/bin/activate4. Install all dependencies:
pip install -r requirements.txtCausalBridge uses a free AI service to understand your natural language questions.
You need one of the following free API keys:
Free. No credit card. 14,400 requests/day.
- Go to https://console.groq.com
- Sign up with Google or GitHub (no credit card needed)
- Click API Keys in the left sidebar → Create API Key
- Copy the key (starts with
gsk_...) - Open the
.envfile and paste it:
GROQ_API_KEY=gsk_your_key_hereFree. Requires Google account. 1,500 requests/day.
- Go to https://aistudio.google.com/app/apikey
- Sign in with your Google account
- Click Create API Key
- Copy the key (starts with
AIzaSy...) - Open the
.envfile and paste it:
GEMINI_API_KEY=AIzaSy_your_key_hereYou ask a question
↓
Gemini key set? → Uses Gemini
↓ (if not set or fails)
Groq key set? → Uses Groq
↓ (if not set or fails)
Manual mode → You specify Treatment & Outcome manually in the dashboard
Note: If neither key is set, the app still works — you just manually select the Treatment and Outcome columns in the dashboard instead of typing a plain-English question.
Make sure your virtual environment is activated, then run:
.\start_server.ps1uvicorn src.main:app --reloaduvicorn src.main:app --host 0.0.0.0 --port 8000 --reloadOnce started, you will see:
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
Open your browser and go to:
| Page | URL |
|---|---|
| 🖥️ Main Dashboard | http://127.0.0.1:8000/dashboard |
| 📖 API Docs (Swagger) | http://127.0.0.1:8000/docs |
| 📄 API Docs (ReDoc) | http://127.0.0.1:8000/redoc |
- Upload your CSV/Excel file using the Upload section
- Type your question in plain English, e.g.:
- "Does having a gold membership cause higher satisfaction?"
- "Does overtime work lead to employee attrition?"
- "Does applying a discount increase the number of items purchased?"
- (Optional) Manually select Treatment, Outcome, and Method if you prefer
- Click Analyze and wait a few seconds
- View the results: effect size, confidence interval, p-value, and interpretation
Run a causal analysis. Explaining how the API takes the questions and understands it.
Request:
{
"question": "Does overtime cause attrition?",
"dataset_uri": "uploads/your_file.csv",
"schema": {
"treatment": "OverTime",
"outcome": "Attrition",
"confounders": ["Age", "MonthlyIncome", "JobSatisfaction"]
},
"params": {
"method": "backdoor",
"confidence_level": 0.95
}
}Response:
{
"success": true,
"plan": {
"treatment": "OverTime",
"outcome": "Attrition",
"method": "backdoor",
"llm_used": "Groq (LLaMA 3.3 70B)"
},
"results": {
"ate": 0.18,
"confidence_interval": [0.12, 0.24],
"p_value": 0.001,
"n_treated": 416,
"n_control": 1054
},
"message": "Analysis completed successfully"
}Upload a dataset file (CSV, Excel, JSON, Parquet).
Get the list of column names from an uploaded file.
Basic health check.
API health check with version info.
| Method | Flag | Best For |
|---|---|---|
| Backdoor Adjustment | backdoor |
Continuous treatments, regression-based control |
| Propensity Score Matching | propensity_score_matching |
Binary treatments (Yes/No, 0/1) |
| Difference-in-Differences | difference_in_differences |
Before/after policy comparisons |
| Instrumental Variables | instrumental_variable |
When hidden confounders are suspected |
The AI automatically recommends the best method based on your data. You can also override it manually.
All settings live in the .env file at the project root:
| Variable | Default | Description |
|---|---|---|
APP_NAME |
CausalBridge |
Application name |
DEBUG |
True |
Enable debug logging |
LLM_PROVIDER |
Groq |
Active AI provider (Groq or Gemini) |
GROQ_API_KEY |
(empty) | Your Groq API key — get free at https://console.groq.com |
GEMINI_API_KEY |
(empty) | Your Gemini API key — get free at https://aistudio.google.com/app/apikey |
DEFAULT_METHOD |
backdoor |
Default causal inference method |
SEED |
42 |
Random seed for reproducibility |
CONFIDENCE_LEVEL |
0.95 |
Statistical confidence level (95%) |
MAX_DATASET_SIZE_MB |
100 |
Maximum allowed file upload size |
- AI question parsing — Gemini ✅ and Groq ✅
- Backdoor Adjustment ✅
- Propensity Score Matching ✅
- Difference-in-Differences ✅
- Instrumental Variables ✅
- Interactive web dashboard ✅
- Multi-format file support (CSV, Excel, JSON, Parquet) ✅
- Data quality validation ✅
- PDF report generation
- Authentication and rate limiting
- Batch analysis (multiple questions at once)
- Database integration for result history
- Async processing for very large datasets
This project is licensed under the MIT License.
- Natural Language Processing: Convert business questions into structured plans for causal analysis
- Multiple Causal Methods: Support for backdoor adjustment, propensity score matching, and more
- Statistical Validation: Confidence intervals, p-values, and bootstrap estimates
- RESTful API: Easy integration with existing systems
- Comprehensive Validation: Input validation and error handling
CausalBridge/
├── src/
│ ├── api/
│ │ ├── __init__.py
│ │ ├── routes.py # API endpoints
│ │ └── dependencies.py # Dependency injection
│ ├── services/
│ │ ├── __init__.py
│ │ ├── nlp_service.py # Question parsing & plan generation
│ │ ├── causal_inference_service.py # Statistical estimation
│ │ └── validation_service.py # Request validation
│ ├── models/
│ │ ├── __init__.py
│ │ ├── request_models.py # Pydantic request models
│ │ └── response_models.py # Pydantic response models
│ ├── core/
│ │ ├── __init__.py
│ │ ├── config.py # Application settings
│ │ └── exceptions.py # Custom exceptions
│ ├── utils/
│ │ ├── __init__.py
│ │ └── helpers.py # Helper functions
│ └── main.py # FastAPI application
├── tests/ # Test suite
├── requirements.txt # Python dependencies
├── pyproject.toml # Project metadata
└── README.md # This file
- Clone the repository:
git clone <repository-url>
cd CausalBridge- Create a virtual environment (recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Configure environment variables:
Create a
.envfile in the project root:
OPENAI_API_KEY=your_api_key_here
DEBUG=True# Development mode with auto-reload
uvicorn src.main:app --reload
# Production mode
uvicorn src.main:app --host 0.0.0.0 --port 8000The API will be available at http://localhost:8000
Interactive API documentation is available at:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
curl -X POST "http://localhost:8000/api/v1/analyze" \
-H "Content-Type: application/json" \
-d '{
"question": "What is the effect of education on income?",
"dataset_uri": "data/income_data.csv",
"schema": {
"treatment": "education_years",
"outcome": "annual_income",
"confounders": ["age", "gender", "experience"]
},
"params": {
"method": "backdoor",
"confidence_level": 0.95
}
}'{
"success": true,
"plan": {
"treatment": "education_years",
"outcome": "annual_income",
"confounders": ["age", "gender", "experience"],
"method": "backdoor",
"effect_type": "ATE"
},
"results": {
"ate": 5000.0,
"confidence_interval": [4500.0, 5500.0],
"p_value": 0.001,
"n_treated": 500,
"n_control": 500,
"standard_error": 250.0
},
"message": "Analysis completed successfully"
}Perform causal analysis on a dataset based on a natural language question.
Request Body:
question(string): Natural language causal questiondataset_uri(string): Path to dataset (CSV, JSON, or Parquet)schema(object): Dataset schema with treatment, outcome, and confoundersparams(object, optional): Additional parameters like method and confidence level
Response:
success(boolean): Whether the analysis succeededplan(object): Generated analysis planresults(object): Statistical results including ATE, CI, p-valuemessage(string): Status message
Health check endpoint
API health check endpoint
- Backdoor Adjustment: Default method using regression with confounders
- Propensity Score Matching: Match treated and control units
- Instrumental Variables: (Placeholder for future implementation)
- Regression Discontinuity: (Placeholder for future implementation)
Configuration is managed through the src/core/config.py file and can be overridden with environment variables:
APP_NAME: Application name (default: "CausalBridge")DEBUG: Debug mode (default: True)OPENAI_API_KEY: OpenAI API key for LLM featuresDEFAULT_METHOD: Default causal inference method (default: "backdoor")SEED: Random seed for reproducibility (default: 42)CONFIDENCE_LEVEL: Default confidence level (default: 0.95)MAX_DATASET_SIZE_MB: Maximum dataset size in MB (default: 100)
pytest tests/# Format code
black src/
# Lint code
flake8 src/- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- LLM integration for advanced question parsing (Gemini AI ✅)
- Support for more causal inference methods (PSM, DiD, IV ✅)
- Data visualization endpoints (✅)
- Multi-format file support (CSV, Excel, JSON, Parquet ✅)
- PDF report generation
- Authentication and rate limiting
- Database integration for result storage
- Async processing for large datasets
- Batch analysis (multiple questions at once)
This project is licensed under the MIT License.



