fix: map Zhipu GLM non-standard finish_reason values - #24373
Merged
Chesars merged 1 commit intoMar 22, 2026
Merged
Conversation
Zhipu GLM returns non-standard finish_reason values during streaming when inference fails mid-request, causing Pydantic validation crash: - "network_error" (inference interrupted) → map to "stop" - "sensitive" (content policy violation) → map to "content_filter" Fixes BerriAI#23386
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile SummaryThis PR fixes a Pydantic validation crash in
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| litellm/litellm_core_utils/core_helpers.py | Adds two Zhipu GLM finish reason mappings ("network_error" → "stop", "sensitive" → "content_filter") to the centralized _FINISH_REASON_MAP. Change is minimal and correct; minor concern around generic key names potentially colliding with future providers. |
| tests/test_litellm/litellm_core_utils/test_core_helpers.py | Adds TestMapFinishReasonZhipu class with two unit tests covering the new mappings. Tests are local-only (no network calls), follow the established test pattern, and are correctly placed in the mocked test directory. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Provider stream chunk] --> B{finish_reason in\n_FINISH_REASON_MAP?}
B -- Yes --> C[Return mapped OpenAI value]
B -- No --> D[Log warning]
D --> E[Return 'stop' default]
subgraph Zhipu GLM new mappings
F["'network_error'"] --> G["'stop'"]
H["'sensitive'"] --> I["'content_filter'"]
end
C --> J[Pydantic validates\nOpenAIChatCompletionFinishReason]
J --> K[stream_chunk_builder succeeds]
Reviews (1): Last reviewed commit: "fix: map Zhipu GLM non-standard finish_r..." | Re-trigger Greptile
Contributor
Chesars
merged commit Mar 22, 2026
de91bbb
into
BerriAI:litellm_staging_03_22_2026
38 of 39 checks passed
fzowl
pushed a commit
to fzowl/litellm
that referenced
this pull request
Jun 24, 2026
…-mapping fix: map Zhipu GLM non-standard finish_reason values
2 tasks
This was referenced Aug 25, 2026
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.
Relevant issues
Fixes #23386
Pre-Submission checklist
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewType
🐛 Bug Fix
Changes
Zhipu GLM returns non-standard
finish_reasonvalues during streaming when inference fails mid-request. These values are not in LiteLLM's_FINISH_REASON_MAP, causing a Pydantic validation crash instream_chunk_builder.Add two mappings to the centralized
_FINISH_REASON_MAPincore_helpers.py:"network_error"→"stop"(inference interrupted)"sensitive"→"content_filter"(content policy violation)Tests added
TestMapFinishReasonZhipu::test_network_errorTestMapFinishReasonZhipu::test_sensitive