litellm/tests/test_litellm/llms/anthropic
yucheng-berri 1018d18e6b
fix(anthropic): split mixed stream chunks by payload kind (#35289)
* fix(anthropic): split mixed reasoning stream chunks

* style: use builtin generic annotation

* fix(anthropic): split mixed stream chunks by payload kind

The mixed-chunk split cleared only the fields it knew about on each
deep-copied piece, so any other payload riding the chunk survived on
both pieces: tool_calls were emitted as two tool_use blocks with the
same id, thinking_blocks on the text piece emitted duplicated thinking
into a text block while dropping the answer text, and chunks whose
reasoning arrived only as thinking_blocks never split at all

Rebuild each piece's delta from scratch with exactly one payload kind
(reasoning, text, tool calls), ordered to match native Anthropic block
order. Fresh Delta construction keeps unset attributes deleted, which
matters because the translators branch on hasattr, and prevents future
Delta fields from riding along on every piece

* fix(anthropic): keep continuation and multi-choice chunks unsplit, emit signature-less thinking once

Adversarial verification against the merge-base found three shapes where
the payload-kind split changed behavior beyond its target: a mixed chunk
carrying a tool argument continuation was torn into a truncated block
plus a fabricated one, a multi-choice chunk lost its secondary choices'
payload, and a signature-less thinking_blocks piece inherited the
non-empty block start body so accumulators collected the thinking twice

Continuation and multi-choice chunks now pass through the splitter
untouched, matching the merge-base byte for byte, and signature-less
thinking_blocks pieces are normalized to reasoning_content so the block
start opens empty and the thinking text is emitted exactly once

---------

Co-authored-by: Napuh <naamanynadiemas@gmail.com>
2026-07-31 02:05:18 +00:00
..
batches test(batches): add 1:1 test file scaffold for batches component paths (#30529) 2026-06-29 09:22:58 +05:30
chat fix(guardrails): add /v1/messages support for Straiker plugin (#34548) 2026-07-24 17:13:11 -07:00
experimental_pass_through fix(anthropic): split mixed stream chunks by payload kind (#35289) 2026-07-31 02:05:18 +00:00
files fix(batches): price anthropic passthrough message batches correctly in batch cost job (#32307) 2026-07-06 20:33:57 -07:00
messages fix(router): don't cool down parent deployment on advisor sub-call failure (#33792) 2026-07-25 10:17:13 -07:00
__init__.py test(batches): add 1:1 test file scaffold for batches component paths (#30529) 2026-06-29 09:22:58 +05:30
test_anthropic_common_utils.py fix(anthropic): self-heal on missing thinking-signature errors from Bedrock/Vertex (#33719) 2026-07-17 18:18:38 +00:00
test_anthropic_count_tokens_transformation.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_anthropic_files_and_batches.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_anthropic_output_format_filter.py fix(anthropic): strip all remaining output_format schema keywords rejected by Anthropic 2026-07-22 16:16:04 -07:00
test_anthropic_structured_output.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_azure_ai_cache_pricing.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_cost_calculation_dict_safety.py fix: completion_cost AttributeError on streaming Anthropic web_search responses (#26153) (#27346) 2026-06-10 21:20:11 -07:00
test_count_tokens_oauth.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_message_sanitization.py fix(anthropic, mcp): sanitize tool names to match Anthropic's [a-zA-Z0-9_-]{1,128} pattern (#26788) 2026-05-06 00:00:36 +00:00