Model A/B testing and tracing for LLM applications
Project description
Fallom SDK
Model A/B testing and tracing for LLM applications. Zero latency, production-ready.
Installation
pip install fallom
# With auto-instrumentation for your LLM provider:
pip install fallom opentelemetry-instrumentation-openai
pip install fallom opentelemetry-instrumentation-anthropic
Quick Start
import fallom
# Initialize FIRST - before importing your LLM libraries
fallom.init(api_key="your-api-key")
# Set default session context for tracing
fallom.trace.set_session("my-agent", session_id)
# All LLM calls are now automatically traced!
response = openai.chat.completions.create(...)
Model A/B Testing
Run A/B tests on models with zero latency. Same session always gets same model (sticky assignment).
from fallom import models
# Get assigned model for this session
model = models.get("summarizer-config", session_id)
# Returns: "gpt-4o" or "claude-3-5-sonnet" based on your config weights
agent = Agent(model=model)
agent.run(message)
Version Pinning
Pin to a specific config version, or use latest (default):
# Use latest version (default)
model = models.get("my-config", session_id)
# Pin to specific version
model = models.get("my-config", session_id, version=2)
Fallback for Resilience
Always provide a fallback so your app works even if Fallom is down:
model = models.get(
"my-config",
session_id,
fallback="gpt-4o-mini" # Used if config not found or Fallom unreachable
)
Resilience guarantees:
- Short timeouts (1-2 seconds max)
- Background config sync (never blocks your requests)
- Graceful degradation (returns fallback on any error)
- Your app is never impacted by Fallom being down
Tracing
Auto-capture all LLM calls with OpenTelemetry instrumentation.
Automatic Tracing
import fallom
# Initialize before importing LLM libraries
fallom.init()
# Set session context
fallom.trace.set_session("my-agent", session_id)
# All LLM calls automatically traced with:
# - Model, tokens, latency
# - Prompts and completions
# - Your config_key and session_id
response = openai.chat.completions.create(model="gpt-4o", messages=[...])
Custom Metrics
Record business metrics that OTEL can't capture automatically:
from fallom import trace
# Record custom metrics for this session
trace.span({
"outlier_score": 0.8,
"user_satisfaction": 4,
"conversion": True
})
# Or explicitly specify session (for batch jobs)
trace.span(
{"outlier_score": 0.8},
config_key="my-agent",
session_id="user123-convo456"
)
Multiple A/B Tests in One Workflow
If you have multiple LLM calls and only want to A/B test some of them:
import fallom
fallom.init()
# Set default context for all tracing
fallom.trace.set_session("my-agent", session_id)
# ... regular LLM calls (traced as "my-agent") ...
# A/B test a specific call - models.get() auto-updates context
model = models.get("summarizer-test", session_id, fallback="gpt-4o")
result = summarizer.run(model=model)
# Reset context back to default
fallom.trace.set_session("my-agent", session_id)
# ... more regular LLM calls (traced as "my-agent") ...
Configuration
Environment Variables
FALLOM_API_KEY=your-api-key
FALLOM_BASE_URL=https://spans.fallom.com # or http://localhost:8001 for local dev
Initialization Options
fallom.init(
api_key="your-api-key", # Or use FALLOM_API_KEY env var
base_url="https://spans.fallom.com", # Or use FALLOM_BASE_URL env var
capture_content=True # Set False for privacy mode
)
Privacy Mode
For companies with strict data policies, disable prompt/completion capture:
# Via parameter
fallom.init(capture_content=False)
# Or via environment variable
# FALLOM_CAPTURE_CONTENT=false
In privacy mode, Fallom still tracks:
- ✅ Model used
- ✅ Token counts
- ✅ Latency
- ✅ Session/config context
- ❌ Prompt content (not captured)
- ❌ Completion content (not captured)
API Reference
fallom.init(api_key?, base_url?, capture_content?)
Initialize the SDK. Call this before importing LLM libraries for auto-instrumentation.
capture_content: Whether to capture prompt/completion text (default:True)
fallom.models.get(config_key, session_id, version?, fallback?) -> str
Get model assignment for a session.
config_key: Your config name from the dashboardsession_id: Unique session/conversation ID (sticky assignment)version: Pin to specific version (default: latest)fallback: Model to return if anything fails
fallom.trace.set_session(config_key, session_id)
Set trace context. All subsequent LLM calls will be tagged with this config_key and session_id.
fallom.trace.clear_session()
Clear trace context.
fallom.trace.span(data, config_key?, session_id?)
Record custom business metrics.
data: Dict of metrics to recordconfig_key: Optional ifset_session()was calledsession_id: Optional ifset_session()was called
Supported LLM Providers
Auto-instrumentation available for:
- OpenAI
- Anthropic
- Cohere
- AWS Bedrock
- Google Generative AI
- Mistral AI
- LangChain
- Replicate
- Vertex AI
Install the corresponding opentelemetry-instrumentation-* package for your provider.
Examples
See the examples/ folder for complete examples:
basic_usage.py- Simple A/B testingtracing_only.py- Just tracing, no A/B testingmodels_only.py- Just A/B testing, no tracingbatch_job.py- Recording metrics in batch jobs
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 fallom-0.1.0.tar.gz.
File metadata
- Download URL: fallom-0.1.0.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5449a490e6da7e838d28ba730936d3027c1f41c946c5ceba66173f3cc17e6a14
|
|
| MD5 |
f33f31cf639a4e1b98c5a62360e62c74
|
|
| BLAKE2b-256 |
1a75dcaadc2b31e0ee67f46bbf4c5030b961c30191397d27059c402a461fe827
|
File details
Details for the file fallom-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fallom-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54c74b0f542c3410e8aa2fd434c952ffef330936e42e6d699746275ad0a59107
|
|
| MD5 |
f9d1c0f50a299e16f44bf891af35a5f5
|
|
| BLAKE2b-256 |
e4defee36b247cdeb9683f98467df045b3b259e0cb3a660a1b7a74754054e489
|