Provider-agnostic A/B testing for LLM systems
Project description
modelab
Provider-agnostic A/B testing for LLM systems in production.
Two components:
- Python SDK — zero-dependency library for assignment, tracking, and evaluation
- Server + Dashboard — self-hosted FastAPI + React app for visualization (Docker Compose)
Quick Start
SDK (local development)
pip install modelab
import modelab
from modelab import Flag, Variant, EvalContext
# Initialize — point to the modelab server
modelab.init(
server="http://localhost:8100",
flags=[
Flag(
name="summarizer_v2",
variants=[
Variant("control", weight=50, config={"model": "gpt-3.5-turbo", "prompt": "Summarize: {input}"}),
Variant("treatment", weight=50, config={"model": "gpt-4", "prompt": "Concisely summarize: {input}"}),
],
rollout_pct=100,
),
],
)
# Assign a variant
ctx = EvalContext(user_id="user_123", session_id="abc")
assignment = modelab.assign("summarizer_v2", ctx)
if assignment is None:
# Outside rollout — use default behavior
response = call_llm(model="gpt-3.5-turbo", prompt=text)
else:
# In experiment — use assigned variant config
response = call_llm(
model=assignment.config["model"],
prompt=assignment.config["prompt"].format(input=text),
)
assignment.record(response, cost=0.013)
assignment.mark_success()
# Evaluate results
results = modelab.evaluate("summarizer_v2")
print(results)
Self-Hosted Server + Dashboard
docker compose up
This starts:
- PostgreSQL on port 5432
- modelab server + dashboard on port 8100
Concepts
Flags
An experiment with one or more variants and a rollout percentage (0-100%).
Variants
Each variant has a name, weight (for traffic splitting), and a config dict you use to parameterize your LLM calls.
Assignment
Deterministic — the same (flag_name, user_id) always maps to the same variant. Uses MD5 hashing into 10,000 buckets for 0.01% rollout granularity.
Recording
Use assignment.record(response) to capture execution metrics. Token counts are automatically extracted from the response object via duck-typing (supports OpenAI and Anthropic response formats). Cost, latency, error, and arbitrary metadata can be passed as keyword arguments:
assignment.record(response, cost=0.013, latency_ms=250.0, model="gpt-4o")
You can also record without a response object:
assignment.record(input_tokens=50, output_tokens=100, cost=0.01)
Events
Mark assignments as success/failure or record custom events (e.g., "copied", "thumbs_up").
Evaluation
modelab.evaluate(flag_name) returns per-variant metrics: success rate, avg latency, avg cost, token usage, and custom event counts.
Server API
Ingestion (from SDK)
POST /api/v1/ingest/assignments (batch)
POST /api/v1/ingest/executions (batch)
POST /api/v1/ingest/events (batch)
Dashboard API
GET /api/v1/flags — list flags with summary stats
GET /api/v1/flags/{name} — detailed per-variant evaluation
GET /api/v1/flags/{name}/timeline — time-series metrics
Development
# Install in dev mode
pip install -e ".[dev]"
# Run tests
pytest
# Run dashboard dev server
cd dashboard && npm install && npm run dev
# Run API server (requires Postgres)
uvicorn server.app:app --reload --port 8100
Architecture
Developer's App
│
├── modelab SDK (pip install modelab)
│ └── ServerStorage ──HTTP POST──▶ modelab-server
│
modelab-server (docker compose up)
├── FastAPI backend
├── React dashboard (served as static files)
└── PostgreSQL
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file modelab-0.2.0.tar.gz.
File metadata
- Download URL: modelab-0.2.0.tar.gz
- Upload date:
- Size: 58.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a877a20ca035fd3ede2c7f12dc15708ef83195101b866dfb076e36c0f3f6c0cf
|
|
| MD5 |
af51a386efe52b5f6b0d00b48d5cd9d2
|
|
| BLAKE2b-256 |
c56549b4be4671e496a93f99b90b64c6859c67cb4a7a6b3ac68611eb813fc18e
|
Provenance
The following attestation bundles were made for modelab-0.2.0.tar.gz:
Publisher:
publish.yml on elliot736/modelab
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modelab-0.2.0.tar.gz -
Subject digest:
a877a20ca035fd3ede2c7f12dc15708ef83195101b866dfb076e36c0f3f6c0cf - Sigstore transparency entry: 956270862
- Sigstore integration time:
-
Permalink:
elliot736/modelab@a47067f545e4ec08f864caa25043870d7b652343 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/elliot736
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a47067f545e4ec08f864caa25043870d7b652343 -
Trigger Event:
release
-
Statement type:
File details
Details for the file modelab-0.2.0-py3-none-any.whl.
File metadata
- Download URL: modelab-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dbe1459af8c5c5f43c363766f4883479423002bd884ba572399eb8abdcd2577
|
|
| MD5 |
8052ba27ec905b962eb4c4d1dd39d38c
|
|
| BLAKE2b-256 |
b224a8ab9ce09c2aa55f4818aa2762dcc5125ad2806f4f7b03249eb6f9d2f67e
|
Provenance
The following attestation bundles were made for modelab-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on elliot736/modelab
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modelab-0.2.0-py3-none-any.whl -
Subject digest:
5dbe1459af8c5c5f43c363766f4883479423002bd884ba572399eb8abdcd2577 - Sigstore transparency entry: 956270864
- Sigstore integration time:
-
Permalink:
elliot736/modelab@a47067f545e4ec08f864caa25043870d7b652343 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/elliot736
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a47067f545e4ec08f864caa25043870d7b652343 -
Trigger Event:
release
-
Statement type: