deterministic-ai-testing
Playwright for AI agents.
Deterministic OpenAI-compatible testing infrastructure for AI applications, agents, and CI pipelines.
The problem
AI applications are extremely difficult to test.
Real LLMs are:
- nondeterministic
- expensive
- slow
- flaky in CI
- hard to reproduce
- difficult to debug
That breaks:
- automated tests
- agent workflows
- CI/CD pipelines
- regression testing
- local development
The solution
deterministic-ai-testing is a local OpenAI-compatible mock server that gives you:
✅ deterministic outputs
✅ reproducible AI tests
✅ local/offline development
✅ CI-safe LLM simulation
✅ programmable scenarios
✅ tool-call mocking
✅ streaming simulation
✅ rate-limit/error testing
Without calling real model APIs.
Why developers use this
Instead of paying for real inference during tests:
frontend -> real OpenAI API
you can do:
frontend -> deterministic-ai-testing
using only:
base_url="http://localhost:8000/v1"
Everything else stays compatible.
Snapshot Testing
Save deterministic AI outputs:
mockllm snapshot save snapshots/hello.json --prompt "hello"
Validate them later:
mockllm snapshot test snapshots/
Example output:
PASS snapshots/hello.json
PASS snapshots/refund.json
This enables:
- deterministic regression testing
- CI-safe AI verification
- stable agent workflows
- reproducible LLM behavior
Tool-call assertions
MockLLM includes assertion helpers for deterministic agent testing.
Example:
from mockllm.assertions import (
assert_tool_called,
assert_tool_called_with,
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "user", "content": "find refund policy"}
],
)
assert_tool_called(response, "search_docs")
assert_tool_called_with(
response,
"search_docs",
{"query": "refund policy"},
)
This enables:
- deterministic AI-agent testing
- orchestration verification
- workflow regression testing
- CI-safe agent assertions
Demo
Start the server
python -m uvicorn app.main:app --reload --port 8000
Health check
curl http://localhost:8000/health
Expected:
{"status":"ok","service":"deterministic-ai-testing"}
Chat completions
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"gpt-4o","messages":[{"role":"user","content":"hello"}]}'
Expected:
{
"choices": [
{
"message": {
"content": "Hello from MockLLM. This response is deterministic."
}
}
]
}
Tool-call mocking
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"gpt-4o","messages":[{"role":"user","content":"please use tool"}]}'
Expected:
{
"tool_calls": [
{
"function": {
"name": "search_docs"
}
}
]
}
Error simulation
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"gpt-4o","messages":[{"role":"user","content":"rate limit"}]}'
Expected:
{
"detail": {
"error": {
"message": "Rate limit exceeded by mock scenario."
}
}
}
Streaming simulation
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"gpt-4o","stream":true,"messages":[{"role":"user","content":"hello"}]}'
OpenAI SDK compatibility
Works with the official OpenAI SDK.
from openai import OpenAI
client = OpenAI(
api_key="mock-key",
base_url="http://localhost:8000/v1",
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "user", "content": "hello"}
],
)
print(response.choices[0].message.content)
Run:
python3 examples/openai_sdk_example.py
60-Second Quickstart
Install directly from PyPI:
pip install deterministic-ai-testing
Start the MockLLM server:
python -m uvicorn app.main:app --reload --port 8000
Verify the server is running:
curl http://localhost:8000/health
Expected response:
{
"status": "ok",
"service": "deterministic-ai-testing"
}
Save a deterministic AI snapshot:
mockllm snapshot save snapshots/hello.json --prompt "hello"
Run snapshot tests:
mockllm snapshot test snapshots/
Expected output:
PASS snapshots/hello.json
PASS snapshots/refund.json
Run MockLLM with Docker:
docker compose up --build
Use with the OpenAI SDK:
from openai import OpenAI
client = OpenAI(
api_key="mock-key",
base_url="http://localhost:8000/v1",
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "user", "content": "hello"}
],
)
print(response.choices[0].message.content)
Example deterministic response:
Hello User - this mock response changed live from YAML.
Run the included example:
python examples/openai_sdk_example.py
Features
OpenAI-compatible endpoints
/v1/chat/completions/v1/completions/v1/embeddings
Deterministic scenario engine
Supports:
- exact matching
- contains matching
- regex matching
YAML scenarios
Edit:
scenarios/default.yaml
Example:
- name: refund request
match:
contains: refund
response:
content: Refund approved. Your money will be returned in 3-5 business days.
Live edits apply immediately.
No recompilation required.
Tool-call simulation
Mock:
- function calls
- tool invocations
- agent actions
- assistant tool responses
Useful for:
- agent testing
- orchestration testing
- frontend AI development
Failure simulation
Test:
- rate limits
- retries
- API failures
- fallback logic
- degraded AI behavior
Streaming support
Simulate streaming token responses locally.
Useful for:
- chat UIs
- token rendering
- frontend streaming logic
- websocket/SSE behavior
Embeddings support
Includes deterministic fake embeddings for:
- RAG testing
- retrieval simulation
- vector pipeline testing
- semantic search development
CI-safe AI testing
Run deterministic AI tests in:
- GitHub Actions
- CI/CD pipelines
- local test suites
without paying for inference.
Testing
Run all tests:
python -m pytest
Docker
Run locally
docker compose up --build
Then test:
curl http://localhost:8000/health
Example use cases
- AI app testing
- AI agent testing
- LangChain testing
- RAG testing
- frontend AI UI development
- CI/CD pipelines
- retry/fallback testing
- local AI simulation
- offline AI development
- deterministic regression testing
Architecture
application
↓
OpenAI SDK
↓
deterministic-ai-testing
↓
deterministic YAML scenarios
Roadmap
Planned features:
- snapshot diffing
- GitHub Actions integration
- installable CLI
- scenario validation
- tool-call assertions
- agent replay
- multi-agent workflows
- hosted team dashboard
Product vision
This is not just an OpenAI mock server.
The goal is to become:
deterministic AI testing infrastructure
for the next generation of AI-native software.
or:
Playwright for AI agents.
Why this matters
The next major software wave is:
- AI infrastructure
- agent orchestration
- deterministic testing
- AI observability
- developer workflow acceleration
AI software requires a new testing stack.
This project is part of that stack.
Contributing
Contributions are welcome.
Especially:
- OpenAI compatibility improvements
- snapshot testing
- LangChain examples
- CLI tooling
- GitHub Actions
- scenario validation
- agent testing workflows
License
MIT
Snapshot diffs
When a snapshot fails, MockLLM shows a unified diff:
FAIL snapshots/hello.json
expected exact:
BROKEN EXPECTED OUTPUT
actual:
Hello User - this mock response changed live from YAML.
diff:
--- expected
+++ actual
@@ -1 +1 @@
-BROKEN EXPECTED OUTPUT
+Hello User - this mock response changed live from YAML.
This makes AI output regressions easy to debug in local development and CI pipelines.
Scenario validation
MockLLM validates scenarios/default.yaml before using it.
It catches:
- missing
match - missing
responseorerror - invalid scenario structure
- scenarios that define both
responseanderror
This helps teams fail fast when test scenarios are malformed.
Multi-step workflow snapshots
MockLLM can validate deterministic tool workflows inside snapshots.
Example:
{
"name": "tool-workflow",
"request": {
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "please use tool"
}
]
},
"expected": {
"tool_name": "search_docs",
"tool_order": [
"search_docs"
]
}
}
Metadata
Release files for deterministic-ai-testing 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| deterministic_ai_testing-0.2.0.tar.gz | 14.4 kB | Without provenance | Details for deterministic_ai_testing-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| deterministic_ai_testing-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for deterministic_ai_testing-0.2.0-py3-none-any.whl |
Total release size: 27.6 kB
Release files / deterministic_ai_testing-0.2.0.tar.gz
| Download URL | deterministic_ai_testing-0.2.0.tar.gz |
|---|---|
| Size | 14.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fab5fe101f20bcd7f3662e8456a5eb6272b6043a259b093b40fd9104639e4c69
|
|
BLAKE2b-256 checksum How to use checksums |
36b1cd69b5ab82a686fe8e81bcc875c92aa4ec9e7558f7be4b770fa8ba2ad1c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / deterministic_ai_testing-0.2.0-py3-none-any.whl
| Download URL | deterministic_ai_testing-0.2.0-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
45efb1c66b53b980debc252758d9cde7e1ab07c1cb7cc41e2cb5a296d5c12114
|
|
BLAKE2b-256 checksum How to use checksums |
070e7ff5342c678ab256fbdb1facb2750d97573859a5ca451b101e53d3f5331e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for deterministic-ai-testing 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.