fix(core_helpers): map generic 'error' finish_reason to 'stop' (#33972)

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
devin-ai-integration[bot] 2026-08-05 22:39:12 +00:00 committed by GitHub
parent 265945dfcd
commit aa1180c0c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View file

@ -131,6 +131,9 @@ _FINISH_REASON_MAP: Final[dict[str, OpenAIChatCompletionFinishReason]] = {
"content_filter": "content_filter",
# Anthropic Sonnet 4
"content_filtered": "content_filter",
# Generic error passthrough (OpenRouter and other OpenAI-compatible providers
# emit lowercase "error" when a provider fails mid-stream)
"error": "stop",
}

View file

@ -192,6 +192,19 @@ class TestMapFinishReasonOpenAIPassthrough:
assert map_finish_reason(reason) == reason
class TestMapFinishReasonGenericError:
def test_lowercase_error_is_explicitly_mapped(self):
assert "error" in _FINISH_REASON_MAP
assert map_finish_reason("error") == "stop"
def test_lowercase_error_does_not_warn(self, mocker):
warn = mocker.patch(
"litellm.litellm_core_utils.core_helpers.verbose_logger.warning"
)
assert map_finish_reason("error") == "stop"
warn.assert_not_called()
class TestMapFinishReasonUnknown:
def test_unknown_value_defaults_to_stop(self):
assert map_finish_reason("some_unknown_value") == "stop"