Pass through unmapped Anthropic stop reasons - #1117
PratikDhanave (PratikDhanave) wants to merge 2 commits into
Conversation
mapStopReason returned "" for any stop_reason outside its fixed set, so a newer value such as model_context_window_exceeded was reported as no finish reason at all. Pass unmapped reasons through unchanged, matching the Python client (an empty reason still maps to "").
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Update the stale function comment to document the new pass-through behavior.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Updates Anthropic stop-reason handling so unknown non-empty values reach callers unchanged.
Changes:
- Passes through unmapped stop reasons.
- Adds non-streaming and streaming test coverage.
| File | Description |
|---|---|
provider/anthropicprovider/agent.go |
Passes through unknown stop reasons. |
provider/anthropicprovider/agent_test.go |
Tests pass-through behavior in both paths. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // Pass through stop reasons we don't explicitly map (e.g. a newer | ||
| // value like model_context_window_exceeded) so they still reach the | ||
| // caller instead of being reported as no finish reason, matching the | ||
| // Python client. An empty reason maps to "". | ||
| return string(reason) |
This comment has been minimized.
This comment has been minimized.
Update the stale comment to reflect that only an empty reason returns ""; unrecognized non-empty reasons are now passed through unchanged.
|
Scope: user-visible behavior Changed Go contract: No exported symbols changed, but observable runtime behavior does: the Upstream evidence reviewed: Result: aligned. This change makes the Go
|

mapStopReason returned
""for anystop_reasonnot in its fixed set, so a value the Anthropic API may add later — e.g.model_context_window_exceeded— was reported as no finish reason instead of reaching the caller. This affects both the non-streaming path and the streaming final update.The Python client passes unmapped reasons through unchanged:
FINISH_REASON_MAP.get(stop_reason, stop_reason), with an explicit docstring that newer API values likemodel_context_window_exceededmust still reach the caller.Change
defaultcase toreturn string(reason). An empty reason still yields"", so the streamingif fr != ""guard is unaffected.StopReasonis a plain string in the anthropic SDK.Test
{"model_context_window_exceeded", "model_context_window_exceeded"}row to the sharedfinishReasonCasestable (runs through bothTestNonStreamingFinishReasonandTestStreamingFinishReason). Fails before (""), passes after.