You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(codecs): map Anthropic refusal stop reason to ContentFilter - #1752
Maps Anthropic's refusal stop reason to FinishReason::ContentFilter, so Anthropic safety refusals are normalized like the other codecs' safety stops instead of as Unknown("refusal").
I confirm this contribution is my own work, or I have the right to submit it under this project's license.
I searched existing issues and open pull requests, and this does not duplicate existing work.
Details
crates/core/src/codec/anthropic.rs: add "refusal" => FinishReason::ContentFilter to map_anthropic_stop_reason.
Consistent with the reverse mapping already in the PII-redaction crate, which maps ContentFilter to Anthropic's "refusal" (overlay.rs, trajectory_projection.rs).
stop_sequence and pause_turn are unchanged.
No breaking changes.
Tested on macOS, on release/0.11 at c56e0fd8:
The new test fails without the fix (Unknown("refusal") vs ContentFilter) and passes with it.
cargo nextest run -p nemo-relay -E 'test(~anthropic)': 88 passed.
Anthropic refusal responses will now report a content-filter finish reason instead of an unknown one. The change is small, tested, and easy to revert, so merge risk is minimal.
Security architecture risk: Minimal · up to 293b7
The change classifies Anthropic refusals using the existing safety-filter finish reason while preserving the original provider reason. No introduced or worsened security, state-ownership, or failure-containment risk was established.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The demonstrated exposure is to consumers of normalized Anthropic responses carrying stop_reason "refusal". Behavior in downstream consumers that distinguish Unknown from ContentFilter was not established.
Trust Boundaries and Controls
observed — Within the inspected decoder, the provider reason is classified as response metadata. The new classification does not gate tool-call extraction or invoke tools, and the original provider reason remains available.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title uses the Conventional Commits format with the allowed type 'fix' and scope 'codecs'. It is 63 characters, under the 72-character limit, has no trailing period, and uses an imperative summary…
Description check
The description follows the repository template. It includes the Overview with both checkboxes checked, the Details section listing the changed files and test, a Where should the reviewer start sectio…
Linked Issues check
Issue #1744 (direct) requires Anthropic stop_reason: "refusal" to normalize to FinishReason::ContentFilter, and requires a regression test for that mapping. At the reviewed head, `map_anthropic_st…
Out of Scope Changes check
The PR summary lists two changed files. crates/core/src/codec/anthropic.rs gains one mapping line, and crates/core/tests/unit/codec/anthropic_tests.rs gains the regression test for that line. Both…
Full details: Title check
Explanation
The title uses the Conventional Commits format with the allowed type 'fix' and scope 'codecs'. It is 63 characters, under the 72-character limit, has no trailing period, and uses an imperative summary. It matches the main change: mapping Anthropic's refusal stop reason to ContentFilter in the codec.
Full details: Description check
Explanation
The description follows the repository template. It includes the Overview with both checkboxes checked, the Details section listing the changed files and test, a Where should the reviewer start section pointing to map_anthropic_stop_reason, and a Related Issues section with 'Closes #1744'. It also gives testing evidence and notes that stop_sequence and pause_turn are unchanged.
Full details: Linked Issues check
Explanation
Issue #1744 (direct) requires Anthropic stop_reason: "refusal" to normalize to FinishReason::ContentFilter, and requires a regression test for that mapping. At the reviewed head, map_anthropic_stop_reason in crates/core/src/codec/anthropic.rs contains "refusal" => FinishReason::ContentFilter, and the other stop reasons keep their prior mappings. crates/core/tests/unit/codec/anthropic_tests.rs contains test_decode_response_finish_reason_refusal, which decodes a response with stop_reason: "refusal" and asserts FinishReason::ContentFilter. The issue's optional stop_sequence alignment is excluded by the issue text and is unchanged here, as the issue states. The issue's coding requirements are met. The author-reported test results were not re-run in this review. The whole-PR diff could not be read, so the change set rests on the supplied summary and the two files inspected at head.
Full details: Out of Scope Changes check
Explanation
The PR summary lists two changed files. crates/core/src/codec/anthropic.rs gains one mapping line, and crates/core/tests/unit/codec/anthropic_tests.rs gains the regression test for that line. Both changes directly implement #1744. No unrelated code, refactoring, or documentation changes are reported. The PR description states that no other stop reasons or breaking changes are introduced. The full diff could not be read (changed blobs unavailable in the checkout), so this verdict relies on the supplied summary and the head file contents inspected.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Reviewing files that changed from the base of the PR and between c56e0fd and 293b74a.
Files selected for processing: 2
crates/core/src/codec/anthropic.rs
crates/core/tests/unit/codec/anthropic_tests.rs
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.
Recent review details
Context from checks skipped due to timeout: 1
GitHub Check: CodeRabbit
Additional context used
Path-based instructions: 2
Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.
CodeRabbit configuration file
Files:
crates/core/tests/unit/codec/anthropic_tests.rs
Review the Rust runtime for async correctness, scope isolation, middleware ordering, and event lifecycle regressions.
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
Bugissue describes bug; PR fixes buglang:rustPR changes/introduces Rust codesize:XSPR is extra small
2 participants
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.
Overview
Maps Anthropic's
refusalstop reason toFinishReason::ContentFilter, so Anthropic safety refusals are normalized like the other codecs' safety stops instead of asUnknown("refusal").Details
crates/core/src/codec/anthropic.rs: add"refusal" => FinishReason::ContentFiltertomap_anthropic_stop_reason.crates/core/tests/unit/codec/anthropic_tests.rs: addtest_decode_response_finish_reason_refusal.ContentFilterto Anthropic's"refusal"(overlay.rs,trajectory_projection.rs).stop_sequenceandpause_turnare unchanged.Tested on macOS, on
release/0.11atc56e0fd8:Unknown("refusal")vsContentFilter) and passes with it.cargo nextest run -p nemo-relay -E 'test(~anthropic)': 88 passed.just test-rust: 6726 passed, 4 skipped (withulimit -n 4096, since test(cli): raise the open-file limit for HTTP/1.1 concurrency tests #1736 is onmainonly).cargo fmt --all -- --checkandcargo clippy -p nemo-relay --all-targets -- -D warningspass.npm auditanduv audit, which I skipped; this change touches no lockfiles.Not tested on Linux or Windows; CI covers those.
Where should the reviewer start?
map_anthropic_stop_reasonincrates/core/src/codec/anthropic.rs.Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)
Closes #1744
Summary by CodeRabbit