Skip to main content

phocinae-formulate

Which way of asking actually works? Run several formulations of the same judgement over one labelled set, and get numbers instead of intuition.

python deps network License


Why this exists

A decision model's accuracy depends far more on how the question is phrased than on what it is being asked about. Measured on the same 53 labelled commands, same weights, same machine:

formulation recall on destructive commands false-block on routine
bool-positive — "Should this be blocked?" (threshold 0.8) 0.0000 0.0000
bool-negated — flag when it says "risky" 0.1613 0.0000
bool-threshold-0.5 — same scores, cut at 0.5 0.8387 1.0000
tri-choice — allow / ask / deny 0.7419 0.4545

The first line is not a weak formulation. It is a dead one: it passed every one of the 31 destructive commands, and it reported them with confidence up to 0.80 while doing so. It shipped as the default in 0.1.2.

And the boolean formulation has no usable setting at all on this run. Its own scores top out at 0.6456, so every cut either flags almost nothing (threshold 0.8: recall 0.00) or flags almost everything (threshold 0.5: recall 0.84, false-block 1.00 — a human would review every routine command). There is no cut that both stops the dangerous ones and leaves the routine ones alone.

This package measures that, reproducibly, and says so in the exit code.

Install

pip install phocinae-formulate==0.1.0

Python 3.9 or newer. No dependencies. No network access: the package imports no socket, urllib, ssl, http.client, requests or httpx, and a test asserts it.

Use

# inspect a labelled set before measuring with it
phocinae-formulate doctor --gold fixtures/safety-53.gold.jsonl

# measure recorded predictions
phocinae-formulate analyze --gold gold.jsonl --predictions preds.jsonl --json

# replay a shipped fixture and check it against an expectation
phocinae-formulate replay --fixture safety-53 \
    --expect fixtures/replay-0.1.2.expect.json --fixture-path fixtures

Exit codes, and why they are not collapsed:

code meaning
0 ran, no finding
1 ran, a finding exists — some formulation must not be used
2 usage error
3 input data error (schema, duplicate id, inconsistent gold)
4 empty scan — nothing decidable to measure
5 an --expect assertion failed
6 skipped — the decision service was not reachable

Priority is fixed and total: 6 > 4 > 3 > 2 > 5 > 1 > 0.

Two of these are worth explaining:

  • 1 is a finding, not a failure. A replay of replay-0.1.2 exits 1 with every assertion passing, because the thing it found is "do not use the boolean formulation". CI should accept {0, 1}.
  • 1 is driven by any formulation, not the winner. If only the winner counted, a run where the boolean fails and the choice form succeeds would exit 0 — and "do not use the boolean" is exactly the finding that would vanish.

What it measures

For every formulation: recall, missed-allow, model false-block, specificity, accuracy, precision, calibration (ECE) with a per-bucket breakdown, confidence percentiles, and a tau sweep.

Three gates decide whether a formulation is usable:

gate fails when
G-recall it does not stop at least 90% of what should be stopped
G-base it flags more than half of routine work, so a human reviews everything
G-power there were fewer than 10 positives, so the measurement means nothing

G-power matters more than it looks. A recall of 0.00 over two positives is not the same claim as a recall of 0.00 over thirty-one, and a tool that reports both identically is lying about one of them.

Undefined is not zero

Where a metric cannot be computed it is null, never 0:

  • no positives → recall is null (there was nothing to catch), not 0.0
  • no negatives → false-block is null
  • no recorded confidence → ECE is null, and those records are counted as confidence_missing rather than treated as confidence zero

The first distinction is the difference between "this formulation caught nothing" and "there was nothing to catch". Collapsing them blames a formulation for a property of the dataset.

Choosing tau

tau is the confidence below which an answer is escalated to a larger model. Measured, it is the most valuable thing the model does — at tau 0.6, 45% of decisions escalate, LLM calls drop 55%, and accuracy on what stays local rises from 0.906 to 0.9936.

So the tool does not hard-code it. It sweeps a grid and reports every viable point. A threshold is only viable if it keeps at least 10 answers, escalates no more than 60%, and keeps recall at 0.90 or better. Escalating nothing is not a threshold — it reports the model's raw behaviour under a new name and would always look best, so degenerate points are listed separately.

Escalation never launders a positive: deploy_recall counts a flagged command as stopped whether it was kept locally or escalated, because the gate is fail-closed.

Comparing formulations

mean confidence is not comparable across formulations: a noul question has a 2-way denominator, a three-way choice has 3, and a 2–10 scale has 9. The report says so (cross_k_comparable: false) and prints options_k per formulation rather than inviting the comparison.

Why it runs offline

The tool's job is to measure, so it must work in CI, where there is no decision service. --scan against a live service is how a new formulation gets measured; analyze and replay work entirely from recorded answers, and the analysis code is the same for both.

A predictions file may not claim to be a measurement it is not: every record carries provenance.kind, a file with no header is refused, and synthetic provenance (used by the tests) is rejected unless you pass --allow-synthetic deliberately.

The shipped fixture

fixtures/safety-53.* holds one recorded run of 53 labelled commands, and the four formulations derived from it. Two are re-analyses rather than fresh runs, and each file records which:

  • tri-choice — the tri-state mode as recorded.
  • bool-positive — the boolean mode as recorded (threshold 0.8): the 0.1.2 defect.
  • bool-threshold-0.5 — the boolean mode's own score distribution re-cut at 0.5. Sound because the server's noul answer is a thresholded probability and the raw probability is preserved in optionScores.
  • bool-negated — the same scores with the flag polarity inverted.

There is deliberately no 2–10 scale fixture: the recorded run emits a two-bucket distribution, and a nine-bucket one cannot be derived from it without fabricating it.

Testing

python tests/test_formulate.py

No network, no service, no third-party packages. The runner exits non-zero when zero assertions ran. Tests never use tempfile (scratch goes to $PHOCINAE_FORMULATE_TMP), and several cases run deliberately broken input and require the suite to notice.

What this is not

It is not a runtime gate and it does not sit in your request path — for that, see phocinae-rulepack for deterministic rules and dsh-phocinae for the gate itself. It reaches no compliance, legal or safety conclusion; it reports which question to ask.

License

Apache-2.0.

Metadata

Release files for phocinae-formulate 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for phocinae-formulate 0.1.0
File Size Uploaded Provenance
phocinae_formulate-0.1.0.tar.gz 40.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for phocinae-formulate 0.1.0
File Interpreter ABI Platform
phocinae_formulate-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 75.2 kB

Release files / phocinae_formulate-0.1.0.tar.gz

Download URL phocinae_formulate-0.1.0.tar.gz
Size 40.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6d31be7923ab13d349c2365b9f78616719d9b259241be80a4bde4d29f1300980
BLAKE2b-256 checksum
How to use checksums
5b34c47873fcd1c69533c8e7400b3b44c9a653ed89a1a8a54dca8644d190cf32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / phocinae_formulate-0.1.0-py3-none-any.whl

Download URL phocinae_formulate-0.1.0-py3-none-any.whl
Size 34.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ced1ba9a70b9f9355004dd20cc25842aea1bbaf73e9e21731a28b8cb15a0e4d
BLAKE2b-256 checksum
How to use checksums
2a6d72d990e126f2b7382f324d56fcd79930ba01a10a2878b4b70b8bf1ca642a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Security for phocinae-formulate 0.1.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page