counterfix 0.2.0__tar.gz → 0.3.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 (140) hide show
  1. {counterfix-0.2.0 → counterfix-0.3.0}/CHANGELOG.md +148 -0
  2. {counterfix-0.2.0 → counterfix-0.3.0}/PKG-INFO +119 -230
  3. {counterfix-0.2.0 → counterfix-0.3.0}/README.md +91 -227
  4. {counterfix-0.2.0 → counterfix-0.3.0}/pyproject.toml +50 -9
  5. counterfix-0.3.0/src/counterfix/__init__.py +143 -0
  6. counterfix-0.3.0/src/counterfix/_compat.py +96 -0
  7. counterfix-0.3.0/src/counterfix/_internal/__init__.py +1 -0
  8. counterfix-0.3.0/src/counterfix/_internal/deprecation.py +57 -0
  9. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/_internal}/safe_eval.py +20 -4
  10. counterfix-0.3.0/src/counterfix/cli/__init__.py +206 -0
  11. counterfix-0.3.0/src/counterfix/cli/__main__.py +7 -0
  12. counterfix-0.3.0/src/counterfix/cli/calls.py +160 -0
  13. counterfix-0.3.0/src/counterfix/cli/common.py +107 -0
  14. counterfix-0.3.0/src/counterfix/cli/evaluate.py +186 -0
  15. counterfix-0.3.0/src/counterfix/cli/models.py +126 -0
  16. counterfix-0.3.0/src/counterfix/cli/setup.py +108 -0
  17. counterfix-0.2.0/src/counterfix/adapters/_attach.py → counterfix-0.3.0/src/counterfix/core/attach.py +14 -0
  18. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/core/caller.py +36 -2
  19. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/core/config.py +5 -11
  20. counterfix-0.3.0/src/counterfix/core/convert.py +245 -0
  21. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/core/diagnosis.py +4 -2
  22. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/core}/presets.py +8 -3
  23. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/data/profiles/openai_gpt-oss-120b.json +6 -6
  24. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/data/profiles/qwen2.5_3b.json +13 -11
  25. counterfix-0.3.0/src/counterfix/detect/__init__.py +123 -0
  26. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/detect}/agents.py +3 -3
  27. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/detect}/code/__init__.py +5 -5
  28. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/detect}/code/check.py +17 -3
  29. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/detect}/code/sandbox.py +3 -1
  30. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/detect}/confidence.py +7 -37
  31. {counterfix-0.2.0/src/counterfix/detectors → counterfix-0.3.0/src/counterfix/detect}/fmt.py +1 -1
  32. {counterfix-0.2.0/src/counterfix/detectors → counterfix-0.3.0/src/counterfix/detect}/fragility.py +1 -1
  33. {counterfix-0.2.0/src/counterfix/detectors → counterfix-0.3.0/src/counterfix/detect}/injection.py +1 -1
  34. counterfix-0.3.0/src/counterfix/detect/instructions/__init__.py +260 -0
  35. counterfix-0.3.0/src/counterfix/detect/instructions/constraint.py +112 -0
  36. counterfix-0.3.0/src/counterfix/detect/instructions/counts.py +135 -0
  37. counterfix-0.3.0/src/counterfix/detect/instructions/language.py +207 -0
  38. counterfix-0.3.0/src/counterfix/detect/instructions/reading.py +112 -0
  39. counterfix-0.3.0/src/counterfix/detect/instructions/wording.py +150 -0
  40. {counterfix-0.2.0/src/counterfix/detectors → counterfix-0.3.0/src/counterfix/detect}/judged.py +8 -8
  41. {counterfix-0.2.0/src/counterfix/detectors → counterfix-0.3.0/src/counterfix/detect}/rag.py +3 -3
  42. counterfix-0.2.0/src/counterfix/rag.py → counterfix-0.3.0/src/counterfix/detect/retrieval.py +3 -3
  43. {counterfix-0.2.0/src/counterfix/detectors → counterfix-0.3.0/src/counterfix/detect}/tools.py +4 -4
  44. {counterfix-0.2.0/src/counterfix/detectors → counterfix-0.3.0/src/counterfix/detect}/truncation.py +1 -1
  45. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/diagnose.py +4 -17
  46. counterfix-0.3.0/src/counterfix/evals/asking.py +118 -0
  47. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/benchmarks/__init__.py +15 -12
  48. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/benchmarks/evalplus.py +8 -8
  49. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/benchmarks/ifeval.py +1 -1
  50. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/benchmarks/injection.py +2 -2
  51. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/evals/data.py +5 -5
  52. counterfix-0.3.0/src/counterfix/evals/fixing.py +187 -0
  53. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/metrics/__init__.py +20 -17
  54. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/metrics/base.py +1 -1
  55. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/metrics/code.py +4 -4
  56. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/metrics/confidence.py +2 -2
  57. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/metrics/extract.py +2 -16
  58. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/metrics/rag.py +3 -3
  59. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/metrics/retrieval.py +5 -5
  60. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/metrics/safety.py +4 -4
  61. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/metrics/semantic.py +1 -1
  62. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/metrics/speed.py +1 -1
  63. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/metrics/structured.py +1 -1
  64. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/metrics/text.py +1 -1
  65. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/metrics/tools.py +1 -1
  66. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/perplexity.py +5 -2
  67. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/evals/report.py +3 -3
  68. counterfix-0.3.0/src/counterfix/evals/results.py +228 -0
  69. counterfix-0.3.0/src/counterfix/evals/runner.py +359 -0
  70. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/safety.py +16 -0
  71. counterfix-0.3.0/src/counterfix/evals/sampling.py +58 -0
  72. counterfix-0.3.0/src/counterfix/fixes/__init__.py +8 -0
  73. counterfix-0.3.0/src/counterfix/fixes/_profile_store.py +112 -0
  74. counterfix-0.3.0/src/counterfix/fixes/engine.py +283 -0
  75. counterfix-0.3.0/src/counterfix/fixes/interventions/__init__.py +53 -0
  76. counterfix-0.3.0/src/counterfix/fixes/interventions/base.py +64 -0
  77. counterfix-0.3.0/src/counterfix/fixes/interventions/code.py +106 -0
  78. counterfix-0.3.0/src/counterfix/fixes/interventions/injection.py +91 -0
  79. counterfix-0.3.0/src/counterfix/fixes/interventions/prompt.py +194 -0
  80. counterfix-0.3.0/src/counterfix/fixes/interventions/rag.py +123 -0
  81. counterfix-0.3.0/src/counterfix/fixes/interventions/tools.py +150 -0
  82. counterfix-0.3.0/src/counterfix/fixes/models.py +99 -0
  83. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/fixes}/profiles.py +14 -105
  84. counterfix-0.3.0/src/counterfix/fixes/verify.py +84 -0
  85. counterfix-0.3.0/src/counterfix/integrations/__init__.py +19 -0
  86. counterfix-0.3.0/src/counterfix/integrations/anthropic.py +21 -0
  87. {counterfix-0.2.0/src/counterfix/adapters → counterfix-0.3.0/src/counterfix/integrations}/callbacks.py +4 -3
  88. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/integrations}/capabilities.py +2 -2
  89. {counterfix-0.2.0/src/counterfix/adapters → counterfix-0.3.0/src/counterfix/integrations}/decorator.py +14 -4
  90. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/integrations}/mcp_server.py +9 -8
  91. counterfix-0.3.0/src/counterfix/integrations/openai_compat/__init__.py +165 -0
  92. counterfix-0.2.0/src/counterfix/adapters/openai_compat.py → counterfix-0.3.0/src/counterfix/integrations/openai_compat/guarded.py +17 -182
  93. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/integrations}/otel.py +5 -69
  94. {counterfix-0.2.0/src/counterfix/adapters → counterfix-0.3.0/src/counterfix/integrations}/streams.py +2 -2
  95. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/judges/auto.py +2 -2
  96. counterfix-0.3.0/src/counterfix/runtime/__init__.py +3 -0
  97. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/runtime}/context.py +2 -2
  98. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/runtime}/perf.py +56 -11
  99. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/runtime}/report.py +8 -3
  100. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/testing.py +2 -2
  101. counterfix-0.2.0/src/counterfix/__init__.py +0 -89
  102. counterfix-0.2.0/src/counterfix/adapters/__init__.py +0 -18
  103. counterfix-0.2.0/src/counterfix/adapters/anthropic.py +0 -113
  104. counterfix-0.2.0/src/counterfix/cli.py +0 -790
  105. counterfix-0.2.0/src/counterfix/detectors/__init__.py +0 -68
  106. counterfix-0.2.0/src/counterfix/detectors/instructions.py +0 -847
  107. counterfix-0.2.0/src/counterfix/engine.py +0 -931
  108. counterfix-0.2.0/src/counterfix/evals/runner.py +0 -825
  109. counterfix-0.2.0/src/counterfix/rules/__init__.py +0 -5
  110. {counterfix-0.2.0 → counterfix-0.3.0}/.gitignore +0 -0
  111. {counterfix-0.2.0 → counterfix-0.3.0}/LICENSE +0 -0
  112. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/__main__.py +0 -0
  113. /counterfix-0.2.0/src/counterfix/_suggest.py → /counterfix-0.3.0/src/counterfix/_internal/suggest.py +0 -0
  114. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/_internal}/text.py +0 -0
  115. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/core/__init__.py +0 -0
  116. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/core/detector.py +0 -0
  117. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/core/precedence.py +0 -0
  118. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/core/record.py +0 -0
  119. /counterfix-0.2.0/src/counterfix/rules/store.py → /counterfix-0.3.0/src/counterfix/core/rules.py +0 -0
  120. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/core/sync.py +0 -0
  121. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/core/types.py +0 -0
  122. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/data/probes.jsonl +0 -0
  123. {counterfix-0.2.0/src/counterfix/detectors → counterfix-0.3.0/src/counterfix/detect}/basic.py +0 -0
  124. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/detect}/code/passk.py +0 -0
  125. {counterfix-0.2.0/src/counterfix/detectors → counterfix-0.3.0/src/counterfix/detect}/refusal.py +0 -0
  126. {counterfix-0.2.0/src/counterfix/detectors → counterfix-0.3.0/src/counterfix/detect}/sampling.py +0 -0
  127. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/evals/__init__.py +0 -0
  128. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/evals}/benchmarks/tool_use.py +0 -0
  129. {counterfix-0.2.0/src/counterfix/adapters → counterfix-0.3.0/src/counterfix/integrations}/responses.py +0 -0
  130. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/judges/__init__.py +0 -0
  131. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/judges/base.py +0 -0
  132. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/judges/cache.py +0 -0
  133. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/judges/jev.py +0 -0
  134. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/judges/llm.py +0 -0
  135. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/judges/tasks.py +0 -0
  136. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/lint/__init__.py +0 -0
  137. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/lint/judged.py +0 -0
  138. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/lint/rules.py +0 -0
  139. {counterfix-0.2.0 → counterfix-0.3.0}/src/counterfix/py.typed +0 -0
  140. {counterfix-0.2.0/src/counterfix → counterfix-0.3.0/src/counterfix/runtime}/background.py +0 -0
