fix(bedrock): degrade gracefully on truncated tool-call arguments instead of failing the request - #32685
Conversation
…tead of failing the request A provider stream that ends mid-tool-call leaves a history item whose arguments string is truncated JSON. split_concatenated_json_objects raised JSONDecodeError on it, so _convert_to_bedrock_tool_call_invoke failed the whole request - and since every later turn replays the conversation, one truncated tool call permanently poisons the session (#18667 reported this class; the concatenated-objects fix in #20543 did not cover truncation). split_concatenated_json_objects now stops at an unparseable tail and returns the complete objects parsed before it; the existing empty-result fallback in _convert_to_bedrock_tool_call_invoke then emits toolUse.input={} so the paired toolResult stays addressable and the conversation continues.
Greptile SummaryThis PR fixes a deterministic request-poisoning bug where a Bedrock ConverseStream that ends mid-tool-call leaves a truncated JSON arguments string in the conversation history, causing every subsequent replay of that conversation to hard-fail with a
Confidence Score: 5/5Safe to merge — the change is a minimal, targeted catch-and-log in a single function with one production caller, and the existing fallback in that caller already handles the empty-result case correctly. The fix is a three-line try/except replacing a bare No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/litellm_core_utils/prompt_templates/common_utils.py | Wraps the inner decoder.raw_decode call in a try/except; on JSONDecodeError logs a warning and breaks instead of propagating. Minimal, targeted fix with clear logging. |
| tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_common_utils.py | Old "invalid JSON raises" test renamed and corrected to match the new degrade contract; two new splitter tests cover truncated-single-object and partial-salvage cases. |
| tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py | Two new end-to-end tests for _convert_to_bedrock_tool_call_invoke: exact production-truncation shape degrades to input={}, and salvage of a complete object before a truncated tail. |
Reviews (2): Last reviewed commit: "log a warning when an unparseable tool-c..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Withdrawing — we're handling this case on the client side instead. Thanks for the project.