Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix(506): apply review wording and docstring fixes
  • Loading branch information
harrycav committed Nov 17, 2026
commit 4b8f50b4d40c8be8ef3507124df5e98be11c6e7c
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Each release links to full notes on the
and now score 0.0 with a `UserWarning`, and replies that only contained
"true" as a substring (`untrue`, `Not true`) no longer match. Formatted
replies still match: surrounding whitespace, quotes, backticks, markdown
emphasis and trailing punctuation are stripped and case is ignored, so
`**True**.` scores 1.0 and `"false"` scores 0.0. Any other reply scores 0.0
and warns, showing the start of the reply, rather than raising.
emphasis and trailing `.` `,` `;` `:` `!` `?` are stripped and case is
ignored, so `**True**.` scores 1.0 and `"false"` scores 0.0. Any other reply
scores 0.0 and warns, showing the start of the reply, rather than raising.

- Corrected introductory example scores, the default text comparator description,
and the sample amount in the documentation and README
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/Guides/Comparators/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ The default model is `distilbert-base-uncased`, loaded globally via the `evaluat

### LLMComparator

Uses a Large Language Model (via AWS Bedrock and the `strands-agents` library) to perform intelligent semantic comparisons. The LLM receives both values and optional evaluation guidelines, then returns a binary equivalence judgment: 1.0 only when the normalised reply is exactly `true`, otherwise 0.0 (with a `UserWarning` when the reply is neither `true` nor `false`). See [LLM-as-a-Judge](llm-as-a-judge.md#llmcomparator) for the exact rule. This is the most flexible comparator but also the most expensive.
Uses a Large Language Model (via AWS Bedrock and the `strands-agents` library) to perform intelligent semantic comparisons. The LLM receives both values and optional evaluation guidelines, then returns a binary equivalence judgment: 1.0 only when the normalized reply is exactly `true`, otherwise 0.0 (with a `UserWarning` when the reply is neither `true` nor `false`). See [LLM-as-a-Judge](llm-as-a-judge.md#llmcomparator) for the exact rule. This is the most flexible comparator but also the most expensive.

**When to use:** Complex comparisons that require reasoning, domain-specific logic, or understanding of abbreviations and conventions. See [LLM-as-a-Judge Comparators](llm-as-a-judge.md) for a detailed guide.

Expand Down
7 changes: 5 additions & 2 deletions docs/docs/Guides/Comparators/llm-as-a-judge.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ The `LLMComparator` sends both values to a Large Language Model and asks it to d
1. A prompt is constructed with both values and optional evaluation guidelines using a Jinja2 template.
2. The prompt is sent to an LLM via the `strands-agents` library and AWS Bedrock.
3. The LLM is asked to reply with one word, `true` or `false`.
4. The reply is normalised: surrounding whitespace, quotes, backticks and markdown emphasis (`*`, `_`) and trailing punctuation are stripped, and case is ignored. Exactly `true` scores 1.0 and exactly `false` scores 0.0, so `**True**.` and `"false"` are read as verdicts.
4. The reply is normalized: surrounding whitespace, quotes, backticks and markdown emphasis (`*`, `_`) and any trailing `.` `,` `;` `:` `!` `?` are stripped, and case is ignored. Exactly `true` scores 1.0 and exactly `false` scores 0.0, so `**True**.` and `"false"` are read as verdicts.
5. Any other reply, such as `untrue`, `Not true` or `True, they are equivalent.`, scores 0.0 and emits a `UserWarning` showing the start of the reply. It does not raise, so one verbose reply does not stop a bulk run.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: step 5 covers this, but the Custom Evaluation Guidelines section at :175 could cross-reference it. A guideline like "explain your reasoning", if the model follows it, turns positive verdicts into 0.0 with a warning. Something like: "Guidelines should only shape the judgment, not the reply format: the model must still answer with one word, and a reply that adds reasoning scores 0.0 with a warning."


### Setup
Expand Down Expand Up @@ -186,6 +186,8 @@ comparator = LLMComparator(
)
```

Guidelines should only shape the judgment, not the reply format: the model must still answer with one word, and a reply that adds reasoning scores 0.0 with a warning (see step 5 above).

### Example

This example is based on the [`examples/scripts/llm_comparator_demo.py`](https://github.com/awslabs/stickler/blob/main/examples/scripts/llm_comparator_demo.py) script.
Expand Down Expand Up @@ -235,7 +237,8 @@ comparator = LLMComparator(

details = comparator.get_comparison_details("St. John's Street", "Saint John's St")
print(details["prompt"]) # The formatted prompt sent to the LLM
print(details["llm_response"]) # Raw LLM reply, before normalisation
print(details["llm_response"]) # Raw reply from one LLM call, not normalized
# (the score below comes from a separate call)
print(details["comparison_result"]) # Final score (1.0 or 0.0)
```

Expand Down
2 changes: 1 addition & 1 deletion src/stickler/comparators/Comparators.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ comparator = LLMComparator(
- Uses LLM to determine semantic equivalence
- Customizable prompt templates
- Configurable temperature
- Binary output: 1.0 only when the normalised reply is exactly `true`; any other reply scores 0.0 (with a `UserWarning` unless it is exactly `false`)
- Binary output: 1.0 only when the normalized reply is exactly `true`; any other reply scores 0.0 (with a `UserWarning` unless it is exactly `false`)
- Note: Implementation in progress

### 4. Structured Data Comparators
Expand Down
20 changes: 10 additions & 10 deletions src/stickler/comparators/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,18 @@ def _compare(self, value1: Any, value2: Any) -> float:
value2: Second value to compare. Can be any type that converts to string.

Returns:
float: Binary similarity score:
- 1.0 if the LLM replies exactly ``true``
- 0.0 if the LLM replies exactly ``false``
- 0.0, with a ``UserWarning``, for any other reply. Before
comparing, surrounding whitespace, quotes, backticks and
markdown emphasis and trailing punctuation are stripped and
case is ignored.
- 0.0 if an error occurs during comparison
float: 1.0 if the normalized reply is exactly ``true``, otherwise 0.0.
Normalizing strips surrounding whitespace, quotes, backticks and
markdown emphasis, strips trailing ``.,;:!?``, and ignores case. A
reply that is neither ``true`` nor ``false`` also emits a
``UserWarning``.

Raises:
NoCredentialsError: If AWS credentials are not found.
Exception: Any other error from the LLM call is re-raised.

Note:
- Error handling: Returns 0.0 for any exceptions during LLM calls
- Cost consideration: Each call incurs API costs and latency
Cost consideration: Each call incurs API costs and latency.

Example:
>>> comparator = LLMComparator()
Expand Down
2 changes: 1 addition & 1 deletion tests/common/comparators/test_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test_ambiguous_response(self):
result = self.comparator.compare("value1", "value2")
assert result == 0.0, f"Failed for response: {response}"

# #506: the verdict is the normalised reply, compared exactly. A substring
# #506: the verdict is the normalized reply, compared exactly. A substring
# test scored "untrue" and "Not true" as matches.
@pytest.mark.parametrize(
"response",
Expand Down
Loading