Metadata-Version: 2.4
Name: sr-zero
Version: 0.11.0
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 0 parameters. Every answer has a receipt.**

0 parameters: no learned weights; the rules are counted data you can read. System Zero answers routine decisions,
such as which team should take a ticket, whether a comment is spam, or which intent or tool fits a request, in under a
millisecond on one CPU core, where neural decision models take tens of milliseconds on GPUs. Every answer names the
rule behind it, the rule's record in training, and its file and line.

- **A receipt for every answer:** the rule, its record in training and its `file:line`, or "no rule applied".
- **Under a millisecond a decision** on one CPU core, and one question from a cold start in under half a second at
  about 36 MB.
- **Pure Python, no dependencies, deterministic.** The rules are Python literals: fix a decision with a diff you can
  review, test and blame.
- **Exact removal of a data source:** every rule's counts add up by training source, so taking a source out is exact.
- **Build your own Zero:** compile your labelled examples into a Zero pack, served in front of the official rules.
- **In front of your model:** `--defer-to` keeps what System Zero is sure of and sends the rest to your model.
- **Install with your agent:** one prompt sets it up in any coding agent.
- **The standard decision API:** `sr-zero serve` speaks the System One decision API, so its clients work unchanged.

The full story, with interactive demos: [system-zero.semantic-router.org](https://system-zero.semantic-router.org).

## Where it fits

- **In front of your model:** routine decisions in under a millisecond with a receipt; the rest goes to your neural
  model.
- **Router signals:** fast, readable signals for an LLM router, such as an intent, a tool choice or a policy check.
- **Decisions you must audit:** every answer names its rule, its record and its file and line.
- **Build your own Zero:** your labelled examples become your own rules, and a data source can be removed exactly.
- **Computable checks:** code, logic and tool calls, answered by modules that compute them.
- **CPU-only, edge or offline:** pure Python, no dependencies, no GPU, and nothing leaves the machine.

Not for: open-domain language and world knowledge; keep those with a neural model.

## Install

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

To install it, run one of:

```sh
uv tool install sr-zero
```

```sh
pip install sr-zero
```

Then serve the System One API:

```sh
sr-zero serve --port 8000
```

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.8999059390425449}},"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.25 to 0.5 seconds and 35 to 38 MB of memory in our tests, on Python 3.9, 3.12 and 3.14. `sr-zero serve` loads every
rule in about 3 seconds, peaks at 410 to 460 MB, and then answers a question in about 0.3 ms at the median.

**Install with your agent**

```text
Set up System Zero by following https://system-zero.semantic-router.org/llms.txt
```

**Add the System Zero skill to your agent**

```text
Install the System Zero agent skill from https://system-zero.semantic-router.org/skill/SKILL.md
```

## Use it in front of your model

Put System Zero in front of your neural model, or of any System One endpoint. It keeps the decisions it is sure of,
each with a receipt, and sends the rest to your model:

```console
$ sr-zero serve --pack support --defer-to http://127.0.0.1:8001 --port 8765
System Zero 0.11.0: loading the rules ...
packs: support 0.1.0
defer: questions not kept here (threshold 0.625, from `pack test --dev --seal` of pack support) go to http://127.0.0.1:8001/v1/systemone
System Zero is listening on http://127.0.0.1:8765 (POST /v1/systemone)
```

A question stays with System Zero when a pack's override decided it, or a rule answered it at or above the threshold;
an answer resting on a prior or on chance always goes. Pick the threshold on your own data:
`sr-zero pack test PACK --dev DATA --seal` recommends one and seals it into the pack, and `--threshold T` sets one by
hand. If your model fails or times out, System Zero keeps its own answer, marked, and the request still succeeds. The
one-shot command and `-j` take the same options.

Without `--defer-to`, a caller does the same with the API's probabilities, in standard-library Python:

```python
import json
import sys
import urllib.request

ZERO = "http://localhost:8765/v1/systemone"
MODEL = "http://localhost:8001/v1/systemone"
THRESHOLD = 0.625  # what `pack test --dev` prints, safe to copy: it keeps the answers the sealed one keeps


def ask(url, state, questions):
    body = json.dumps({"state": state, "questions": questions}).encode()
    request = urllib.request.Request(url, body, {"Content-Type": "application/json"})
    with urllib.request.urlopen(request, timeout=10) as reply:
        return json.load(reply)["answers"]


def top(answer):
    """The probability of the answer's top option."""
    if answer["type"] == "noul":
        return max(answer["noul"], 1 - answer["noul"])
    return max(answer["probabilities"].values())


def decide(state, questions):
    answers = ask(ZERO, state, questions)
    unsure = {key: questions[key] for key, answer in answers.items() if top(answer) < THRESHOLD}
    if unsure:
        try:
            answers.update(ask(MODEL, state, unsure))
        except OSError as error:
            print(f"your model did not answer ({error}); keeping System Zero's answers", file=sys.stderr)
    return answers, sorted(unsure)
```

## Results

System Zero is at its best on answers it can compute, tool calls and intents. On the Decision Index public suite
(chance-corrected skill, 0 to 100; release 0.11.0):

| Benchmark | The decision | System Zero |
|---|---|---:|
| CRUXEval | how a short Python function executes | **97.5**, above the best of the board's 1.2 to 4.7B entrants (95.8) |
| BFCL | which function to call, with which arguments | **88.8**, with 91.7% of cases exactly right |
| BANKING77 | the intent of a banking request | **83.9** |
| CLINC150 | the intent of an assistant request, or none | **82.1** |
| BBH, fixed-option tasks | logic puzzles and other BIG-Bench Hard tasks | **60.1** |
| PhishNChips | whether an email is phishing | **56.5**, with 78.2% right |
| API-Bank | the API call a request needs | **52.6** |
| When2Call | whether to call a tool, ask a follow-up or decline | **51.7** |

Tools & Automation (49.4) and Retrieval & Classification (48.4) are its strongest areas. CLINC150, BANKING77 and
When2Call train on their own training splits, and the BBH and phishing tasks on generated ones in the same formats.

| Measure | System Zero | For reference |
|---|---:|---|
| Decision Index, public index (37 benchmarks) | **27.60** | neural decision models on the same board: 0.6B 28.82, 0.8B 36.93, 2B 42.22, 4B 54.90 |
| Latency, one CPU core | **0.3 ms** a question at the median, 0.6 ms p95, in one process; 0.6 ms median a request on the Decision Index harness | neural decision models: tens of milliseconds on GPUs |
| Cold start, one question | **0.25 to 0.5 s** at 35 to 38 MB | `sr-zero serve`: every rule loaded in about 3 s, 410 to 460 MB at the peak |
| Decision Bench, bench-v4 (1,071 decisions, accuracy) | **46.6%** | chance 28.0% |

## How it works

A decision model with no learned weights. It answers the typed decision questions of the System One API (a choice
of 2 to 255 options, a yes/no, a score) with a probability for every option. The answers come from rules counted
over training decisions (decision lists, evidence sums, bags of words, relation tables and context cues) and from
hand-written modules for what can be computed: an interpreter, puzzle solvers, scene readers, rhyme and meter, chord
templates, tool planning, BM25 ranking and checks for personal data. 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, and reaches 0.9 only on a record that three or more families of training questions back, so a weak
record says "not sure", and a caller can send the decision up to a neural model.

- **Traceable.** A rule behind every answer, and counts behind every rule that add up by training source, so
  removing a source is exact.
- **Editable.** Rules are Python literals. A decision is fixed with a diff that can be reviewed and tested, and
  `git blame` names the commit.
- **Calibrated in distribution.** Probabilities are read off counted records, with no fitted temperature:
  calibration error 2.8% on 50,443 held-out dev questions.

## 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 serve --pack PACK --defer-to URL` | keep what System Zero is sure of, and send the rest to your model's System One endpoint |
| `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 |
| `POST /api/decide` | a `/v1/systemone` request, answered with the rule behind each answer: its record, file and line |

| 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 data/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 data/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 · 419 µ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 your model with `--defer-to` (above).

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.11.0: 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 data/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.

## Limits

- Open-domain language and world knowledge are not its strength: System Zero is near chance there. Outside what
  its rules cover it falls back to the prior or chance, and its confidence on new domains can be wrong, so keep
  open-domain or new-domain decisions with a neural model.
- Its results are public-benchmark numbers, largely in distribution; private tests may show less.
- Its modules are written for English text.
- 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 for the label rules, 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. The package metadata names their licence
  `LicenseRef-System-Zero-Rule-Tables`, and `NOTICE` describes it. The tool ranker also counts 86,720 candidate questions of
  2,710 ToolRet training queries, whose dataset card states no licence.
- 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.
