supposing 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. supposing-0.1.0/.gitignore +12 -0
  2. supposing-0.1.0/CHANGELOG.md +18 -0
  3. supposing-0.1.0/LICENSE +202 -0
  4. supposing-0.1.0/NOTICE +4 -0
  5. supposing-0.1.0/PKG-INFO +178 -0
  6. supposing-0.1.0/README.md +149 -0
  7. supposing-0.1.0/examples/custom_judge.py +36 -0
  8. supposing-0.1.0/examples/quickstart.py +34 -0
  9. supposing-0.1.0/examples/resume.py +24 -0
  10. supposing-0.1.0/examples/state_machine.py +60 -0
  11. supposing-0.1.0/pyproject.toml +69 -0
  12. supposing-0.1.0/src/supposing/__init__.py +54 -0
  13. supposing-0.1.0/src/supposing/cli/__init__.py +232 -0
  14. supposing-0.1.0/src/supposing/cli/__main__.py +5 -0
  15. supposing-0.1.0/src/supposing/cli/billing.py +148 -0
  16. supposing-0.1.0/src/supposing/cli/cloud.py +328 -0
  17. supposing-0.1.0/src/supposing/cli/local.py +123 -0
  18. supposing-0.1.0/src/supposing/cli/output.py +128 -0
  19. supposing-0.1.0/src/supposing/cli/shared.py +51 -0
  20. supposing-0.1.0/src/supposing/cloud/__init__.py +39 -0
  21. supposing-0.1.0/src/supposing/cloud/client.py +731 -0
  22. supposing-0.1.0/src/supposing/cloud/config.py +70 -0
  23. supposing-0.1.0/src/supposing/cloud/errors.py +77 -0
  24. supposing-0.1.0/src/supposing/cloud/folder.py +33 -0
  25. supposing-0.1.0/src/supposing/cloud/models.py +345 -0
  26. supposing-0.1.0/src/supposing/cloud/records.py +116 -0
  27. supposing-0.1.0/src/supposing/judge.py +105 -0
  28. supposing-0.1.0/src/supposing/mcp_server.py +513 -0
  29. supposing-0.1.0/src/supposing/present.py +109 -0
  30. supposing-0.1.0/src/supposing/providers/__init__.py +44 -0
  31. supposing-0.1.0/src/supposing/providers/anthropic.py +77 -0
  32. supposing-0.1.0/src/supposing/providers/base.py +39 -0
  33. supposing-0.1.0/src/supposing/providers/claude_cli.py +81 -0
  34. supposing-0.1.0/src/supposing/providers/mock.py +63 -0
  35. supposing-0.1.0/src/supposing/providers/openai_compat.py +101 -0
  36. supposing-0.1.0/src/supposing/py.typed +0 -0
  37. supposing-0.1.0/src/supposing/ranking.py +346 -0
  38. supposing-0.1.0/src/supposing/rating.py +251 -0
  39. supposing-0.1.0/src/supposing/report.py +180 -0
  40. supposing-0.1.0/src/supposing/rubric.py +149 -0
  41. supposing-0.1.0/src/supposing/runner.py +182 -0
  42. supposing-0.1.0/src/supposing/samples.json +230 -0
  43. supposing-0.1.0/src/supposing/samples.py +46 -0
  44. supposing-0.1.0/src/supposing/scheduler.py +101 -0
  45. supposing-0.1.0/src/supposing/store.py +92 -0
  46. supposing-0.1.0/tests/conftest.py +3 -0
  47. supposing-0.1.0/tests/fake_api.py +168 -0
  48. supposing-0.1.0/tests/test_cli.py +426 -0
  49. supposing-0.1.0/tests/test_cloud_client.py +188 -0
  50. supposing-0.1.0/tests/test_examples.py +19 -0
  51. supposing-0.1.0/tests/test_mcp_server.py +84 -0
  52. supposing-0.1.0/tests/test_present.py +46 -0
  53. supposing-0.1.0/tests/test_ranking.py +124 -0
  54. supposing-0.1.0/tests/test_report.py +137 -0
  55. supposing-0.1.0/tests/test_rubric.py +75 -0
  56. supposing-0.1.0/tests/test_samples.py +26 -0
  57. supposing-0.1.0/tests/test_spend_cap.py +46 -0
  58. supposing-0.1.0/tests/test_statistics.py +370 -0
