Skip to content

fix(ifeval): count characters, not bytes, in tolerance check - #1195

Merged
Mostelk merged 1 commit into
masterfrom
fix-ifeval-char-length
Nov 3, 2026
Merged

Mostelk merged 1 commit into
masterfrom
fix-ifeval-char-length

Conversation

@AhmedTElthakeb

Copy link
Copy Markdown
Contributor

Problem

ends_with / starts_with (used by startend:end_checker and combination:repeat_prompt) and ConstrainedResponse allow 3 extra characters around the expected text, but measure them with std::string::size(), which counts bytes. The Python reference uses len(), which counts characters. Any non-ASCII character in that window makes the C++ check fail where Python passes.

Example: "My answer is no. ⁇ " is 19 characters (limit 16 + 3, passes in Python) but 21 bytes (fails in C++).

Proposed Fix

Add utf8_len (character count) and utf8_offset (byte offset of the n-th character) to common.h, and use them to size the comparison window in ends_with / starts_with and the length check in ConstrainedResponse. The window is clamped to the string length. ASCII input behaves as before.

@AhmedTElthakeb
AhmedTElthakeb requested review from a team and anhappdev as code owners November 3, 2026 02:00
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅

@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@freedomtan

Copy link
Copy Markdown
Contributor

@farook-edev please copy this to the standalone one.

@Mostelk
Mostelk merged commit 763e50b into master Nov 3, 2026
37 checks passed
@Mostelk
Mostelk deleted the fix-ifeval-char-length branch November 3, 2026 23:41
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants