Skip to content

Apply the llm pattern number as a confidence threshold; handle models that reject temperature - #38

Merged
fr0gger merged 1 commit into
mainfrom
fix/llm-temperature-threshold
Nov 29, 2026
Merged

fr0gger merged 1 commit into
mainfrom
fix/llm-temperature-threshold

Conversation

@fr0gger

@fr0gger fr0gger commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

The number on a quoted llm: pattern is now the confidence threshold the documentation describes, and LLM rules work again on models that reject a custom temperature. Supersedes #33 and builds on its retry idea.

The problem

  • $check = "prompt" (0.7) is documented as "how confident the LLM must be to trigger a match". Since v0.1.4 the engine has sent that number to the model as its temperature and never checked the reported confidence. Any yes matched, and raising the number only made the model more random.
  • Models that accept only their default sampling settings answer a custom temperature with HTTP 400. Every LLM rule then failed closed and never matched (the case reported in Fix temperature in OpenAI and Anthropic evaluators #33).

Changes

  • Threshold. A pattern matches only when the model answers yes with confidence at or above the number. Applied in NovaMatcher and in the decision engine (quoted checks inside typed rules). The number is no longer sent to the model.
  • Missing confidence. A yes without a usable confidence fails closed with a warning unless the threshold is 0.0. Confidences are clamped to 0-1 on every provider.
  • Temperature. Checks run at the evaluators' fixed 0.1. On a 400 that names temperature, the OpenAI, OpenRouter, Azure and Anthropic evaluators retry once without it and stop sending it for that evaluator.
  • Anthropic parsing. The verdict is read from the text blocks, not content[0], so a leading thinking block is not parsed as an empty non-match. A response with no text is an error. max_tokens goes from 200 to 1024.
  • CLI. Verbose output shows the verdict next to the threshold, for example yes at 0.9800 (a yes needs 0.7).
  • Docs. README, docs/decision.md, the layered example and the changelog no longer call the number a temperature.

Behaviour changes

  • A rule can stop matching where the model says yes below its stated number. Lower the number to keep the old behaviour; (0.0) accepts any yes.
  • A pattern without a number uses 0.6. That was already the parser default; LLMPattern objects built in code previously defaulted to 0.1.

Verification

  • 396 tests pass, 2 skipped; ruff, build, twine check, verify_artifacts.py, the dependency audit and the wheel smoke test pass. 35 new tests cover the threshold and the fallback.
  • Live on OpenAI gpt-5-mini, which rejects a custom temperature: before, an "ignore all previous instructions" prompt failed closed; after, it matches at 0.98 through the CLI, the SDK parallel scan and the decision-engine path, and a benign prompt does not match.
  • Live on gpt-4o-mini, OpenRouter and Groq: the 0.1 temperature is kept and verdicts are returned.
  • On the nova-rules pack (42 LLM patterns × 8 prompts, gpt-4o-mini), all 100 yes verdicts had confidence ≥ 0.8, so no outcome changed.

Not tested live

🤖 Generated with Claude Code

The number on a quoted llm pattern, as in `$check = "prompt" (0.7)`, is
documented as the confidence the LLM needs to trigger a match. The engine
sent it to the model as the sampling temperature instead and never
compared the reported confidence to it, so any yes matched and a higher
"threshold" only made verdicts more random.

The matcher and the decision engine now match a pattern only when the
model answers yes at or above the threshold, and no longer pass the
number to the evaluator. Checks run at the evaluators' fixed 0.1
temperature. A pattern without a number uses 0.6 whether it is parsed
from a rule file or built in code.

A yes that comes without a usable confidence fails closed with a
warning unless the threshold is 0.0, and reported confidences are
clamped to 0-1 on every provider.

Models that accept only their default sampling settings answer a custom
temperature with HTTP 400, which made every LLM rule fail closed. The
OpenAI, OpenRouter, Azure and Anthropic evaluators now retry once without
the field and stop sending it for that evaluator.

The Anthropic evaluator reads the verdict from the text blocks rather
than the first content block, so a leading thinking block is not parsed
as an empty non-match, reports a response with no text as an error, and
allows 1024 output tokens.

Supersedes #33.

Co-authored-by: Marco Pedrinazzi <marcopedrinazzi.mp@gmail.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@fr0gger
fr0gger merged commit 27d881a into main Nov 29, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant