Repository navigation
Pass through unmapped Anthropic stop reasons - #1117
PratikDhanave (PratikDhanave) wants to merge 3 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.
💡 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.
This comment has been minimized.
This comment has been minimized.
|
Copilot resolve the merge conflicts in this pull request |
…reason-passthrough # Conflicts: # go.mod # go.sum
API consistency review
Changed Go contract
Upstream evidence reviewedAssessmentThe Go change is a direct, faithful parity fix: it makes the Anthropic provider's unmapped-stop-reason behavior match the Python client's documented pass-through semantics exactly (same motivating example, same fallback-to-raw-value approach), while still returning Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
To allow these domains, add them to the network:
allowed:
- defaults
- "github.com"See Network Configuration for more information.
|


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.