Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to LettuceDetect are documented here.

## [Unreleased]

### Fixed
- Claude Code Stop hook: `--min-confidence` above `0.0` no longer drops every span in `--llm-model` mode. Unscored spans are kept, matching `BaseDetector._filter_spans_by_confidence` (#117)

## [0.2.3] - 2026-08-14

### Added
Expand Down
2 changes: 1 addition & 1 deletion lettucedetect/integrations/claude_code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ found the agent receives them and revises.
| `--llm-model ID` | Generative detector or LLM judge; use `KRLabsOrg/lettucedect-v2-qwen-2b` for typed spans in one pass |
| `--llm-base-url URL` | OpenAI-compatible endpoint for `--llm-model` (e.g. `vllm serve KRLabsOrg/lettucedect-v2-qwen-2b`) |
| `--context-file F` | Grounding passage file, repeatable; default `context.md` |
| `--min-confidence X` | Report only spans at or above this confidence |
| `--min-confidence X` | Report only spans at or above this confidence; spans the detector did not score (every span in `--llm-model` mode) are always reported |

Models: `KRLabsOrg/lettucedect-base-modernbert-en-v1` for prose RAG answers;
`KRLabsOrg/lettucedect-v2-mmbert-base` plus
Expand Down
10 changes: 8 additions & 2 deletions lettucedetect/integrations/claude_code/check_answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ def main(argv: list[str] | None = None) -> int:
"--min-confidence",
type=float,
default=0.0,
help="Report only spans at or above this confidence (default 0.0)",
help=(
"Report only spans at or above this confidence (default 0.0). "
"Applies to scored spans only; spans the detector did not score "
"(every span in --llm-model mode) are always reported."
),
)
args = parser.parse_args(argv)

Expand Down Expand Up @@ -231,7 +235,9 @@ def main(argv: list[str] | None = None) -> int:
flagged = [
s
for s in spans
if (s.get("confidence", s.get("hallucination_score")) or 0.0) >= args.min_confidence
if args.min_confidence <= 0.0
or s.get("confidence", s.get("hallucination_score")) is None
or s.get("confidence", s.get("hallucination_score")) >= args.min_confidence
]
if not flagged:
return 0
Expand Down
75 changes: 75 additions & 0 deletions tests/test_claude_code_hook_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,81 @@ def test_min_confidence_filters(self, tmp_path):
)
assert code == 0

def test_min_confidence_keeps_unscored_spans(self, tmp_path, capsys):
"""Test min confidence keeps unscored spans."""
ctx = self.make_context(tmp_path)
code = run_main(
["--model-path", "stub", "--context-file", ctx, "--min-confidence", "0.5"],
{"transcript_path": str(FIXTURE)},
spans=[
{"text": "69 million", "hallucination_score": None},
{"text": "wrong version", "start": 0, "end": 13},
],
)
assert code == 2
captured = capsys.readouterr()
assert "69 million" in captured.err
assert "wrong version" in captured.err

def test_min_confidence_mixes_scored_and_unscored(self, tmp_path, capsys):
"""Test min confidence keeps unscored spans and drops scored ones."""
ctx = self.make_context(tmp_path)
code = run_main(
["--model-path", "stub", "--context-file", ctx, "--min-confidence", "0.5"],
{"transcript_path": str(FIXTURE)},
spans=[
{"text": "low confidence", "confidence": 0.1},
{"text": "native typed span", "category": "unsupported_addition"},
{"text": "high confidence", "confidence": 0.9},
],
)
assert code == 2
err = capsys.readouterr().err
assert "low confidence" not in err
assert "native typed span" in err
assert "high confidence" in err

def test_llm_mode_unscored_spans_reported_above_threshold(self, tmp_path, capsys):
"""Test llm mode unscored spans reported above threshold."""
ctx = self.make_context(tmp_path)
seen = {}

class StubDetector:
"""Stub LLM detector returning native-path spans without confidence."""

def __init__(self, **kwargs):
seen.update(kwargs)

def predict(self, **kwargs):
return [
{
"text": "added retry logic",
"start": 0,
"end": 19,
"category": "unsupported_addition",
}
]

with (
patch("sys.stdin", io.StringIO(json.dumps({"transcript_path": str(FIXTURE)}))),
patch("lettucedetect.models.inference.HallucinationDetector", StubDetector),
):
code = main(
[
"--llm-model",
"KRLabsOrg/lettucedect-v2-qwen-2b",
"--llm-base-url",
"http://localhost:8001/v1",
"--context-file",
ctx,
"--min-confidence",
"0.5",
]
)
assert seen["base_url"] == "http://localhost:8001/v1"
assert code == 2
assert "added retry logic" in capsys.readouterr().err

def test_invalid_stdin_exits_0(self):
"""Test invalid stdin exits 0."""
with patch("sys.stdin", io.StringIO("not json")):
Expand Down
Loading