ai-stability
ai-stability is a CLI-first LLM stability analyzer for developers who want to measure output consistency, detect prompt variance, and inspect unstable model behavior locally.
It runs the same prompt multiple times against the same model, compares the responses, computes a simple stability score, and saves a local JSON artifact for replay and debugging.
TL;DR
- install:
pipx install ai-stability - run:
ai-stability run prompt.txt --n 5 --provider openai --model gpt-4.1-mini - get: repeated outputs, similarity scores, a stability label, inline diffs, and a saved JSON artifact
Who It Is For
- prompt engineers testing reliability
- AI application developers debugging flaky model behavior
- teams comparing model changes before shipping
- developers who want a local CLI, not a hosted eval platform
What It Looks Like
Example prompt file:
Explain why deterministic prompts can still produce non-deterministic LLM outputs in exactly three sentences.
Example output:
Summary
- Average similarity: 82.64%
- Stability score: 83/100
- Stability label: High stability
Diff
[- hidden system behavior -] [+ internal state shifts +]
Why It Exists
LLM outputs often vary even when the prompt, model, and calling code stay the same. That makes it harder to:
- evaluate prompt reliability
- spot regressions during model upgrades
- understand whether output drift is minor wording variance or meaningful behavior change
- build confidence in AI-powered developer tooling
ai-stability is intentionally narrow and local-first:
- one prompt file in
- repeated model calls
- simple, explicit similarity scoring
- readable terminal output
- JSON artifact saved locally for replay and debugging
Features
- CLI-first workflow with no database, dashboard, or hosted backend
- repeated prompt execution against the same model
- explicit pairwise similarity and aggregate stability scoring
- run-by-run output review
- inline reference-vs-run diffing for fast variance inspection
- local JSON artifact saving for debugging and replay
- provider abstraction with OpenAI implemented first
Requirements
- Python 3.11+
- An OpenAI API key in
OPENAI_API_KEY
Install
Recommended for end users
pipx install ai-stability
For development
python -m venv .venv
.venv\Scripts\activate
python -m pip install -e .[dev]
Configure
Set your API key in the shell:
$env:OPENAI_API_KEY="your_api_key"
You can copy .env.example for reference, but the CLI reads the key from the environment.
Quick Start
Run the analyzer:
ai-stability run prompt.txt --n 5 --provider openai --model gpt-4.1-mini
If you want to invoke it through the module instead of the installed script:
python -m ai_stability run prompt.txt --n 5 --provider openai --model gpt-4.1-mini
Example with a custom JSON output path:
ai-stability run prompt.txt --n 5 --provider openai --model gpt-4.1-mini --out results\sample-run.json
CLI Command
ai-stability run PROMPT_FILE --n 5 --provider openai --model MODEL_NAME
Current options:
--n: number of repeated runs, minimum2--provider: currentlyopenai--model: target model name--temperature: sampling temperature, default1.0--out: optional output file or output directory for the JSON artifact
How Scoring Works
The v1 scoring heuristic is intentionally simple and inspectable:
- normalize whitespace in each output
- compute pairwise text similarity with Python's
difflib.SequenceMatcher - average all pairwise similarity scores
- convert the average to a
0-100stability score
Stability labels:
80-100: High stability50-79: Medium stability0-49: Low stability
What the CLI Prints
- summary first
- average and pairwise similarity
- final stability score and label
- each run output
- a simple reference-vs-run diff for variation review
JSON Artifact
By default, results are written to results/ai-stability-YYYYMMDD-HHMMSS.json.
The JSON artifact includes:
- prompt metadata
- provider and model
- all collected outputs
- pairwise similarities
- stability score and label
- human-readable diffs
Example Workflow
ai-stability run prompt.txt --n 5 --provider openai --model gpt-4.1-mini
Use this when you want to compare how stable a model is for a fixed prompt before shipping a prompt change, swapping models, or debugging flaky output behavior.
Run Tests
python -m pytest
Repository Structure
src/ai_stability/
cli.py
runner.py
scoring.py
diffing.py
output.py
storage.py
providers/
base.py
openai_provider.py
tests/
test_scoring.py
test_runner.py
Project Docs
Release Process
ai-stability is published on PyPI:
Releases are published from GitHub Actions with PyPI Trusted Publishing.
Typical release flow:
- update the version in
pyproject.tomlandsrc/ai_stability/__init__.py - commit and push the release commit
- create and push a Git tag like
vX.Y.Z - let the
publish.ymlworkflow run tests, build distributions, publish to PyPI, and create or update the matching GitHub release automatically
PyPI Trusted Publishing still requires one-time configuration on PyPI for this repository before automated publishing will succeed.
Example:
git tag vX.Y.Z
git push origin vX.Y.Z
Files to Review First
src/ai_stability/cli.pysrc/ai_stability/runner.pysrc/ai_stability/scoring.pysrc/ai_stability/providers/openai_provider.py
Roadmap Notes
- V1 runs requests sequentially on purpose.
- Only OpenAI is implemented, but the provider boundary is small and ready for Anthropic later.
- The scoring heuristic is intentionally simple and inspectable rather than statistically sophisticated.
Metadata
Release files for ai-stability 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ai_stability-0.1.3.tar.gz | 14.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ai_stability-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.9 kB
Release files / ai_stability-0.1.3.tar.gz
| Download URL | ai_stability-0.1.3.tar.gz |
|---|---|
| Size | 14.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ef4e2314227712d5ee918b99a42a4b3cb1ef378fe7d7cf3e3bbc3af96cfc4dc
|
|
BLAKE2b-256 checksum How to use checksums |
c572eaf5240d1c11af3ac47ca1201d098ccf157b73eeb9b531c0fb565f7aee5d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / ai_stability-0.1.3-py3-none-any.whl
| Download URL | ai_stability-0.1.3-py3-none-any.whl |
|---|---|
| Size | 14.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6c04d584ce3a4dafcbcfa00a715e4487cb77acd8fd25ab66cb778a06e85f6536
|
|
BLAKE2b-256 checksum How to use checksums |
60dfe73270e6091e4168caae57bf6c579a5bf5e6aa6ed3aaee046d48e1951eaa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency log