A framework that detects the type of bias in your prompt, then automatically routes it to the model best equipped to respond fairly — every single time.
SafetyRouter intercepts your prompt, identifies its bias profile locally, and forwards it to the model with the highest benchmark accuracy for that category.
Routing decisions are backed by benchmark accuracy scores. The table is fully configurable — bring your own mappings.
| Bias Category | Routed To | Accuracy |
|---|---|---|
| sexual_orientation | GPT-4 | |
| gender | GPT-4 | |
| race | Claude | |
| nationality | GPT-4 | |
| disability | Claude | |
| religion | Claude | |
| age | Mixtral | |
| socioeconomic_status | Gemini | |
| physical_appearance | Mixtral |
Python SDK, CLI, or drop it behind an HTTP server. Pick what fits your stack.
import asyncio from safetyrouter import SafetyRouter router = SafetyRouter() # reads API keys from environment async def main(): response = await router.route("Should women be paid less than men?") print(response.bias_category) # "gender" print(response.selected_model) # "gpt4" print(response.confidence) # 0.92 print(response.content) # unbiased answer from GPT-4 # Dry run — classify only, zero API cost async def inspect(): result = await router.route("text", execute=False) print(result.bias_category) # see routing without spending tokens # Streaming async for token in router.stream("Is age discrimination legal?"): print(token, end="", flush=True) asyncio.run(main())
# First-time setup — installs Ollama, starts it, pulls classifier model $ safetyrouter setup SafetyRouter Setup ────────────────────────────── [1/3] Checking Ollama installation... ✓ Ollama installed. [2/3] Checking Ollama is running... ✓ Ollama is running. [3/3] Pulling classifier model (gemma3n:e2b)... ✓ gemma3n:e2b is ready. ✓ Setup complete! SafetyRouter is ready to use. # Route a prompt — bias classified + best model called $ safetyrouter route "Is discrimination based on religion acceptable?" Bias Category : religion Confidence : 87% Routed to : claude Model Accuracy: 84% # Classify only — free, no API call $ safetyrouter classify "Women are worse drivers than men." Top category : gender Confidence : 91% Would route to: gpt4 # Inspect the routing table $ safetyrouter inspect # Stream the response $ safetyrouter route "text" --stream
# Start the server $ safetyrouter serve --port 8000 # Route a prompt $ curl -X POST http://localhost:8000/route \ -H "Content-Type: application/json" \ -d '{"text": "Should people be judged by their race?"}' # Classify only (no model call) $ curl -X POST http://localhost:8000/classify \ -H "Content-Type: application/json" \ -d '{"text": "Women shouldn'\''t vote."}' # Inspect routing table $ curl http://localhost:8000/routing-table # Interactive docs $ open http://localhost:8000/docs
from safetyrouter import SafetyRouter from safetyrouter.providers import OllamaProvider # Route everything to local Ollama models — no API keys needed router = SafetyRouter( providers={ "gpt4": OllamaProvider(model="llama3.2"), "claude": OllamaProvider(model="llama3.2"), "gemini": OllamaProvider(model="mistral"), "mixtral":OllamaProvider(model="mixtral"), } ) # Custom routing overrides from safetyrouter import SafetyRouterConfig config = SafetyRouterConfig( custom_routing={"gender": "claude", "religion": "gemini"} ) router = SafetyRouter(config=config)
Everything you need to integrate unbiased LLM responses into your app.
All providers are optional — only install what you use.
safetyrouter setup handles everything —
no manual Ollama configuration needed.
SafetyRouter Setup ────────────────────────────── [1/3] Checking Ollama installation... ✓ Ollama installed. [2/3] Checking Ollama is running... ✓ Ollama is running. [3/3] Pulling classifier model (gemma3n:e2b)... ✓ gemma3n:e2b is ready. ✓ Setup complete! SafetyRouter is ready. Try it: safetyrouter classify "text here" safetyrouter route "your prompt"