@@ -0,0 +1,12 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ .DS_Store
10
+ *.db
11
+ *.db-shm
12
+ *.db-wal
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2026-11-22)
4
+
5
+ First public release.
6
+
7
+ - `rank` and `run_ranking`: pairwise tournaments with an LLM judge, Bradley-Terry ratings and 90% bootstrap intervals on rating and rank.
8
+ - Swiss, random and round-robin pairing; both-order judging to cancel position bias; top-N runs that stop when the cut is settled.
9
+ - `supposing.ranking`: the run as a pure state machine (`next_action`, `plan_round`, `results`) for job queues and many workers.
10
+ - Plain-words results: `summarize` (the verdict sentence), `tiers`, and graded judge checks in `diagnostics["reliability"]`.
11
+ - `Rubric`: criteria with weights and judge instructions, saved as Markdown or JSON.
12
+ - Providers: OpenRouter, Anthropic, any OpenAI-compatible API, the local Claude Code CLI, and a free mock judge.
13
+ - Resumable runs in one SQLite file (`SQLiteStore`).
14
+ - `max_cost_usd` is a hard spend cap: no call starts that could take spend past it.
15
+ - `supposing.samples`: two sample datasets we wrote (twelve short stories; thirty invented grant applications).
16
+ - `supposing` command line: `rank` a folder locally, or `run` it on Supposing Cloud.
17
+ - `supposing.cloud`: a Python client for the Supposing Cloud API.
18
+ - `supposing mcp`: a stdio MCP server for coding agents (`pip install "supposing[mcp]"`).
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
supposing-0.1.0/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ Supposing
2
+ Copyright 2026 The Supposing Authors
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE).
@@ -0,0 +1,178 @@
1
+ Metadata-Version: 2.5
2
+ Name: supposing
3
+ Version: 0.1.0
4
+ Summary: Rank documents with LLM judges: pairwise tournaments with confidence intervals.
5
+ Project-URL: Homepage, https://supposing.app
6
+ Project-URL: Documentation, https://app.supposing.app/docs
7
+ Project-URL: Source, https://github.com/simulplatform-ai/supposing
8
+ Project-URL: Changelog, https://github.com/simulplatform-ai/supposing/blob/main/CHANGELOG.md
9
+ Author: The Supposing Authors
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ License-File: NOTICE
13
+ Keywords: bradley-terry,evaluation,llm,llm-as-a-judge,pairwise-comparison,ranking
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.12
24
+ Requires-Dist: httpx>=0.27
25
+ Requires-Dist: numpy>=2.1
26
+ Provides-Extra: mcp
27
+ Requires-Dist: mcp>=2.3; extra == 'mcp'
28
+ Description-Content-Type: text/markdown
29
+
30
+ # supposing
31
+
32
+ Rank documents with LLM judges. A model compares the documents two at a time against a rubric you write in plain words, and the verdicts are combined into a ranking with confidence intervals.
33
+
34
+ ```sh
35
+ pip install supposing
36
+ ```
37
+
38
+ Documentation: [app.supposing.app/docs](https://app.supposing.app/docs). The same package has a client and command line for Supposing Cloud (`supposing run`, `supposing.cloud`) and a stdio MCP server for coding agents (`pip install "supposing[mcp]"`, then `supposing mcp`).
39
+
40
+ ## Try it in a minute, with no API key
41
+
42
+ The `mock` provider is a free, deterministic fake judge. It prefers whichever text carries the higher hidden `[[q=...]]` score, with some noise, so you can see the whole thing work before spending anything.
43
+
44
+ ```python
45
+ from supposing import rank
46
+
47
+ ranking = rank(
48
+ {"a.md": "First draft. [[q=0.2]]", "b.md": "Second draft. [[q=0.9]]", "c.md": "Third draft. [[q=0.5]]"},
49
+ "Which draft makes the strongest case for funding?",
50
+ provider="mock",
51
+ )
52
+ for row in ranking.leaderboard:
53
+ print(row["rank"], row["item_id"], row["rating"], row["rank_lo"], row["rank_hi"])
54
+ ```
55
+
56
+ Or from the command line, on a folder with one document per `.md`, `.txt` or `.html` file:
57
+
58
+ ```sh
59
+ supposing rank ./proposals --rubric "Which proposal makes the strongest case for funding?" --provider mock
60
+ ```
61
+
62
+ ```
63
+ p3.md ranks first, but any of the top 2 could be first. 3 clear tiers. Treat with care: the judge often changed its mind when the two texts swapped places (same winner in both orders 69%; 1 more check is poor). Read some comparisons before relying on this ranking.
64
+
65
+ rank could be rating 90% interval won-lost item
66
+ 1 1-2 1826 1746 to 1875 11-5 p3.md
67
+ 2 1-2 1819 1738 to 1858 11-5 p4.md
68
+ 3 3 1444 1362 to 1547 10-6 p2.md
69
+ 4 4 911 857 to 1027 0-16 p1.md
70
+ ```
71
+
72
+ The mock judge is noisy on purpose, and the result says so: the warning comes from the judge checks, and appears whenever a real judge is that inconsistent too.
73
+
74
+ No documents to hand? `supposing.samples` has two datasets to try: `samples.items("stories")` (twelve short pieces) and `samples.items("grants")` (thirty invented applications to a small community fund, from vague to well evidenced), each with a suggested rubric in `samples.load(id)["rubric"]`.
75
+
76
+ More in [`examples/`](https://github.com/simulplatform-ai/supposing/tree/main/examples): resuming a run, driving it step by step, and writing your own judge. Each one runs with `python examples/<name>.py` and no key.
77
+
78
+ ## Real judges
79
+
80
+ | `provider` | Needs |
81
+ |---|---|
82
+ | `openrouter` (default) | `OPENROUTER_API_KEY`; `model` is any OpenRouter model id |
83
+ | `anthropic` | `ANTHROPIC_API_KEY` |
84
+ | `openai_compat` | `base_url`, for Ollama, vLLM, LM Studio or OpenAI |
85
+ | `claude_cli` | Claude Code installed and logged in; for local use |
86
+ | `mock` | Nothing |
87
+
88
+ ```python
89
+ ranking = rank(docs, rubric, model="anthropic/claude-haiku-5.5") # OpenRouter
90
+ ```
91
+
92
+ Know the cost before you start. A run makes at most `planned_calls(n_items, RankConfig(...))` judge calls: by default 8 rounds × (n ÷ 2) pairs × 2 orders, so 8 calls per document. `supposing rank ... --dry-run` prints the estimate and stops, and `max_cost_usd` (`--max-cost`) is a hard cap: no call starts that could take recorded spend past it (each call is assumed to cost as much as the dearest so far), and the run's note says when the cap ended it. Providers that don't report prices, such as `claude_cli`, can't be capped.
93
+
94
+ ## Rubrics
95
+
96
+ A rubric is what the judge should prefer, in plain words. A string is enough. To keep one in a file, weight its parts, or add instructions for the judge, use a `Rubric`:
97
+
98
+ ```markdown
99
+ # Grant proposals
100
+
101
+ Which proposal makes the strongest case for funding?
102
+
103
+ ## Criteria
104
+
105
+ - Impact (weight 2): how many people benefit, and how much.
106
+ - Feasibility: can this team do it with this budget?
107
+
108
+ ## Judge instructions
109
+
110
+ Ignore formatting and spelling.
111
+ ```
112
+
113
+ ```python
114
+ from supposing import Rubric, rank
115
+
116
+ ranking = rank(docs, Rubric.load("grants.md"))
117
+ ```
118
+
119
+ Every part but the text is optional, so any Markdown or text file is a rubric. `Rubric.save` writes Markdown, or JSON for a `.json` path. The judge sees the criteria and their weights in its prompt and still returns one verdict per comparison; weights say what matters more, they do not score criteria separately.
120
+
121
+ ## Reading the result
122
+
123
+ `ranking.summary` is the verdict in one plain sentence, such as "repair-cafe is first, clearly. 4 clear tiers." A tier is a group of items whose rank ranges overlap, so the judge cannot reliably order them; `supposing.tiers(leaderboard)` returns them. When a judge check is poor, the summary adds one sentence of warning.
124
+
125
+ `ranking.leaderboard` is sorted best first. Each row has:
126
+
127
+ - `rating`: on an Elo-like scale. The average is 1500, and a 400-point gap means the judge prefers the higher item about 10 times out of 11.
128
+ - `rating_lo`, `rating_hi`: the 90% interval for the rating.
129
+ - `rank_lo`, `rank_hi`: the ranks the item holds with 90% confidence. **Items whose rank ranges overlap are not reliably different.** Report them as a tie, or add rounds.
130
+ - `wins`, `losses`, and `p_top_n` (the chance of being in the top N) for top-N runs.
131
+
132
+ `ranking.diagnostics` says how far the judge can be trusted:
133
+
134
+ - `order_consistency`: the share of pairs with the same winner in both orders. Low means the judge often cannot tell the two apart, or is swayed by position.
135
+ - `first_position_win_rate`: near 0.5 is good. Both-order judging cancels this bias in the ranking, but a high value still means noisy verdicts.
136
+ - `split_half_reliability`: how well two halves of the verdicts agree on the order (Spearman). Near 1 is stable.
137
+ - `length_correlation`: whether longer documents tend to rank higher.
138
+ - `upsets`: verdicts that contradict the final ranking most strongly. Read a few.
139
+ - `first_shown_won_both`, `second_shown_won_both`: among pairs judged in both orders, the share where the same position won both times. A gap between the two is position bias.
140
+ - `reliability`: the checks above graded Good, Caution or Poor, with one plain sentence (`reliability["line"]`) to show beside the ranking. Thresholds are rules of thumb, not tests.
141
+
142
+ These checks say whether the judge is consistent. They cannot say whether its taste is right. Read some verdicts (`ranking.comparisons`, each with `reasoning`) before trusting a ranking.
143
+
144
+ ## How it works
145
+
146
+ - **Swiss rounds.** Each round pairs every document once, with an opponent of similar current rating, where a verdict is informative. A pair meets again only when no round without rematches exists.
147
+ - **Round robin** (`pairing="round_robin"`) is for a handful of options: every pair is planned in the first round, so all the calls can run at once. n options make n(n-1)/2 pairs (28 for 8), so one round is usually enough.
148
+ - **Both orders.** Each pair is judged twice with the order swapped, so every document is shown first exactly as often as second. This cancels the judge's tendency to favour one position.
149
+ - **Bradley-Terry ratings** fitted to all verdicts at once, so the result does not depend on the order the calls finished in. A weak prior (half a win and half a loss against an average opponent) keeps an unbeaten document's rating finite.
150
+ - **Intervals** come from a bootstrap over pairs: refit on resampled pairs a few hundred times and take the middle 90%.
151
+ - **Top-N mode** (`goal="top_n", top_n=10`) ranks everything for three rounds. After that it judges only the documents whose side of the cut is still open (a chance of making the top N between 5% and 95%, checked after each of the last two rounds), plus the nearest settled document on either side as a reference, and stops when none is open. `ranking.calls_saved` says how many calls that saved against the fixed plan. In simulations with 30 to 100 documents it used 45-53% of a full ranking's calls and found the true top N as often.
152
+ - **Resumable.** With a `SQLiteStore` (`--state run.db` on the command line), every verdict is saved as it arrives. Run the same command again and it continues; nothing already decided is judged again.
153
+
154
+ ### What the tests show
155
+
156
+ `tests/test_statistics.py` plants a known order, simulates a judge that follows it with noise, and checks what comes back (the many-trial coverage and top-N simulations are marked `stats`; run them with `pytest -m stats`):
157
+
158
+ - The planted order is recovered, and with enough verdicts the planted ratings too.
159
+ - The 90% intervals contain the planted rating 80-97% of the time on evenly spread and on closely matched collections, and the rank ranges at least 80-85%.
160
+ - A judge that favours the first text strongly (82% first-position wins between equals) still gives the planted order, and the diagnostics report the bias.
161
+ - Pairing never repeats a pair while a round without rematches exists, and byes rotate.
162
+ - A run stopped at any point and resumed from its file gives exactly the same result as an uninterrupted one.
163
+
164
+ **Known limit.** When a document wins or loses nearly every comparison, the data cannot say how far ahead it is, and the prior pulls its rating toward the middle. Its rating interval may then sit too close to the middle. The error is in the safe direction (the gap is understated), and its rank range is still reliable.
165
+
166
+ ## Building on the engine
167
+
168
+ `supposing.ranking` is a pure state machine with no I/O. `next_action(comparisons, config, n_items)` says whether to judge the pending comparisons, plan the next round, or stop; `plan_round(...)` produces the next round deterministically; `results(...)` fits the ranking. Any process holding the comparison rows can continue a run, so you can run it from a job queue or across many workers ([`examples/state_machine.py`](https://github.com/simulplatform-ai/supposing/blob/main/examples/state_machine.py)).
169
+
170
+ - Keep runs anywhere by implementing the three-method `RunStore` protocol (`load`, `add`, `update`).
171
+ - Use any judge by implementing the two-method `Provider` protocol (`complete`, `close`; [`examples/custom_judge.py`](https://github.com/simulplatform-ai/supposing/blob/main/examples/custom_judge.py)).
172
+ - `SYSTEM_PROMPT` is exactly what the judge is told.
173
+
174
+ Public names are those in `supposing.__all__`; everything else may change.
175
+
176
+ ## Licence
177
+
178
+ Apache License 2.0. See [LICENSE](https://github.com/simulplatform-ai/supposing/blob/main/LICENSE) and [NOTICE](https://github.com/simulplatform-ai/supposing/blob/main/NOTICE).
@@ -0,0 +1,149 @@
1
+ # supposing
2
+
3
+ Rank documents with LLM judges. A model compares the documents two at a time against a rubric you write in plain words, and the verdicts are combined into a ranking with confidence intervals.
4
+
5
+ ```sh
6
+ pip install supposing
7
+ ```
8
+
9
+ Documentation: [app.supposing.app/docs](https://app.supposing.app/docs). The same package has a client and command line for Supposing Cloud (`supposing run`, `supposing.cloud`) and a stdio MCP server for coding agents (`pip install "supposing[mcp]"`, then `supposing mcp`).
10
+
11
+ ## Try it in a minute, with no API key
12
+
13
+ The `mock` provider is a free, deterministic fake judge. It prefers whichever text carries the higher hidden `[[q=...]]` score, with some noise, so you can see the whole thing work before spending anything.
14
+
15
+ ```python
16
+ from supposing import rank
17
+
18
+ ranking = rank(
19
+ {"a.md": "First draft. [[q=0.2]]", "b.md": "Second draft. [[q=0.9]]", "c.md": "Third draft. [[q=0.5]]"},
20
+ "Which draft makes the strongest case for funding?",
21
+ provider="mock",
22
+ )
23
+ for row in ranking.leaderboard:
24
+ print(row["rank"], row["item_id"], row["rating"], row["rank_lo"], row["rank_hi"])
25
+ ```
26
+
27
+ Or from the command line, on a folder with one document per `.md`, `.txt` or `.html` file:
28
+
29
+ ```sh
30
+ supposing rank ./proposals --rubric "Which proposal makes the strongest case for funding?" --provider mock
31
+ ```
32
+
33
+ ```
34
+ p3.md ranks first, but any of the top 2 could be first. 3 clear tiers. Treat with care: the judge often changed its mind when the two texts swapped places (same winner in both orders 69%; 1 more check is poor). Read some comparisons before relying on this ranking.
35
+
36
+ rank could be rating 90% interval won-lost item
37
+ 1 1-2 1826 1746 to 1875 11-5 p3.md
38
+ 2 1-2 1819 1738 to 1858 11-5 p4.md
39
+ 3 3 1444 1362 to 1547 10-6 p2.md
40
+ 4 4 911 857 to 1027 0-16 p1.md
41
+ ```
42
+
43
+ The mock judge is noisy on purpose, and the result says so: the warning comes from the judge checks, and appears whenever a real judge is that inconsistent too.
44
+
45
+ No documents to hand? `supposing.samples` has two datasets to try: `samples.items("stories")` (twelve short pieces) and `samples.items("grants")` (thirty invented applications to a small community fund, from vague to well evidenced), each with a suggested rubric in `samples.load(id)["rubric"]`.
46
+
47
+ More in [`examples/`](https://github.com/simulplatform-ai/supposing/tree/main/examples): resuming a run, driving it step by step, and writing your own judge. Each one runs with `python examples/<name>.py` and no key.
48
+
49
+ ## Real judges
50
+
51
+ | `provider` | Needs |
52
+ |---|---|
53
+ | `openrouter` (default) | `OPENROUTER_API_KEY`; `model` is any OpenRouter model id |
54
+ | `anthropic` | `ANTHROPIC_API_KEY` |
55
+ | `openai_compat` | `base_url`, for Ollama, vLLM, LM Studio or OpenAI |
56
+ | `claude_cli` | Claude Code installed and logged in; for local use |
57
+ | `mock` | Nothing |
58
+
59
+ ```python
60
+ ranking = rank(docs, rubric, model="anthropic/claude-haiku-5.5") # OpenRouter
61
+ ```
62
+
63
+ Know the cost before you start. A run makes at most `planned_calls(n_items, RankConfig(...))` judge calls: by default 8 rounds × (n ÷ 2) pairs × 2 orders, so 8 calls per document. `supposing rank ... --dry-run` prints the estimate and stops, and `max_cost_usd` (`--max-cost`) is a hard cap: no call starts that could take recorded spend past it (each call is assumed to cost as much as the dearest so far), and the run's note says when the cap ended it. Providers that don't report prices, such as `claude_cli`, can't be capped.
64
+
65
+ ## Rubrics
66
+
67
+ A rubric is what the judge should prefer, in plain words. A string is enough. To keep one in a file, weight its parts, or add instructions for the judge, use a `Rubric`:
68
+
69
+ ```markdown
70
+ # Grant proposals
71
+
72
+ Which proposal makes the strongest case for funding?
73
+
74
+ ## Criteria
75
+
76
+ - Impact (weight 2): how many people benefit, and how much.
77
+ - Feasibility: can this team do it with this budget?
78
+
79
+ ## Judge instructions
80
+
81
+ Ignore formatting and spelling.
82
+ ```
83
+
84
+ ```python
85
+ from supposing import Rubric, rank
86
+
87
+ ranking = rank(docs, Rubric.load("grants.md"))
88
+ ```
89
+
90
+ Every part but the text is optional, so any Markdown or text file is a rubric. `Rubric.save` writes Markdown, or JSON for a `.json` path. The judge sees the criteria and their weights in its prompt and still returns one verdict per comparison; weights say what matters more, they do not score criteria separately.
91
+
92
+ ## Reading the result
93
+
94
+ `ranking.summary` is the verdict in one plain sentence, such as "repair-cafe is first, clearly. 4 clear tiers." A tier is a group of items whose rank ranges overlap, so the judge cannot reliably order them; `supposing.tiers(leaderboard)` returns them. When a judge check is poor, the summary adds one sentence of warning.
95
+
96
+ `ranking.leaderboard` is sorted best first. Each row has:
97
+
98
+ - `rating`: on an Elo-like scale. The average is 1500, and a 400-point gap means the judge prefers the higher item about 10 times out of 11.
99
+ - `rating_lo`, `rating_hi`: the 90% interval for the rating.
100
+ - `rank_lo`, `rank_hi`: the ranks the item holds with 90% confidence. **Items whose rank ranges overlap are not reliably different.** Report them as a tie, or add rounds.
101
+ - `wins`, `losses`, and `p_top_n` (the chance of being in the top N) for top-N runs.
102
+
103
+ `ranking.diagnostics` says how far the judge can be trusted:
104
+
105
+ - `order_consistency`: the share of pairs with the same winner in both orders. Low means the judge often cannot tell the two apart, or is swayed by position.
106
+ - `first_position_win_rate`: near 0.5 is good. Both-order judging cancels this bias in the ranking, but a high value still means noisy verdicts.
107
+ - `split_half_reliability`: how well two halves of the verdicts agree on the order (Spearman). Near 1 is stable.
108
+ - `length_correlation`: whether longer documents tend to rank higher.
109
+ - `upsets`: verdicts that contradict the final ranking most strongly. Read a few.
110
+ - `first_shown_won_both`, `second_shown_won_both`: among pairs judged in both orders, the share where the same position won both times. A gap between the two is position bias.
111
+ - `reliability`: the checks above graded Good, Caution or Poor, with one plain sentence (`reliability["line"]`) to show beside the ranking. Thresholds are rules of thumb, not tests.
112
+
113
+ These checks say whether the judge is consistent. They cannot say whether its taste is right. Read some verdicts (`ranking.comparisons`, each with `reasoning`) before trusting a ranking.
114
+
115
+ ## How it works
116
+
117
+ - **Swiss rounds.** Each round pairs every document once, with an opponent of similar current rating, where a verdict is informative. A pair meets again only when no round without rematches exists.
118
+ - **Round robin** (`pairing="round_robin"`) is for a handful of options: every pair is planned in the first round, so all the calls can run at once. n options make n(n-1)/2 pairs (28 for 8), so one round is usually enough.
119
+ - **Both orders.** Each pair is judged twice with the order swapped, so every document is shown first exactly as often as second. This cancels the judge's tendency to favour one position.
120
+ - **Bradley-Terry ratings** fitted to all verdicts at once, so the result does not depend on the order the calls finished in. A weak prior (half a win and half a loss against an average opponent) keeps an unbeaten document's rating finite.
121
+ - **Intervals** come from a bootstrap over pairs: refit on resampled pairs a few hundred times and take the middle 90%.
122
+ - **Top-N mode** (`goal="top_n", top_n=10`) ranks everything for three rounds. After that it judges only the documents whose side of the cut is still open (a chance of making the top N between 5% and 95%, checked after each of the last two rounds), plus the nearest settled document on either side as a reference, and stops when none is open. `ranking.calls_saved` says how many calls that saved against the fixed plan. In simulations with 30 to 100 documents it used 45-53% of a full ranking's calls and found the true top N as often.
123
+ - **Resumable.** With a `SQLiteStore` (`--state run.db` on the command line), every verdict is saved as it arrives. Run the same command again and it continues; nothing already decided is judged again.
124
+
125
+ ### What the tests show
126
+
127
+ `tests/test_statistics.py` plants a known order, simulates a judge that follows it with noise, and checks what comes back (the many-trial coverage and top-N simulations are marked `stats`; run them with `pytest -m stats`):
128
+
129
+ - The planted order is recovered, and with enough verdicts the planted ratings too.
130
+ - The 90% intervals contain the planted rating 80-97% of the time on evenly spread and on closely matched collections, and the rank ranges at least 80-85%.
131
+ - A judge that favours the first text strongly (82% first-position wins between equals) still gives the planted order, and the diagnostics report the bias.
132
+ - Pairing never repeats a pair while a round without rematches exists, and byes rotate.
133
+ - A run stopped at any point and resumed from its file gives exactly the same result as an uninterrupted one.
134
+
135
+ **Known limit.** When a document wins or loses nearly every comparison, the data cannot say how far ahead it is, and the prior pulls its rating toward the middle. Its rating interval may then sit too close to the middle. The error is in the safe direction (the gap is understated), and its rank range is still reliable.
136
+
137
+ ## Building on the engine
138
+
139
+ `supposing.ranking` is a pure state machine with no I/O. `next_action(comparisons, config, n_items)` says whether to judge the pending comparisons, plan the next round, or stop; `plan_round(...)` produces the next round deterministically; `results(...)` fits the ranking. Any process holding the comparison rows can continue a run, so you can run it from a job queue or across many workers ([`examples/state_machine.py`](https://github.com/simulplatform-ai/supposing/blob/main/examples/state_machine.py)).
140
+
141
+ - Keep runs anywhere by implementing the three-method `RunStore` protocol (`load`, `add`, `update`).
142
+ - Use any judge by implementing the two-method `Provider` protocol (`complete`, `close`; [`examples/custom_judge.py`](https://github.com/simulplatform-ai/supposing/blob/main/examples/custom_judge.py)).
143
+ - `SYSTEM_PROMPT` is exactly what the judge is told.
144
+
145
+ Public names are those in `supposing.__all__`; everything else may change.
146
+
147
+ ## Licence
148
+
149
+ Apache License 2.0. See [LICENSE](https://github.com/simulplatform-ai/supposing/blob/main/LICENSE) and [NOTICE](https://github.com/simulplatform-ai/supposing/blob/main/NOTICE).
@@ -0,0 +1,36 @@
1
+ """Plug in your own judge by implementing the two-method ``Provider`` protocol.
2
+
3
+ python examples/custom_judge.py
4
+
5
+ Anything that turns a system prompt and a user prompt into text can judge: a model behind your own gateway,
6
+ a rules engine, or a human in a loop. This one prefers the shorter text, and answers in the JSON shape the
7
+ judge prompt asks for.
8
+ """
9
+ import json
10
+ import re
11
+
12
+ from supposing import Completion, rank
13
+
14
+
15
+ class ShorterIsBetter:
16
+ name = "shorter"
17
+ model = "rule"
18
+
19
+ async def complete(self, system: str, user: str) -> Completion:
20
+ a, b = re.findall(r"<text_[ab]>\n(.*?)\n</text_[ab]>", user, re.S)
21
+ winner = "A" if len(a) <= len(b) else "B"
22
+ return Completion(text=json.dumps({"reasoning": "Text %s is shorter." % winner, "winner": winner}))
23
+
24
+ async def close(self) -> None:
25
+ pass
26
+
27
+
28
+ answers = {
29
+ "terse": "Use a list.",
30
+ "medium": "A list works well here because order matters.",
31
+ "long": "There are several options, but on balance a list is the best fit, because order matters and "
32
+ "the collection is small.",
33
+ }
34
+ ranking = rank(answers, "Which answer is more concise?", provider=ShorterIsBetter(), rounds=3)
35
+ print([row["item_id"] for row in ranking.leaderboard])
36
+ assert ranking.leaderboard[0]["item_id"] == "terse"
@@ -0,0 +1,34 @@
1
+ """Rank five short pitches with the free mock judge. No API key, no network.
2
+
3
+ python examples/quickstart.py
4
+
5
+ The mock judge is a fake: it prefers whichever text carries the higher hidden ``[[q=...]]`` score, with some
6
+ noise, so you can see the machinery work. Swap ``provider="mock"`` for a real one (see the README) to rank
7
+ by an actual model's judgment.
8
+ """
9
+ from supposing import rank
10
+
11
+ pitches = {
12
+ "bakery": "A neighbourhood bakery that sells yesterday's bread at half price. [[q=0.35]]",
13
+ "tutoring": "Peer tutoring for first-year students, run by second-years for credit. [[q=0.70]]",
14
+ "repair-cafe": "A monthly repair cafe where volunteers fix appliances for free. [[q=0.80]]",
15
+ "app": "An app that reminds you to drink water. [[q=0.15]]",
16
+ "library": "A tool library: borrow a drill instead of buying one. [[q=0.60]]",
17
+ }
18
+
19
+ ranking = rank(pitches, "Which project would do the most good for the neighbourhood per dollar?",
20
+ provider="mock", rounds=6)
21
+
22
+ print(ranking.summary)
23
+ print()
24
+ print("rank item rating 90% interval rank range")
25
+ for row in ranking.leaderboard:
26
+ print("%4d %-12s %7.0f [%5.0f, %5.0f] %d-%d" % (
27
+ row["rank"], row["item_id"], row["rating"], row["rating_lo"], row["rating_hi"], row["rank_lo"],
28
+ row["rank_hi"]))
29
+ print()
30
+ print("judge calls:", len(ranking.comparisons))
31
+ print("judge checks:", ranking.diagnostics["reliability"]["line"])
32
+ best = ranking.comparisons[0]
33
+ print("one verdict: %s beat %s. %s" % (best.winner_item, best.item_b if best.winner_item == best.item_a
34
+ else best.item_a, best.reasoning))