Skip to content

fix(codecs): map Anthropic refusal stop reason to ContentFilter - #1752

Merged
greysonlalonde merged 3 commits into
NVIDIA:release/0.11from
Sakshitapkir03:fix/anthropic-refusal-finish-reason-0.11
Nov 17, 2026
Merged

greysonlalonde merged 3 commits into
NVIDIA:release/0.11from
Sakshitapkir03:fix/anthropic-refusal-finish-reason-0.11

Conversation

@Sakshitapkir03

@Sakshitapkir03 Sakshitapkir03 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Overview

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.
  • crates/core/tests/unit/codec/anthropic_tests.rs: add test_decode_response_finish_reason_refusal.
  • 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.
  • just test-rust: 6726 passed, 4 skipped (with ulimit -n 4096, since test(cli): raise the open-file limit for HTTP/1.1 concurrency tests #1736 is on main only).
  • cargo fmt --all -- --check and cargo clippy -p nemo-relay --all-targets -- -D warnings pass.
  • Pre-commit hooks pass, except npm audit and uv 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_reason in crates/core/src/codec/anthropic.rs.

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

Closes #1744

Summary by CodeRabbit

  • Bug Fixes
    • Anthropic refusal responses are now classified as content-filtered completions.

@Sakshitapkir03
Sakshitapkir03 requested a review from a team as a code owner November 16, 2026 23:44
@copy-pr-bot

copy-pr-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added size:XS PR is extra small Bug issue describes bug; PR fixes bug lang:rust PR changes/introduces Rust code labels Nov 16, 2026
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 293b74a and ba6f239.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • No new commits to review - use @coderabbitai full review for a full pass

No actionable comments were generated in the recent review.

Walkthrough

The Anthropic codec now maps the "refusal" stop reason to FinishReason::ContentFilter. A response-decoding test verifies the mapping.

Changes

Anthropic refusal mapping

Layer / File(s) Summary
Map refusal and verify decoding
crates/core/src/codec/anthropic.rs, crates/core/tests/unit/codec/anthropic_tests.rs
The stop-reason mapping returns ContentFilter for "refusal". A response-decoding test checks the result.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · previous review 293b7

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed 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 Passed 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
Recent review info

Run configuration

Commits

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.

CodeRabbit configuration file

Files:

  • crates/core/src/codec/anthropic.rs
  • crates/core/tests/unit/codec/anthropic_tests.rs

@greysonlalonde

Copy link
Copy Markdown
Contributor

/ok to test 293b74a

@github-actions

Copy link
Copy Markdown

@greysonlalonde

Copy link
Copy Markdown
Contributor

/ok to test ba6f239

@greysonlalonde greysonlalonde left a comment

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.

Thank you @Sakshitapkir03 !

@greysonlalonde
greysonlalonde merged commit 6b7afd5 into NVIDIA:release/0.11 Nov 17, 2026
169 of 171 checks passed
@Sakshitapkir03
Sakshitapkir03 deleted the fix/anthropic-refusal-finish-reason-0.11 branch November 18, 2026 17:51

This branch was previously deployed

1 inactive deployment
fern — ba6f2398 Deployed Nov 17, 2026 by copy-pr-bot[bot] via Preview docs #7371
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug issue describes bug; PR fixes bug lang:rust PR changes/introduces Rust code size:XS PR is extra small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Anthropic codec maps stop_reason: "refusal" to FinishReason::Unknown instead of ContentFilter

2 participants