CI-native regression enforcement for LLM outputs.
Project description
Phylax — CI for AI Behavior
Stop AI regressions before they reach production.
⚡ 30-Second Example
pip install phylax
from phylax import trace, expect
@trace(provider="openai")
@expect(must_include=["refund"], must_not_include=["lawsuit"])
def reply(prompt):
return llm(prompt) # your LLM call
phylax check
❌ FAIL — expected "refund" in response
Trace ID: abc-123
Violation: must_include rule failed
That's it. Your CI now blocks AI behavior regressions.
🎯 What Phylax Does
Phylax enforces deterministic contracts on LLM outputs. When your AI's behavior changes across model versions, prompts, or configurations — Phylax catches it.
Developer writes rules → Phylax tests every response → CI blocks regressions
Phylax is NOT monitoring, observability, or AI-based evaluation. It's a test framework for AI behavior.
🚀 Quick Start
1. Install
pip install phylax[openai] # or phylax[google], phylax[groq], phylax[all]
2. Write Traced Code
from phylax import trace, expect, execution, OpenAIAdapter
# Single call with expectations
@trace(provider="openai")
@expect(must_include=["refund"], max_latency_ms=3000)
def handle_refund(message: str) -> str:
adapter = OpenAIAdapter()
response, _ = adapter.generate(prompt=message)
return response
# Multi-step agent flow
@trace(provider="openai")
@expect(must_include=["intent"])
def classify(message: str) -> str:
adapter = OpenAIAdapter()
response, _ = adapter.generate(prompt=f"Classify: {message}")
return response
# Track agent workflows as execution graphs
with execution() as exec_id:
intent = classify("I want a refund")
response = handle_refund("Process refund for order #123")
3. Enforce in CI
# .github/workflows/phylax.yml
name: Phylax CI
on: [push, pull_request]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pip install phylax[openai]
- run: phylax check # exits 1 on contract violation
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
📋 Expectation Rules
| Rule | What It Enforces | Example |
|---|---|---|
must_include |
Response contains required text | ["refund", "policy"] |
must_not_include |
Response excludes forbidden text | ["lawsuit", "attorney"] |
max_latency_ms |
Response time limit | 3000 (3 seconds) |
min_tokens |
Minimum response length | 50 tokens |
Combine with Logic
from phylax import trace, expect, AndGroup, OrGroup, MustIncludeRule, MaxLatencyRule
@trace(provider="openai")
@expect(rules=AndGroup([
MustIncludeRule("refund"),
OrGroup([
MaxLatencyRule(3000),
MustIncludeRule("processing"),
]),
]))
def handle(message):
...
🔬 Surface Enforcement
Enforce contracts on any LLM output type — not just text.
from phylax import (
Surface, SurfaceEvaluator,
FieldExistsRule, # JSON field must exist
TypeEnforcementRule, # Strict type checking
ToolPresenceRule, # Tool must be called
StepCountRule, # Execution must have N steps
ExactStabilityRule, # Output must not change between runs
)
| Surface Type | Rules | Use Case |
|---|---|---|
| Structured Output | Field exists, type, value, enum, array bounds | JSON API responses |
| Tool Calls | Presence, count, argument, ordering | Agent tool usage |
| Execution Traces | Step count, forbidden transitions, required stages | Multi-step workflows |
| Cross-Run Stability | Exact match, allowed drift | Regression detection |
📊 Execution Graphs
Visualize and debug multi-step agent workflows:
from phylax import trace, expect, execution
with execution() as exec_id:
step1 = classify(message) # → Node 1
step2 = research(step1) # → Node 2
step3 = respond(step2) # → Node 3
# Phylax builds a DAG:
# [classify] → [research] → [respond]
#
# View it:
# phylax server → http://127.0.0.1:8000/ui
🛡️ Enforcement Modes
from phylax import ModeHandler, EnforcementMode
handler = ModeHandler(mode=EnforcementMode.ENFORCE)
# enforce → CI fails on violation (default)
# quarantine → CI fails, but logs for review
# observe → CI passes, violations logged only
🔧 Commands
| Command | What It Does |
|---|---|
phylax init |
Initialize config |
phylax server |
Start API + UI |
phylax list |
List traces (--failed for failures only) |
phylax show <id> |
Inspect a trace |
phylax bless <id> |
Mark as golden baseline |
phylax check |
CI enforcement — exits 1 on violation |
phylax --version |
Show version |
🔌 Supported Providers
pip install phylax[all] # Install all providers
| Provider | Import | Env Variable |
|---|---|---|
| OpenAI | from phylax import OpenAIAdapter |
OPENAI_API_KEY |
| Gemini | from phylax import GeminiAdapter |
GOOGLE_API_KEY |
| Groq | from phylax import GroqAdapter |
GROQ_API_KEY |
| Mistral | from phylax import MistralAdapter |
MISTRAL_API_KEY |
| HuggingFace | from phylax import HuggingFaceAdapter |
HF_TOKEN |
| Ollama | from phylax import OllamaAdapter |
OLLAMA_HOST |
📁 Examples & Templates
Examples — Learn by doing
| Example | What You'll Learn |
|---|---|
examples/quickstart/ |
Basic tracing in 10 lines |
examples/support_bot/ |
Content safety enforcement |
examples/summarization/ |
Latency + quality contracts |
examples/agent_workflow/ |
Multi-step agents with execution graphs |
Templates — Start building
| Template | What It Includes |
|---|---|
templates/ai-chatbot/ |
Chatbot + contracts + CI config |
templates/ai-agent/ |
Multi-step agent + execution tracking |
templates/ai-rag/ |
RAG pipeline + grounding enforcement |
📖 Documentation
Start here:
- Quickstart — 10 minutes to CI enforcement
- Mental Model — What Phylax is and isn't
- Providers — LLM provider reference
- Error Codes — Error code reference
Reference:
- API Contract — Stability guarantees
- Execution Context — Trace grouping
- Non-Goals — What Phylax will never do
- Versioning — Release policy
Advanced:
🏛️ Architecture
phylax/
├── _internal/
│ ├── expectations/ # Deterministic rule engine
│ ├── surfaces/ # Surface enforcement (JSON, tools, traces)
│ ├── metrics/ # Expectation health & coverage
│ ├── modes/ # Enforcement mode control
│ ├── meta/ # Dilution guards
│ ├── artifacts/ # Machine-consumable CI outputs
│ ├── adapters/ # LLM provider adapters
│ └── graph.py # Execution graphs
├── cli/ # CLI commands
├── server/ # API + health routes
└── ui/ # Web inspector
910 tests · v1.6.0 · All 4 axes complete + Dataset Contracts + Behavioral Diff + Model Simulator + CI Kits + Guardrail Packs
TL;DR
Phylax is CI for AI behavior. It records LLM outputs, evaluates them against declared contracts, and fails builds when behavior regresses. No scoring. No judgment. No AI-based evaluation. Just deterministic enforcement.
License
MIT License
Made with love❤️
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 phylax-1.6.1.tar.gz.
File metadata
- Download URL: phylax-1.6.1.tar.gz
- Upload date:
- Size: 6.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52d1fba794678d678b09edf8983db16db567235db7cea63f88ac338b5677d918
|
|
| MD5 |
6eafcc731df865aab7cf41a4fda62323
|
|
| BLAKE2b-256 |
a5460bb1f78581ccc41a7b920ce51df34fe6626da6e7a87d0dac11737de60d01
|
File details
Details for the file phylax-1.6.1-py3-none-any.whl.
File metadata
- Download URL: phylax-1.6.1-py3-none-any.whl
- Upload date:
- Size: 6.9 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d8a0051e6fab6498032fe2ebb441024a3e2842b9ef9fec9bf44d1a96d0d439e
|
|
| MD5 |
57b04d6a50172632458850d80640293c
|
|
| BLAKE2b-256 |
c44ecdf83805a69b983e6067d9c5dd9a66b60f5da491d9278a1c8cc12ce49be4
|