Metadata-Version: 2.4
Name: sr-zero
Version: 0.9.1
Summary: A decision model with no learned weights: readable rule tables learned from data, plus hand-written modules. Pure Python, no dependencies.
Author: vLLM Semantic Router
License-Expression: Apache-2.0 AND LicenseRef-System-Zero-Rule-Tables
Project-URL: Homepage, https://system-zero.semantic-router.org
Keywords: decision model,rules,interpretable,explainable,classification,System One,LLM routing
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Text Processing :: Linguistic
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
License-File: DATA_SOURCES.md
Dynamic: license-file

# System Zero

**A decision model with no learned weights**, published as `sr-zero`. System Zero answers the typed decision
questions of the System One API (a choice of 2 to 255 options, a yes/no, a score on ordered levels) with a
probability for every option. The answers come from rules counted over training decisions, kept as Python literals
you can read, and from hand-written modules for what can be computed. Every answer names its rule, the rule's record
in training, and its file and line, or says that no rule applied. The probability is the lower end of that record's
95% interval, so a weak record says "not sure", and a caller can send the decision up to a neural model.

Pure Python standard library, no dependencies, one CPU core, deterministic. The full story, with interactive demos:
[system-zero.semantic-router.org](https://system-zero.semantic-router.org).

**Licence, in short:** the code is Apache-2.0. The rule tables are statistics counted from datasets with mixed
licences, some of them non-commercial, share-alike, research-only or unknown, and from labels generated by models;
their licence is under review. Check `DATA_SOURCES.md`, installed with the package, before commercial use.

## Install

```sh
uvx sr-zero 'Check out my channel and subscribe' -q 'Is this comment spam?' --yes-no
```

```sh
uv tool install sr-zero        # or: pip install sr-zero
sr-zero serve --port 8000
```

Then, from another terminal, one question over HTTP:

```sh
curl -s http://localhost:8000/v1/systemone \
  -H 'Content-Type: application/json' \
  -d '{"state": "Check out my channel and subscribe",
       "questions": {"spam": {"type": "noul", "instructions": "Is this comment spam?"}}}'
```

```json
{"model":"system-zero","answers":{"spam":{"type":"noul","noul":0.9059390425448562}},"usage":{"input_tokens":10,"output_tokens":0}}
```

Python 3.9 or newer. The package installs the command `sr-zero`, also available as `system-zero`, and the Python
package `system_zero`. Every process loads all the rule tables before its first answer: 8.5 to 21 seconds and 1.2 to
1.4 GB of memory in our tests, depending on the Python version (the newer, the faster). `sr-zero serve` loads them
once and keeps them loaded, so for more than a few questions, run it or pass a file of requests with `-j`. A compact
rules format that loads lazily is planned for a later release.

## From the command line

| Command | What it does |
|---|---|
| `sr-zero STATE -q QUESTION -o A B C` | one choice, with the rule behind it |
| `sr-zero STATE -q QUESTION --yes-no` | a yes/no probability |
| `sr-zero STATE -q QUESTION --levels LOW MID HIGH` | a score on ordered levels |
| `sr-zero -j requests.jsonl -e` | `{state, questions}` per line in, one answer per line out, with explanations |
| `sr-zero serve --host HOST --port PORT` | the System One API over HTTP |

## From Python

With System One's request: a state and named questions.

```python
from system_zero import decide

decide("Our production app has returned 500 errors since the 09:00 deploy. Customers cannot check out.",
       {"team": {"type": "choice", "instructions": "Which team should handle this ticket?",
                 "criteria": {"billing": "Payments, invoices and refunds",
                              "engineering": "Outages, errors and bugs",
                              "sales": "Plans, pricing and contracts"}},
        "urgent": {"type": "noul", "instructions": "Does the user report a problem that blocks them?"}},
       explain=True)
```

## The System One API

`sr-zero serve` answers the System One API as the published standard, `systemone/0.2`, and its `vllm-sr/5.0`
extensions define it, so System One clients work unchanged.

| Endpoint | Does |
|---|---|
| `POST /v1/systemone` | one request; a question that cannot be answered fails it with `question_failed` |
| `POST /v1/systemone/batch` | named requests in one call, each answered as it would be alone |
| `POST /v1/decisions` | the native form: a failed question carries its own error in a 200 |
| `GET /v1/models`, `GET /health` | the model and its card, and readiness |

| Question | You write | The answer |
|---|---|---|
| `choice` | `criteria`: 2 to 255 options, each a key and a description | `choice`, `confidence` and every option's `probabilities` |
| `noul` | `instructions`; optionally `criteria.true` and `criteria.false` | `noul`: P(yes) |
| `score` | `criteria`: 2 to 10 levels, lowest first | `score` (the expected level), `confidence`, `legend` and each level's `probabilities` |

Errors are the standard's. System Zero reads text: `box` questions and images are refused. Set
`SYSTEM_ZERO_API_KEYS` to require an API key on the `/v1/` paths.

## Results

Public-benchmark results of the full 0.9.0 build, the one this package ships, each run with its benchmark's own
scorer on one CPU core.

| Measure | System Zero 0.9.0 | For reference |
|---|---:|---|
| Decision Index, public index (37 benchmarks, chance-corrected) | **25.6** | |
| Decision Index, public, outside language understanding (28 benchmarks, index points) | **23.44** | |
| Decision Bench, bench-v4 (1,071 decisions, accuracy) | **48.4%** | chance 28.0% |
| Held-out test (49,674 questions, accuracy) | **57.16%**, calibration error 2.2% | majority answer 39.6%; uniform 33.8% |
| Latency, one CPU core | **1.1 ms** median, 13.1 ms p95 | |

These are public-index and largely in-distribution numbers: stand-ins and train splits for many of the task formats
are in the training data, so private tests may show less.

## Limits

- Language understanding and world knowledge stay with neural models. Words alone do not carry those answers, and
  System Zero says so with a low probability, so the decision can go up.
- Under distribution shift, some families of decisions are confidently wrong.
- Its modules are written for English text, so other languages lean on the counted rules.
- Part of the training labels were generated by models, and the rules reflect their data.
- Not for decisions about people or other high-stakes uses without review.

## Licence

- The code is licensed under the Apache License 2.0 (`LICENSE`).
- The rule tables are derived from the datasets listed in `DATA_SOURCES.md` and from labels generated by models.
  37.6% of the 995,023 training questions come from sources flagged there: non-commercial, share-alike, of unknown
  licence, or written by a model or a machine. Their licence is under review; the package metadata names it
  `LicenseRef-System-Zero-Rule-Tables`.
- Check `DATA_SOURCES.md` before commercial use. It is in the sdist, and `NOTICE` and `DATA_SOURCES.md` are
  installed with the package in its `.dist-info/licenses/` directory.
