feat(providers/anthropic): surface refusal stop_reason as content-filter#41
Draft
jscottmiller wants to merge 2 commits into
Draft
feat(providers/anthropic): surface refusal stop_reason as content-filter#41jscottmiller wants to merge 2 commits into
jscottmiller wants to merge 2 commits into
Conversation
Map Anthropic's "refusal" stop_reason to FinishReasonContentFilter and capture stop_details (category, explanation) into the finish part's ProviderMetadata via a new RefusalMetadata type, so callers can surface why a turn produced no content. Coder Agents generated.
Author
|
Verified the claim in the
So the raw-JSON parsing is the right call today. Suggested follow-ups, not blocking:
Coder Agents generated (on behalf of @jscottmiller). |
… the pinned SDK fork
Author
|
Merge-order note relative to #40 (the main -> coder_2_33 sync):
Since the refusal mapping is not Coder-specific, it is also a candidate to send upstream to charmbracelet/fantasy rather than carrying it as a fork patch long-term. Coder Agents generated (on behalf of @jscottmiller). |
Author
|
/coder-agents-review |
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
Map Anthropic's
refusalstop reason to a content-filter finish reason andpreserve the block details, so downstream callers can tell a safety block apart
from a normal stop and surface why a turn produced no content.
Anthropic's real-time safety classifiers end a response with
stop_reason: "refusal"and astop_detailsobject (category,explanation), and emit no content. PreviouslymapFinishReasonfell throughto
FinishReasonUnknownand the details were dropped.Changes
mapFinishReason:"refusal"->FinishReasonContentFilter.stop_detailsfrom themessage_deltaraw JSON (the Anthropic SDK doesnot model it) and attach it to the finish stream part via a new
RefusalMetadata{Category, Explanation}provider-metadata type(registered, marshal/unmarshal,
GetRefusalMetadatagetter).Testing
go test ./providers/anthropic/(newrefusal_test.gocovers the finish-reasonmapping,
stop_detailsparsing, and metadata round-trip).Notes
Consumed by coder/coder PR for chat "Response blocked" messaging.
Coder Agents generated.