The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test: add direct coverage for content_filter and refusal in anthropic and responses adapters
tusharjamunkare54399eff7a1
diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.pyindex 03b9840b1c3..0e09e27f4db 100644--- a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py+++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py@@ -102,6 +102,46 @@ def test_translate_chat_length_takes_precedence_over_refusal():assert result.get("stop_details") is None+def test_translate_chat_content_filter_to_anthropic_response():+ response = ModelResponse(+ id="chatcmpl-content-filter",+ model="openai-model",+ choices=[+ Choices(+ index=0,+ finish_reason="content_filter",+ message=Message(content=None, role="assistant"),+ )+ ],+ usage=Usage(prompt_tokens=1, completion_tokens=0, total_tokens=1),+ )++ result = LiteLLMAnthropicMessagesAdapter().translate_openai_response_to_anthropic(response)++ assert result["content"] == []+ assert result["stop_reason"] == "refusal"+++def test_translate_chat_refusal_finish_reason_to_anthropic_response():+ response = ModelResponse(+ id="chatcmpl-refusal-reason",+ model="openai-model",+ choices=[+ Choices(+ index=0,+ finish_reason="refusal",+ message=Message(content=None, role="assistant"),+ )+ ],+ usage=Usage(prompt_tokens=1, completion_tokens=0, total_tokens=1),+ )++ result = LiteLLMAnthropicMessagesAdapter().translate_openai_response_to_anthropic(response)++ assert result["content"] == []+ assert result["stop_reason"] == "refusal"++def test_translate_streaming_openai_chunk_to_anthropic_content_block():choices = [StreamingChoices(diff --git a/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py b/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.pyindex 46249e50572..f2ebbf316c3 100644--- a/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py+++ b/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py@@ -4246,3 +4246,65 @@ class TestStreamingSnapshotItemIds:reasoning_items = _bridged_output_items(completed_event.response, "reasoning")assert len(reasoning_items) == 1assert reasoning_items[0].id == streamed_event.item_id+++def test_transform_chat_completion_response_incomplete_details():+ from openai.types.responses.response import IncompleteDetails++ resp_length = ModelResponse(+ id="resp-length",+ choices=[Choices(index=0, finish_reason="length", message=Message(content="cutoff", role="assistant"))],+ model="gpt-4o",+ )+ result_length = LiteLLMCompletionResponsesConfig.transform_chat_completion_response_to_responses_api_response(+ request_input="test prompt",+ responses_api_request={},+ chat_completion_response=resp_length,+ )+ assert result_length.status == "incomplete"+ assert result_length.incomplete_details is not None+ assert result_length.incomplete_details.reason == "max_output_tokens"++ resp_filter = ModelResponse(+ id="resp-filter",+ choices=[Choices(index=0, finish_reason="content_filter", message=Message(content=None, role="assistant"))],+ model="gpt-4o",+ )+ result_filter = LiteLLMCompletionResponsesConfig.transform_chat_completion_response_to_responses_api_response(+ request_input="test prompt",+ responses_api_request={},+ chat_completion_response=resp_filter,+ )+ assert result_filter.status == "incomplete"+ assert result_filter.incomplete_details is not None+ assert result_filter.incomplete_details.reason == "content_filter"++ resp_refusal = ModelResponse(+ id="resp-refusal",+ choices=[Choices(index=0, finish_reason="refusal", message=Message(content=None, role="assistant"))],+ model="gpt-4o",+ )+ result_refusal = LiteLLMCompletionResponsesConfig.transform_chat_completion_response_to_responses_api_response(+ request_input="test prompt",+ responses_api_request={},+ chat_completion_response=resp_refusal,+ )+ assert result_refusal.status == "incomplete"+ assert result_refusal.incomplete_details is not None+ assert result_refusal.incomplete_details.reason == "content_filter"++ existing_details = IncompleteDetails(reason="content_filter")+ resp_existing = ModelResponse(+ id="resp-existing",+ choices=[Choices(index=0, finish_reason="length", message=Message(content="cutoff", role="assistant"))],+ model="gpt-4o",+ )+ resp_existing.incomplete_details = existing_details+ result_existing = LiteLLMCompletionResponsesConfig.transform_chat_completion_response_to_responses_api_response(+ request_input="test prompt",+ responses_api_request={},+ chat_completion_response=resp_existing,+ )+ assert result_existing.status == "incomplete"+ assert result_existing.incomplete_details == existing_details+