fix(client): reject malformed sampled-token evidence#108
Merged
hallerite merged 2 commits intoJul 21, 2026
Conversation
Require one finite, non-sentinel sampling logprob per returned completion token before parsing the response. Preserve valid zero values instead of treating them as missing.
hallerite
approved these changes
Jul 21, 2026
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/inference/v1/generatesampled-token evidence before renderer parsingtoken_id:<id>-9999.0evidenceMalformedGenerateResponseErrorso callers can distinguish an unusable provider response from other failuresWhy
The generate response contains parallel
token_idsandlogprobs.contentfields. Matching their lengths alone does not prove that a logprob belongs to the sampled token at that position.The vLLM endpoint labels each entry with
token_id:<id>. It also uses-9999.0both as the default when evidence is absent and as a lower-bound clamp. That value therefore cannot prove the original sampled-token logprob and must fail closed.Validation belongs before renderer parsing because this is a provider wire-contract invariant. Downstream rollout and training code should not receive incomplete or misbound sampling evidence as a successful generation.
Compatibility
Malformed responses now raise
MalformedGenerateResponseError, aValueErrorsubclass. This intentionally tightens behavior while retaining compatibility with callers that already handleValueError. The exported subtype lets downstream clients map this provider failure explicitly.Verification
uv run pytest tests/test_client.py -q— 20 passed, 2 skippeduv run ruff check renderers/client.py renderers/__init__.py tests/test_client.pyuv run ruff format --check renderers/client.py renderers/__init__.py tests/test_client.pyNote
Medium Risk
Rollout/training paths that relied on silently accepting bad or placeholder logprobs will now error at generation time, which is intentional but can surface more provider failures.
Overview
Tightens how completion logprobs are read from
/inference/v1/generateresponses. Instead of coercing missinglogprobsto0.0, the client runs_parse_completion_logprobsbeforerenderer.parse_response.Validation requires one
choice.logprobs.contententry per completion token, each labeledtoken_id:<id>matching that position’s sampled id, with a finite numericlogprob. It rejects vLLM’s-9999.0sentinel when it indicates missing sampling evidence. Failures raise the new exportedMalformedGenerateResponseError(ValueErrorsubclass).Tests cover malformed/missing logprobs, count and token-id mismatches, non-finite values, and that invalid responses fail before renderer parsing; valid
0.0logprobs still pass through.Reviewed by Cursor Bugbot for commit 07ce506. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Reject malformed sampled-token evidence in
generatewithMalformedGenerateResponseErrorMalformedGenerateResponseError(aValueErrorsubclass) torenderers/client.pyand exports it from therendererspackage._parse_completion_logprobsto strictly validate per-token logprobs: checks structural alignment withtoken_ids, rejects non-numeric/non-finite values, and rejects the vLLM missing-evidence sentinel (-9999.0).generate()now calls_parse_completion_logprobsinstead of loosely extracting logprobs, raisingMalformedGenerateResponseErroron any validation failure while preserving exact zero values.Macroscope summarized 07ce506.