mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-28 06:23:07 +00:00
test(anthropic): cover malformed content blocks in the survivor predicate
_survives_assistant_conversion had a separate non-dict guard that no test reached, since _is_empty_text_block already rejects non-dict blocks before the predicate runs on them in practice. Folding the check into the type lookup keeps the same behaviour for bare strings and blocks without a type key, with no unreachable branch. Extends the sibling-block test with a block missing its type key.
This commit is contained in:
parent
fd83156073
commit
4932047b2e
2 changed files with 3 additions and 4 deletions
|
|
@ -2024,9 +2024,7 @@ def _is_empty_text_block(block: object) -> bool:
|
|||
|
||||
|
||||
def _survives_assistant_conversion(block: object) -> bool:
|
||||
if not isinstance(block, dict):
|
||||
return False
|
||||
block_type = block.get("type")
|
||||
block_type = block.get("type") if isinstance(block, dict) else None
|
||||
if not isinstance(block_type, str) or block_type == "text":
|
||||
return False
|
||||
if block_type == "thinking":
|
||||
|
|
|
|||
|
|
@ -508,8 +508,9 @@ class TestMessageSanitization:
|
|||
{"type": "image_url", "image_url": {"url": "data:image/png;base64,aGk="}},
|
||||
{"type": "thinking", "thinking": ""},
|
||||
{"type": "unknown_future_block"},
|
||||
{"no_type_key": "malformed"},
|
||||
],
|
||||
ids=["image_url", "unsignable_thinking", "unknown_type"],
|
||||
ids=["image_url", "unsignable_thinking", "unknown_type", "missing_type"],
|
||||
)
|
||||
def test_empty_text_kept_when_sibling_block_would_not_survive(self, sibling_block):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue