Metadata-Version: 2.4
Name: sr-zero
Version: 0.9.2
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; 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`. The command line reads only the rules a question needs: one question in a fresh process took
0.2 to 0.6 seconds and 31 to 35 MB of memory in our tests. `sr-zero serve` loads every rule in 1.2 to 1.6 seconds,
peaks at 190 to 220 MB, and then answers in about 0.2 ms a question.

## 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 |
| `sr-zero pack COMMAND` | your own rules in a Zero pack: `init`, `compile`, `test`, `explain`, `unlearn` (below) |

## 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.

## Build your own Zero

A Zero pack is your own rules, counted from your labelled examples and served in front of the official rules. Every
answer from a pack names the line of the rule that decided it, its record, and how many of its counts came from each
of your sources. A CSV needs `text` and `label` columns; `source` keeps the counts by source, so a source can be
removed exactly, and `group` keeps near-duplicates together when the compiler holds questions out. System One JSON
lines (`{"state", "questions", "expected"}`) compile the same way. The example: 600 synthetic support tickets for six
teams, written from templates, and 180 dev tickets from templates the training tickets never use.

```console
$ sr-zero pack init support --question 'Which team should handle this ticket?'
created support/: manifest.json, overrides.jsonl (rules you write), tests.jsonl (their examples and your decision tests)
…
$ sr-zero pack compile tickets.csv -o support --licence Apache-2.0
read 600 rows from 1 file(s); skipped 0 without a usable label
  account, billing, returns, sales, shipping, technical (under any question template): 600 training questions, evidence sums and a decision list: 45 rules, 1134 evidence cues
sources (questions, licence class): email 300 (P), web 300 (P)
…
$ sr-zero pack test support --dev dev.csv
…
  accuracy        51.7% (the official rules alone: 20.6%)
…
gate: passed (180 questions the pack answers: pack 51.7%, official alone 20.6%; 56 won, 0 lost, sign test p < 0.0001)
$ sr-zero pack explain support 'I was charged twice for my plan this month'
> billing     0.63  ###############
…
why: the answer the request's words count for most (12 of its cues: "i was", "month", "was charged") (132 of 190 right in training)
     support/rules.jsonl:454 · 353 µs · 0 parameters
     by source: email 64 of 98, web 68 of 92
```

The gate passes: on the dev tickets, the pack is right where the official rules are wrong 56 times, and never the
reverse. A third of the dev tickets get a probability of 0.5 or more, and those are right 88.5% of the time: serve
the pack for them, and send the rest to a person or a larger model.

A policy you know is one line of `support/overrides.jsonl`. The examples it must fire on, or leave alone, and your
decision tests go in `support/tests.jsonl`; the pack refuses to load when an example does not hold.

```json
{"id": "chargebacks", "when": {"any": ["chargeback", "disputed the charge"]}, "answer": "billing", "note": "Payment disputes go to billing, whatever else the ticket says."}
```

```json
{"rule": "chargebacks", "state": "My bank shows a chargeback from you.", "fires": true}
{"rule": "chargebacks", "state": "I disputed the charge with my card company.", "fires": true}
{"rule": "chargebacks", "state": "Can I charge my phone with the dock?", "fires": false}
{"state": "I was charged twice for my plan this month", "expect": "billing"}
```

```console
$ sr-zero pack test support --seal
…
overrides: 1 rule(s), 3 example(s), all as they should be
decision tests: 1 of 1 pass
sealed: manifest.json records the hashes of the files that passed
$ sr-zero serve --pack support --port 8000
System Zero 0.9.2: loading the rules ...
packs: support 0.1.0
System Zero is listening on http://127.0.0.1:8000 (POST /v1/systemone)
$ sr-zero pack unlearn support --source email tickets.csv -o support-web
removed 300 rows of email; rebuilt support-web from 300 rows: 1121 rule lines gone, 839 new or changed
its rules.jsonl is the one a compile of the remaining rows gives, byte for byte; manifest.json records the removal
```

The served pack answers its own question, and the official rules answer every other question as they would without
it. `unlearn` rebuilds the pack from the remaining sources with the recorded settings; overrides and tests come along.

## 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, on the Decision Index harness | **1.1 ms** median, 13.1 ms p95 | in one process, about 0.2 ms a question |

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.
- Most answer keys come from the generator that built the row or from the source dataset; 0.6% were set by models,
  and for 26.7% (our pooled data) the origin isn't recorded per row.
- 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 counted from the datasets and data pools listed in `DATA_SOURCES.md`: 995,023 training
  questions, 37.6% of them from sources flagged there (non-commercial, share-alike, of unknown licence, or written by
  a model or a machine). Their answer keys: 41.2% set by the generator program that built the row, 27.2% published
  with the source dataset, 4.3% source labels on machine-translated or paraphrased text, 26.7% our pooled data whose
  label origin is not recorded per row, and 0.6% set by models. 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.
