litellm/tests/unit/responses/litellm_completion_transformation
joshua-berri 995aaa64f0
fix(responses): preserve deferred tool references on Anthropic routes (#52977)
* fix(responses): keep tool_reference blocks in function call outputs

The Responses to Chat bridge turned reference-only tool outputs into a JSON
string and dropped references that sat next to text, so Claude never saw
tools loaded through defer_loading. The bridge now keeps each valid
reference in order. Guardrail text extraction keeps its existing JSON
fallback, and malformed or unknown parts fall back as before.

Fixes #46681

* fix(responses): keep tool references only on Anthropic routes

Keeping tool_reference blocks for every bridge route turned the JSON text that
OpenAI and Vertex Gemini received into empty content. The flag now defaults to
off and is set from provider_builds_anthropic_request at the request send site
and in previous_response_id history replay, so inspection callers and
non-Anthropic routes keep their existing serialization. The reference check
moves into a small part decoder so the normalizer's complexity is unchanged.

* fix(responses): skip tool references when the route does not resolve

Checking the route with provider_builds_anthropic_request raised
BadRequestError for model aliases with no resolvable provider, such as batch
aliases. Both send sites now use the bridge's existing non-raising
_resolved_chat_config, so an unresolved alias keeps its existing tool output
serialization on the first turn and on previous_response_id replay.

---------

Co-authored-by: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com>
2026-11-19 15:55:31 -08:00
..
__init__.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_anthropic_responses_bridge.py fix(bedrock): stop the prefill 400 when the last user message is empty (#50701) 2026-11-18 03:44:11 +00:00
test_client_tool_search.py fix(responses): keep the namespace == name shape for deferred top-level tools (#50602) 2026-11-10 14:24:15 -08:00
test_compaction_items.py fix(responses)!: round-trip Anthropic compaction blocks as compaction items (#46754) 2026-10-21 08:50:19 +00:00
test_count_request.py fix(bedrock): stop the prefill 400 when the last user message is empty (#50701) 2026-11-18 03:44:11 +00:00
test_function_call_output_normalization.py fix(responses): preserve deferred tool references on Anthropic routes (#52977) 2026-11-19 15:55:31 -08:00
test_google_ai_studio_responses_bridge.py test: move the unit half of 126 mixed legacy files into tests/unit (#45090) 2026-10-07 14:07:43 -07:00
test_google_ai_studio_responses_wire.py fix(responses): normalize empty function_call_output to an empty tool result (#48845) 2026-10-30 11:01:00 -07:00
test_handler.py fix(bedrock): stop the prefill 400 when the last user message is empty (#50701) 2026-11-18 03:44:11 +00:00
test_image_generation_output.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_litellm_completion_responses.py fix(responses): preserve single-object input through the completion bridge (#52483) 2026-11-18 07:43:07 +00:00
test_reasoning_input_item_preservation.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_reasoning_items.py feat(proxy): mixed Codex model picker and LiteLLM routing on native codex routes (#49408) 2026-11-06 11:14:47 -08:00
test_session_handler.py fix(responses): preserve deferred tool references on Anthropic routes (#52977) 2026-11-19 15:55:31 -08:00
test_session_handler_with_cold_storage.py refactor(s3-log): move the rust-backed s3 logger from s3_v3 to s3_v2 (#51893) 2026-11-14 22:24:23 -08:00
test_streaming_iterator_transformation.py fix(responses): keep reasoning item IDs consistent across streaming events (#51243) 2026-11-11 15:49:46 -08:00
test_tool_output_order_preserved_for_gemini.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00