@@ -2,6 +2,154 @@
2
2
 
3
3
  All notable changes to counterfix. Versions follow [semantic versioning](https://semver.org).
4
4
 
5
+ ## 0.3.0 (2026-11-12)
6
+
7
+ A smaller front door, a new layout, and a clearer job: counterfix finds out why an LLM
8
+ call failed and proves which fix works, alongside your evaluation and tracing tools rather
9
+ than in place of them. Nothing that worked in 0.2.1 stops working; see
10
+ [Migrating to 0.3](https://kansadwala.github.io/CounterFix/migrating/).
11
+
12
+ - A `MODEL@http://host/v1` model spec without the OpenAI SDK installed now says what to
13
+ install (`pip install "counterfix[openai]"`) instead of failing with a bare
14
+ `ModuleNotFoundError`, as `provider:model` specs already did.
15
+ - **Evaluation features that other tools already provide are deprecated** (planned for
16
+ removal in 0.4). They keep working, with a `FutureWarning` that names what to use
17
+ instead: the metrics `bleu`, `chrf`, `rouge_l`, `bertscore`, `embedding_similarity`, the
18
+ judge-scored RAG metrics (`faithfulness`, `answer_relevancy`, `answer_correctness`,
19
+ `context_precision`, `context_recall`, `citations`; use Ragas or DeepEval), `pii` and
20
+ `toxicity` (Presidio, Detoxify), `ifeval` and `evalplus`; the benchmarks MMLU, GSM8K,
21
+ ARC, TruthfulQA, IFEval (lm-evaluation-harness), HumanEval(+) and MBPP(+) (EvalPlus);
22
+ and `counterfix.evals.perplexity`. What diagnosis and fixes rely on stays: the simple
23
+ checks, retrieval label metrics, `tests` (F12), `tool_call` (F14), `injection` (F13),
24
+ `confidence`, and the `injection` and `tools` probe benchmarks.
25
+
26
+ - **Shortcuts on `guard()` and `watch()`:** `guard(client, mode="retry", log="calls.jsonl",
27
+ judge=..., sample_rate=0.05)` needs no `Config`. With a `config`, the shortcuts override
28
+ its matching fields; the object you passed is not changed. `watch()` takes `log`, `judge`
29
+ and `sample_rate`.
30
+ - **`counterfix.__all__` lists 12 names** (`guard`, `watch`, `diagnose`, `fix`,
31
+ `configure`, `Config`, `Diagnosis`, `FixResult`, `FailureType`, `CallRecord`, `Message`,
32
+ `log_to`). The other 0.2 names (`evaluate`, `metrics`, `RuleStore`, `litellm_callback`,
33
+ ...) still import from `counterfix` with no warning; they now load on first use.
34
+ - **`import counterfix` is about 40% faster** (it no longer loads the metrics, evaluation,
35
+ background and OpenTelemetry modules until used).
36
+ - **New extras:** `counterfix[evals]` (the dataset runner, its reports and the command
37
+ line) and `counterfix[all]`.
38
+ - README and docs reorganised around the three-step loop: wrap, see why, get a verified
39
+ fix. The docs menu now reads Core loop, In production, Evaluation (optional).
40
+ - Fixed: `counterfix.fix(response)` raised `NoJudgeError` on a first run with no judge
41
+ key, even for a cut-off answer that needs no judge. It now falls back to judging with
42
+ the checked model (with `SelfJudgeWarning`, as `diagnose()` already did), and with no
43
+ model at all it fixes what the live checks find and warns that facts and premises were
44
+ not checked. A judge you name explicitly that cannot be built still raises.
45
+ - **Layers are now checked in CI** (`lint-imports`, with `import-linter` in the dev
46
+ extra): lower modules may not import higher ones. To get there, a few helpers moved
47
+ down into `counterfix.core`, with every old import path kept: `RuleStore` and
48
+ `FixRule` (`core.rules`), turning OpenAI, Anthropic and OpenTelemetry responses into
49
+ records plus token log probabilities (`core.convert`), `AnthropicCaller`
50
+ (`core.caller`), `get_diagnosis` (`core.attach`); `extract_code` moved to
51
+ `counterfix.code.check` and stored profiles to an internal module the fix engine can
52
+ read. One exception is listed in the contract: the metric registry's three benchmark
53
+ scorers.
54
+ - **New package layout.** Every module now sits in one of nine subpackages, layered
55
+ (each imports only from those below it, checked in CI): `_internal`, `core`, `judges`,
56
+ `detect`, `fixes`, `runtime`, `integrations`, `evals`, plus `lint`; only `cli`,
57
+ `diagnose` and `testing` stay at the top. The old module paths still import, giving the
58
+ very same module objects (so `isinstance`, monkeypatching and private names behave as
59
+ before), with a `DeprecationWarning`; they are planned to go in 0.4. Type checkers do
60
+ not follow the old paths, so typed code should switch. `counterfix.context()`,
61
+ `counterfix.otel`, `counterfix.perf`, `counterfix.background` and `counterfix.metrics`
62
+ keep working as before, without a warning.
63
+
64
+ | Old path | New path |
65
+ | --- | --- |
66
+ | `counterfix.adapters` | `counterfix.integrations` |
67
+ | `counterfix.agents` | `counterfix.detect.agents` |
68
+ | `counterfix.background` | `counterfix.runtime.background` |
69
+ | `counterfix.benchmarks` | `counterfix.evals.benchmarks` |
70
+ | `counterfix.capabilities` | `counterfix.integrations.capabilities` |
71
+ | `counterfix.code` | `counterfix.detect.code` |
72
+ | `counterfix.confidence` | `counterfix.detect.confidence` |
73
+ | `counterfix.context` | `counterfix.runtime.context` |
74
+ | `counterfix.detectors` | `counterfix.detect` |
75
+ | `counterfix.engine` | `counterfix.fixes.engine` |
76
+ | `counterfix.mcp_server` | `counterfix.integrations.mcp_server` |
77
+ | `counterfix.metrics` | `counterfix.evals.metrics` |
78
+ | `counterfix.otel` | `counterfix.integrations.otel` |
79
+ | `counterfix.perf` | `counterfix.runtime.perf` |
80
+ | `counterfix.perplexity` | `counterfix.evals.perplexity` |
81
+ | `counterfix.presets` | `counterfix.core.presets` |
82
+ | `counterfix.profiles` | `counterfix.fixes.profiles` |
83
+ | `counterfix.rag` | `counterfix.detect.retrieval` |
84
+ | `counterfix.report` | `counterfix.runtime.report` |
85
+ | `counterfix.rules` | `counterfix.fixes` |
86
+ | `counterfix.rules.store` | `counterfix.core.rules` |
87
+ | `counterfix.safe_eval` | `counterfix._internal.safe_eval` |
88
+ | `counterfix.safety` | `counterfix.evals.safety` |
89
+ | `counterfix.text` | `counterfix._internal.text` |
90
+ | `counterfix.verify` | `counterfix.fixes.verify` |
91
+
92
+ - **The five largest files are split** (no behaviour change; every name they exported
93
+ still imports from the same path): the fix engine (1018 lines) into the search,
94
+ result models and one interventions module per failure type; the eval runner (870)
95
+ into running, results, scoring and fixes, asking and sampling; the instruction checks
96
+ (847) into a package by kind of instruction; the command line (805) into a package by
97
+ group of commands (`python -m counterfix.cli` also works); and the OpenAI wrapper (532)
98
+ into `guard()` and the guarded client. No source file is over 460 lines.
99
+ - `Config.rules` is typed as `RuleStore | None`: a wrong value now fails when the Config
100
+ is built (pydantic `ValidationError`) instead of on the first retry (`TypeError`).
101
+ - A test now freezes the 0.2.1 public surface (every top-level name, module path and
102
+ subpackage export, and both entry points), so later restructuring cannot break imports
103
+ unnoticed.
104
+
105
+ "Verified" now has a stated error rate.
106
+
107
+ - **A change must beat a plain retry to count as a fix.** The plain retry and each change
108
+ are re-run up to 6 times; a change is verified only if a one-sided Fisher exact test
109
+ says it passed clearly more often (p at or below 0.05 divided by the number of changes
110
+ the search may try). The old rule (2 of 3 re-runs) called a change that does nothing
111
+ "verified" in 11% to 36% of searches on a model that fails at random; the new one in
112
+ under 1%. Applies to `fix()`, `speed_fix()` and the fix search in `counterfix eval`.
113
+ The statistics live in `counterfix.verify`.
114
+ - `explain()` shows the retry's count, each change's count and its p-value; attempts gain
115
+ `p_value`, and `FixResult.level` is the bar each change had to reach.
116
+ - Default `max_runs` is now 30 (was 15 for `fix()` and 9 for `eval`, MCP and profiles):
117
+ a deterministic fix such as a larger `max_tokens` now takes about 13 re-runs instead of
118
+ 6. Intermittent failures cost about the same, because the retry stops early once it
119
+ passes too often for any change to beat.
120
+ - `need=` on `fix()`, `speed_fix()` and `fix_item()` is ignored with a
121
+ `DeprecationWarning`. `check_retry=False` now assumes the plain retry never passes.
122
+ - Fixed: `counterfix fix --caller MODEL@http://host/v1` (and `compare`, `profile`,
123
+ `drift`) crashed with "unknown provider"; they now take every spec `eval` takes, and an
124
+ unusable spec prints one line and exits 2. `counterfix fix` also shows the real reason a
125
+ call cannot be re-run instead of always blaming the log.
126
+ - Fixed: the F8 expression evaluator had no bound on nested loops (one expression ran for
127
+ over two minutes); it now stops after 100,000 steps.
128
+ - Docs: "so luck does not count" and similar claims replaced by what the test does and
129
+ does not show.
130
+ - Re-measured on the 38 seed failures (`bench/results/fixes_v022.md`): 14 verified fixes
131
+ (cause right and retry not passing: 14 of 22, 64%), against 18 (18 of 23, 78%) under the
132
+ old rule. The 5 that dropped out (`allow_unknown`, `work_it_out`) were on failures that,
133
+ re-run more often, did not repeat reliably. 6.8 re-runs per failure (was 3.7).
134
+ - `bench/fix_seed.py`: `--learn` counts only the change the engine verified (it counted
135
+ any attempt with 2 passes), and the report counts "plain retry passes" from where the
136
+ engine stopped, not from a pass count.
137
+
138
+ ## 0.2.1 (2026-11-11)
139
+
140
+ Wording that claims no more than counterfix does.
141
+
142
+ - New tagline everywhere (PyPI, README, docs, CLI, MCP server): "LLM evaluation that
143
+ diagnoses failures and re-runs fixes to see which ones work". The old one ("get a fix
144
+ that was tested to work") implied a fix every time; often no change passes, and
145
+ counterfix says so.
146
+ - `diagnose()` output, the HTML report and `counterfix lint` show an untested suggestion as
147
+ `try:`; only a suggestion that passed re-runs is shown as `fix (verified):`. `fix()`
148
+ output is unchanged (it prints `fix:` only for a verified change).
149
+ - The README and docs intros say counterfix looks for the likely cause and tests fixes,
150
+ and that when none passes it says so and lists what to try next.
151
+ - Docs: the confidence example shows the guarded client.
152
+
5
153
  ## 0.2.0 (2026-11-11)
6
154
 
7
155
  counterfix grows from diagnosing single calls into one-stop evaluation, where every miss
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: counterfix
3
- Version: 0.2.0
4
- Summary: Find why an LLM call failed and get a fix that was tested to work.
3
+ Version: 0.3.0
4
+ Summary: Find out why an LLM call failed, and prove the fix works: a one-line wrapper that diagnoses failures and verifies fixes by re-running them.
5
5
  Project-URL: Homepage, https://github.com/KANSADWALA/CounterFix
6
6
  Project-URL: Documentation, https://kansadwala.github.io/CounterFix/
7
7
  Project-URL: Changelog, https://github.com/KANSADWALA/CounterFix/blob/main/CHANGELOG.md
@@ -9,7 +9,7 @@ Project-URL: Issues, https://github.com/KANSADWALA/CounterFix/issues
9
9
  Author: Shubham Kansadwala
10
10
  License-Expression: MIT
11
11
  License-File: LICENSE
12
- Keywords: counterfactual,debugging,evaluation,hallucination,llm,reliability
12
+ Keywords: anthropic,counterfactual,debugging,evaluation,hallucination,llm,openai,reliability,root-cause
13
13
  Classifier: Development Status :: 3 - Alpha
14
14
  Classifier: Intended Audience :: Developers
15
15
  Classifier: License :: OSI Approved :: MIT License
@@ -25,6 +25,25 @@ Requires-Dist: json-repair>=0.30
25
25
  Requires-Dist: jsonschema>=4.20
26
26
  Requires-Dist: pydantic>=2.7
27
27
  Requires-Dist: tenacity>=8.2
28
+ Provides-Extra: all
29
+ Requires-Dist: anthropic>=0.40; extra == 'all'
30
+ Requires-Dist: bert-score>=0.3.13; extra == 'all'
31
+ Requires-Dist: detoxify>=0.5; extra == 'all'
32
+ Requires-Dist: diskcache>=5.6; extra == 'all'
33
+ Requires-Dist: jinja2>=3.1; extra == 'all'
34
+ Requires-Dist: langchain-core>=0.3; extra == 'all'
35
+ Requires-Dist: litellm>=1.50; extra == 'all'
36
+ Requires-Dist: llama-index-core>=0.11; extra == 'all'
37
+ Requires-Dist: mcp>=2.0; extra == 'all'
38
+ Requires-Dist: openai>=1.40; extra == 'all'
39
+ Requires-Dist: opentelemetry-sdk>=1.27; extra == 'all'
40
+ Requires-Dist: presidio-analyzer>=2.2; (python_version >= '3.11') and extra == 'all'
41
+ Requires-Dist: pyyaml>=6.0; extra == 'all'
42
+ Requires-Dist: rich>=13.7; extra == 'all'
43
+ Requires-Dist: sentence-transformers>=3.0; extra == 'all'
44
+ Requires-Dist: torch>=2.2; extra == 'all'
45
+ Requires-Dist: transformers>=4.44; extra == 'all'
46
+ Requires-Dist: typer>=0.12; extra == 'all'
28
47
  Provides-Extra: anthropic
29
48
  Requires-Dist: anthropic>=0.40; extra == 'anthropic'
30
49
  Provides-Extra: benchmarks
@@ -38,6 +57,7 @@ Requires-Dist: typer>=0.12; extra == 'cli'
38
57
  Provides-Extra: code
39
58
  Requires-Dist: evalplus>=0.3.1; extra == 'code'
40
59
  Provides-Extra: dev
60
+ Requires-Dist: import-linter==2.15; extra == 'dev'
41
61
  Requires-Dist: mypy==2.4.0; extra == 'dev'
42
62
  Requires-Dist: pytest-recording>=0.13; extra == 'dev'
43
63
  Requires-Dist: pytest>=8.0; extra == 'dev'
@@ -49,6 +69,11 @@ Provides-Extra: docs
49
69
  Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
50
70
  Provides-Extra: eval
51
71
  Requires-Dist: pyyaml>=6.0; extra == 'eval'
72
+ Provides-Extra: evals
73
+ Requires-Dist: jinja2>=3.1; extra == 'evals'
74
+ Requires-Dist: pyyaml>=6.0; extra == 'evals'
75
+ Requires-Dist: rich>=13.7; extra == 'evals'
76
+ Requires-Dist: typer>=0.12; extra == 'evals'
52
77
  Provides-Extra: jev
53
78
  Requires-Dist: typesafe-sdk>=0.7; extra == 'jev'
54
79
  Provides-Extra: langchain
@@ -85,15 +110,19 @@ Description-Content-Type: text/markdown
85
110
  [![Docs](https://img.shields.io/badge/docs-online-blue)](https://kansadwala.github.io/CounterFix/)
86
111
  [![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://github.com/KANSADWALA/CounterFix/blob/main/LICENSE)
87
112
 
88
- **Find why an LLM call failed, and get a fix that was tested to work.**
113
+ **Find out why an LLM call failed, and prove the fix works.**
89
114
 
90
- Most LLM evaluation tools tell you *that* a model failed. counterfix is built to tell you
91
- *why*, and to hand back a fix it has already checked. When a call fails, it changes one
92
- thing at a time (raises `max_tokens`, asks for bare JSON, adds the source text, tells the
93
- model to check the question's premises, repeats a missed instruction) and re-runs the
94
- call. A change counts only if it works in 2 of 3 re-runs. The change that fixes the
95
- failure is both the diagnosis and the prescription. We call this **counterfactual
96
- diagnosis**.
115
+ One line around the client you already use. counterfix names the likely failure type
116
+ (F1 to F14) on every call. Ask it for a fix and it changes one thing at a time (raises
117
+ `max_tokens`, asks for bare JSON, adds the source text, tells the model to check the
118
+ question's premises, repeats a missed instruction) and re-runs the call. A change counts
119
+ only if it passes clearly more often than re-running the call unchanged (a Fisher exact
120
+ test against a plain retry). When none does, counterfix says so and lists what to try
121
+ next. We call this **counterfactual diagnosis**.
122
+
123
+ counterfix works alongside your evaluation and tracing tools (DeepEval, Ragas, Promptfoo,
124
+ Langfuse, MLflow, ...): they tell you *that* calls fail and how often; counterfix tells you
125
+ *why* one failed and which change verifiably fixes it.
97
126
 
98
127
  > **Status: alpha** (latest version in the PyPI badge above). Everything below works today: live checks, judge checks,
99
128
  > verified fixes, reports, regression tests, profiles, dataset and RAG evaluation, code
@@ -117,30 +146,43 @@ diagnosis**.
117
146
  pip install counterfix
118
147
  ```
119
148
 
120
- That is all most people need: the core has 4 small dependencies and needs no API key.
121
- counterfix is an independent open-source project, not affiliated with any model provider.
149
+ The core has 4 small dependencies and needs no API key. counterfix is an independent
150
+ open-source project, not affiliated with any model provider. If your project already has
151
+ the OpenAI or Anthropic SDK, nothing else is needed; otherwise add it with
152
+ `pip install "counterfix[openai]"` or `"counterfix[anthropic]"`.
122
153
 
123
- Optional extras add a provider's SDK only if you do not have it already:
154
+ ## Quickstart
124
155
 
125
- | You use | Install |
126
- | --- | --- |
127
- | OpenAI's SDK, or any OpenAI-compatible API through it (Groq, Gemini, OpenRouter, Ollama, vLLM, ...) | `pip install "counterfix[openai]"` |
128
- | Anthropic's SDK | `pip install "counterfix[anthropic]"` |
129
- | LiteLLM or LangChain | `pip install "counterfix[litellm]"` or `"counterfix[langchain]"` |
130
- | Benchmarks (MMLU, GSM8K, ARC, TruthfulQA, IFEval) | `pip install "counterfix[benchmarks]"` |
131
- | HumanEval / MBPP and HumanEval+ / MBPP+ (EvalPlus) | `pip install "counterfix[code]"` |
132
- | BLEU / chrF, or BERTScore, embeddings and perplexity | `"counterfix[metrics]"` or `"counterfix[semantic]"` |
133
- | Toxicity and Presidio personal-data checks | `pip install "counterfix[safety]"` |
134
- | Suite files in YAML, the MCP server, OpenTelemetry, LlamaIndex | `"counterfix[eval]"`, `"counterfix[mcp]"`, `"counterfix[otel]"`, `"counterfix[llamaindex]"` |
156
+ ```python
157
+ import counterfix
158
+ from openai import OpenAI
135
159
 
136
- If that SDK is already in your project, plain `pip install counterfix` is enough.
160
+ client = counterfix.guard(OpenAI()) # 1. wrap your client (same API as before)
161
+ r = client.chat.completions.create(model="gpt-4o-mini", messages=[...])
162
+ print(r.diagnosis.summary()) # 2. see why it failed (live checks, free)
163
+ print(counterfix.fix(r).explain()) # 3. get a fix that was re-run and verified
164
+ ```
137
165
 
138
- ## Quickstart
166
+ ```text
167
+ found: F1 Truncation (95%)
168
+ plain retry: passed 0/6
169
+ tried raise_max_tokens: passed 0/2 vs retry 0/6, p=1.000 -> no (still: F1 Truncation)
170
+ tried raise_max_tokens_more: passed 5/5 vs retry 0/6, p=0.002 -> VERIFIED
171
+ fix: Raise max_tokens a lot (long answers, or reasoning that uses the budget)
172
+ change: {'max_tokens': 4096}
173
+ 13 re-run(s); stopped at the first verified fix
174
+ ```
175
+
176
+ That is the whole loop. Step 2 costs nothing: live checks make no extra calls. Step 3
177
+ re-runs the call (here 13 times) and may use a judge model for checks code cannot do; the
178
+ judge comes from your own key (a free `GROQ_API_KEY` or `GEMINI_API_KEY` is enough; run
179
+ `counterfix setup` to see what it finds). "Verified" means the change beat asking again
180
+ *on this call*, not that it works on every prompt. How the test works:
181
+ [Verified fixes](https://kansadwala.github.io/CounterFix/fixes/).
139
182
 
140
- ### 1. See it work in 10 seconds (no key)
183
+ **Try it with no key at all:**
141
184
 
142
185
  ```python
143
- import counterfix
144
186
  from counterfix import CallRecord, Message
145
187
 
146
188
  record = CallRecord(
@@ -153,238 +195,85 @@ print(counterfix.diagnose(record, judge=False).explain())
153
195
  ```text
154
196
  F6 Dropped instruction (90%)
155
197
  why: instructions not met: exactly 1 word (has 9); a one-word answer (has 9 words)
156
- fix: Repeat the broken instructions at the end of the prompt as a short checklist. ...
157
- ```
158
-
159
- `judge=False` runs only the live checks: free, instant, no extra calls. More cases in
160
- [`examples/quickstart.py`](https://github.com/KANSADWALA/CounterFix/blob/main/examples/quickstart.py).
161
-
162
- ### 2. Wrap your client (one line)
163
-
164
- ```python
165
- from openai import OpenAI
166
- import counterfix
167
-
168
- client = counterfix.guard(OpenAI()) # same API as before
169
- response = client.chat.completions.create(
170
- model="gpt-4o-mini",
171
- messages=[{"role": "user", "content": "Why did Einstein win his third Nobel Prize?"}],
172
- )
173
- print(response.choices[0].message.content)
174
- print(response.diagnosis.summary()) # live checks, already run on this call
198
+ try: Repeat the broken instructions at the end of the prompt as a short checklist. ...
175
199
  ```
176
200
 
177
- Any OpenAI-compatible endpoint works, for example a local Ollama server:
201
+ ## Plug it into what you use
178
202
 
179
- ```python
180
- client = counterfix.guard(OpenAI(base_url="http://localhost:11434/v1", api_key="ollama"))
181
- ```
182
-
183
- The guarded client behaves like the original: sync or `AsyncOpenAI`, `stream=True`,
184
- `chat.completions.parse()`, the Responses API (`responses.create` / `.parse`),
185
- `with` / `async with`, and `with_options()` all work and stay checked. Your type checker sees the client you passed. Two things differ:
203
+ | You use | One line |
204
+ | --- | --- |
205
+ | OpenAI SDK, or any OpenAI-compatible API (Groq, Gemini, OpenRouter, Ollama, vLLM, ...) | `client = counterfix.guard(OpenAI(...))` |
206
+ | Anthropic SDK | `client = counterfix.guard(Anthropic())` |
207
+ | LiteLLM | `litellm.callbacks = [counterfix.litellm_callback()]` |
208
+ | LangChain | `llm.invoke(..., config={"callbacks": [counterfix.langchain_callback()]})` |
209
+ | Your own function | `@counterfix.watch(model="llama3.2")` on a function that takes a prompt and returns text |
210
+
211
+ The guarded client behaves like the original: sync or async, `stream=True`,
212
+ `chat.completions.parse()`, the Responses API, `with` blocks and `with_options()` all work
213
+ and stay checked, and your type checker sees the client you passed. Two things differ:
186
214
  `isinstance(client, OpenAI)` is False (pass `client.unwrapped` where a library insists on
187
215
  the real object), and type checkers do not know `response.diagnosis`, so typed code can use
188
- `counterfix.get_diagnosis(response)`.
189
-
190
- The Anthropic SDK works the same way (`messages.create`, sync or async; `tool_use`
191
- arguments are checked against each tool's `input_schema`):
192
-
193
- ```python
194
- from anthropic import Anthropic
195
-
196
- client = counterfix.guard(Anthropic())
197
- ```
216
+ `counterfix.integrations.get_diagnosis(response)`. Callbacks only observe; they never change a
217
+ reply. Details: [Plug it in](https://kansadwala.github.io/CounterFix/plugs/).
198
218
 
199
- Already on LiteLLM or LangChain? Add a callback; it only observes, never changes a reply:
200
-
201
- ```python
202
- litellm.callbacks = [counterfix.litellm_callback()]
203
- llm.invoke("...", config={"callbacks": [counterfix.langchain_callback()]})
204
- ```
205
-
206
- Not using any of these? Decorate the function that calls your model (sync or
207
- async). It takes a prompt string or chat messages and returns text or a response:
208
-
209
- ```python
210
- @counterfix.watch(model="llama3.2")
211
- def ask(prompt: str) -> str:
212
- return my_local_model(prompt)
213
-
214
-
215
- answer = ask("Answer in one word: sky colour?") # returned unchanged
216
- print(ask.last_diagnosis.summary())
217
- ```
218
-
219
- ### 3. Ask a judge for the deeper look
220
-
221
- ```python
222
- report = counterfix.diagnose(response) # adds judge checks: false premise, invented facts, ...
223
- print(report.explain())
224
- ```
225
-
226
- The judge comes from your own key (a free `GROQ_API_KEY` or `GEMINI_API_KEY` is enough;
227
- see [Bring your own key](#bring-your-own-key)). Run `counterfix setup` to see what it
228
- found. Full script: [`examples/diagnose_with_judge.py`](https://github.com/KANSADWALA/CounterFix/blob/main/examples/diagnose_with_judge.py).
229
-
230
- ### 4. Get a fix that was tested to work
231
-
232
- ```python
233
- result = counterfix.fix(response) # a guarded response, its diagnosis, or a CallRecord
234
- print(result.explain())
235
- ```
236
-
237
- ```text
238
- found: F1 Truncation (95%)
239
- plain retry: passed 0/2
240
- tried raise_max_tokens: passed 0/2 -> no (still: F1 Truncation)
241
- tried raise_max_tokens_more: passed 2/3 -> VERIFIED
242
- fix: Raise max_tokens a lot (long answers, or reasoning that uses the budget)
243
- change: {'max_tokens': 4096}
244
- 7 re-run(s); stopped at the first verified fix
245
- ```
246
-
247
- For each failure, counterfix changes one thing (raise `max_tokens`, ask for bare JSON,
248
- check the question's premises, repeat missed instructions, add the source text, ...),
249
- re-runs the call, and re-checks it. A change counts as the fix only if the failure is
250
- gone, with no new failure, in 2 of 3 re-runs, so luck does not count. It first re-runs
251
- the call unchanged: if a plain retry already passes, no change is claimed. The verified
252
- change is in `result.fix` (`changed` params, or full new `messages`) and on the finding's
253
- prescription (`verified=True`). `max_runs` caps the re-runs (15); judge calls come on top.
254
- When nothing passes, `result.escalation` lists what is left (retrieval, a larger model, a
255
- code tool, a clarifying question).
256
-
257
- ### 5. Log calls, then report on them
219
+ ## In production
258
220
 
259
221
  ```python
260
222
  client = counterfix.guard(
261
- OpenAI(), config=counterfix.Config(on_diagnosis=counterfix.log_to("calls.jsonl"))
223
+ OpenAI(),
224
+ log="calls.jsonl", # every call and its diagnosis, as JSON lines
225
+ sample_rate=0.05, # judge checks on every flagged call + 5% of the rest
226
+ mode="retry", # re-run a flagged call once with a known fix
262
227
  )
263
228
  ```
264
229
 
265
- ```bash
266
- counterfix diagnose calls.jsonl # terminal summary, live checks only (free)
267
- counterfix diagnose calls.jsonl --judge --html report.html --json results.jsonl
268
- counterfix diagnose calls.jsonl --fail-on-failure # exit code 1 if any call failed (CI)
269
- ```
270
-
271
- The HTML report is one self-contained file you can send to a teammate: totals per failure
272
- type, then each call with its prompt, answer, why it was flagged and the suggested fix.
273
- The JSON lines (`{"record": ..., "diagnosis": ...}`) suit log pipelines, and can be read
274
- back with `counterfix diagnose` or `counterfix.load_log()`.
275
-
276
- ### 6. Judge checks on production traffic, without slowing it down
277
-
278
- ```python
279
- config = counterfix.Config(
280
- sample_rate=0.05, # every flagged call + 5% of the rest get judge checks
281
- max_judged_per_hour=60, # cost cap; calls over it are skipped, never delayed
282
- on_judged=counterfix.log_to("judged.jsonl"),
283
- )
284
- client = counterfix.guard(OpenAI(), config=config)
285
- ```
286
-
287
- Judge checks run on one background thread, so your call returns as fast as before. If the
288
- queue fills up, new calls are skipped rather than waited on; `counterfix.background.stats`
289
- counts what was judged and skipped. Call `counterfix.background.flush()` before a short
290
- script exits if you want the queued checks to finish.
291
-
292
- ### 7. Evaluate a dataset: the score, the misses by cause, the fixes
293
-
294
- ```bash
295
- counterfix eval capitals.jsonl --model groq:openai/gpt-oss-120b --metric exact_match --judge --fix 5
296
- ```
297
-
298
- Scores every answer (exact match, F1, ROUGE-L, BLEU, multiple choice, final number, JSON,
299
- latency, ...), groups the misses by cause (F1 to F14), and searches verified fixes on up to
300
- 5 misses. Streamed calls also record TTFT; reports show latency, TTFT and tokens/s
301
- percentiles per model. Guides: [Evaluate a dataset](https://kansadwala.github.io/CounterFix/evals/),
302
- [Speed and cost](https://kansadwala.github.io/CounterFix/speed/).
303
-
304
- ### 8. RAG: was it the retriever or the model?
230
+ Judge checks run on a background thread, capped per hour, so calls return as fast as
231
+ before. Retry mode is off by default; without it counterfix only reports. For anything
232
+ else, pass a `counterfix.Config` (the shortcuts above override it).
305
233
 
306
234
  ```bash
307
- counterfix eval rag.jsonl --model groq:openai/gpt-oss-120b --metric recall@5 --metric faithfulness --fix 5
235
+ counterfix diagnose calls.jsonl --judge --html report.html # a report you can send a teammate
236
+ counterfix fix calls.jsonl --judge --out fixes.jsonl # search verified fixes in bulk
237
+ counterfix export-tests fixes.jsonl --out tests/test_prompt_regressions.py
308
238
  ```
309
239
 
310
- Retrieval metrics from gold labels (hit, recall, precision, MRR, nDCG at k), judge metrics
311
- (faithfulness, context precision and recall, answer relevancy, citations), and the cause of
312
- each miss: F10 retrieval miss or F11 context ignored, with verified fixes (the gold passage
313
- proves the retriever was at fault; the key passage first fixes ignored context). To test
314
- your whole pipeline, pass it as a function: `counterfix eval qa.jsonl --app myapp:answer`
315
- (or `evaluate(..., app=answer)`; LangChain and LlamaIndex outputs are read as they are).
316
- Guide: [RAG evaluation](https://kansadwala.github.io/CounterFix/rag/).
317
-
318
- ### 9. Code and benchmarks
240
+ Each verified fix becomes a pytest case that fails if the failure comes back after a prompt
241
+ edit or a model change; `counterfix.testing.assert_ok(response)` does the same in your own
242
+ tests. Guides: [In production](https://kansadwala.github.io/CounterFix/production/),
243
+ [Prompt regression tests](https://kansadwala.github.io/CounterFix/testing/).
319
244
 
320
- ```bash
321
- counterfix eval coding.jsonl --model groq:openai/gpt-oss-120b --metric tests --allow-code --fix 5
322
- counterfix benchmark gsm8k --model ollama:qwen2.5:3b --limit 200
323
- counterfix benchmark humaneval+ --model groq:openai/gpt-oss-120b --allow-code
324
- ```
325
-
326
- Code runs against its tests in a sandbox (Docker, or a subprocess for trusted
327
- benchmarks; off until you allow it). A failure is named (syntax, wrong name or signature,
328
- runtime error, wrong output, timeout: F12), with what the code returned, and fixes such as
329
- sending the error back are verified on re-run (measured so far: 2 of 8 repeatable
330
- failures fixed on qwen2.5:3b; gpt-oss-120b passed 18 of 20 HumanEval problems). `--samples N` reports pass@k. Benchmarks: MMLU, GSM8K, ARC-Challenge,
331
- TruthfulQA, IFEval (official checks), HumanEval/MBPP (counterfix's checker, any OS) and
332
- HumanEval+/MBPP+ (scored by EvalPlus, Linux and macOS), with seeded subsets that fit a free
333
- tier. Scores match lm-evaluation-harness on the same prompts (GSM8K 0.81 vs 0.79, MMLU
334
- abstract algebra 0.56 vs 0.56, on qwen2.5:3b). Guides: [Code evaluation](https://kansadwala.github.io/CounterFix/code/),
335
- [Benchmarks](https://kansadwala.github.io/CounterFix/benchmarks/).
245
+ ## The same checks over a dataset
336
246
 
337
- ### 10. Prompt injection, personal data, token confidence
247
+ The checks and fixes above also run over a whole dataset: the misses grouped by cause, and
248
+ a verified fix searched for each. Install with `pip install "counterfix[evals]"`.
338
249
 
339
250
  ```bash
340
- counterfix benchmark injection --model ollama:qwen2.5:3b --fix 10
341
- counterfix eval support.jsonl --model groq:openai/gpt-oss-120b --metric pii --metric toxicity
342
- counterfix eval qa.jsonl --model openai:gpt-4o-mini --param logprobs=true --metric confidence
251
+ counterfix eval qa.jsonl --model groq:openai/gpt-oss-120b --metric exact_match --judge --fix 5
343
252
  ```
344
253
 
345
- 20 injection probes (instructions planted in retrieved passages and tool results, checked
346
- exactly with canaries) and a judge check for any call with untrusted text: F13, with
347
- verified fixes such as marking untrusted text as data. PII in answers (built-in
348
- recognizers with checksums, optional Presidio), toxicity (Detoxify), and token confidence
349
- where the provider returns logprobs. Guides: [Safety](https://kansadwala.github.io/CounterFix/safety/),
350
- [Confidence and perplexity](https://kansadwala.github.io/CounterFix/confidence/).
254
+ counterfix works alongside your evaluation tools rather than replacing them. Metrics and
255
+ benchmarks those tools already provide (BLEU, ROUGE, BERTScore, judge-scored RAG metrics,
256
+ PII and toxicity, MMLU, GSM8K, HumanEval and the like) still work in 0.3 but are
257
+ deprecated, with a warning that names the tool to use instead, and are planned for removal
258
+ in 0.4.
351
259
 
352
- ### 11. Agents and tool calls
353
-
354
- ```bash
355
- counterfix benchmark tools --model ollama:qwen2.5:3b --fix 10
356
- counterfix eval tool_tests.jsonl --model groq:openai/gpt-oss-120b --metric tool_call --fix 5
357
- ```
358
-
359
- ```python
360
- rec = counterfix.agents.record(task, langgraph_result, tools=tools, expect_tools=["search"])
361
- counterfix.diagnose(rec) # F14: unknown tool, loop, missing call; judge: task done, and why
362
- ```
363
-
364
- Runs from OpenAI-style messages, LangChain/LangGraph, Anthropic, OpenTelemetry spans or
365
- guarded responses. Verified fixes for tool choice: `tool_choice`, naming the tool,
366
- describing the arguments. Guide: [Agents and tool calls](https://kansadwala.github.io/CounterFix/agents/).
367
-
368
- ### 12. Keep fixed failures fixed (pytest)
369
-
370
- ```bash
371
- counterfix fix calls.jsonl --judge --out fixes.jsonl
372
- counterfix export-tests fixes.jsonl --out tests/test_prompt_regressions.py
373
- pytest tests/test_prompt_regressions.py
374
- ```
375
-
376
- Each verified fix becomes a test case that fails if the failure comes back after a prompt
377
- edit or a model change. In your own tests, `counterfix.testing.assert_ok(response)` fails
378
- with the explanation when counterfix finds a failure.
260
+ | Area | What you get | Guide |
261
+ | --- | --- | --- |
262
+ | Datasets | Exact match, F1, number, choice, JSON, latency; misses by cause; fixes on up to N misses | [Evaluate a dataset](https://kansadwala.github.io/CounterFix/evals/) |
263
+ | RAG | Retrieval metrics from gold labels, and whether the retriever (F10) or the model (F11) caused each miss | [RAG evaluation](https://kansadwala.github.io/CounterFix/rag/) |
264
+ | Code | Tests run in a sandbox, failures named (F12), pass@k, fixes such as sending the error back | [Code evaluation](https://kansadwala.github.io/CounterFix/code/) |
265
+ | Prompt injection | Canary probes and a judge check (F13), with verified fixes | [Safety](https://kansadwala.github.io/CounterFix/safety/) |
266
+ | Agents | Tool misuse (F14) from OpenAI, LangGraph, Anthropic or OpenTelemetry runs | [Agents and tool calls](https://kansadwala.github.io/CounterFix/agents/) |
267
+ | Speed and confidence | Latency, TTFT and tokens/s percentiles; token confidence where logprobs exist | [Speed](https://kansadwala.github.io/CounterFix/speed/), [Confidence](https://kansadwala.github.io/CounterFix/confidence/) |
379
268
 
380
269
  ### More
381
270
 
382
271
  | | |
383
272
  | --- | --- |
384
- | Streams (`stream=True`) | every chunk passes straight through; the whole answer is checked at the end |
385
273
  | `with counterfix.context(source=..., reference=...)` | tell the checks what the model was given (RAG) or the right answer |
386
274
  | `counterfix profile / compare / drift / route` | measure models, compare an upgrade on your own calls, alert on drift, pick the cheapest safe model per task |
387
275
  | `counterfix.otel.export()`, `counterfix.otel.SpanChecker()` | send diagnoses to OpenTelemetry, or check the GenAI spans you already have |
276
+ | `counterfix lint prompts.jsonl` | catch prompt problems before you send them |
388
277
  | `counterfix mcp` | an MCP server so coding agents can lint prompts and check calls |
389
278
 
390
279
  Full docs: https://kansadwala.github.io/CounterFix/ (or build locally with `mkdocs serve`). Measured accuracy and fix rates:
@@ -550,7 +439,7 @@ Done:
550
439
  - Background judge checks on a sample of traffic, with a cost cap ✅
551
440
  - `@counterfix.watch` decorator for any function, sync or async ✅
552
441
  - Anthropic SDK in `guard()`, LiteLLM and LangChain callbacks ✅
553
- - Verified fixes: `counterfix.fix()` (counterfactual re-runs, 2 of 3 must pass) ✅
442
+ - Verified fixes: `counterfix.fix()` (counterfactual re-runs; a change must beat a plain retry) ✅
554
443
  - Prompt regression tests: `counterfix export-tests` and a pytest plugin ✅
555
444
  - Model profiles, `compare`, `drift`, `route`; fixes ordered by what worked per model ✅
556
445
  - OpenTelemetry export and GenAI span reader; streams; RAG context; MCP server ✅