langchain-ai
langchain
BlogDocsChangelog

fix(anthropic): clean up `cache_control` in middleware to prevent fallback errors

#33894
Comparing
yashwantbezawada:fix/anthropic-cache-control-cleanup-issue-33709
(
2cb902d
) with
master
(
cc3af82
)
CodSpeed Performance Gauge
0%
Untouched
3
Skipped
31

Benchmarks

Skipped (31)

test_create_chat_prompt_init_time
libs/partners/prompty/tests/unit_tests/test_standard.py
Skipped
311.9 µs*
test_exa_retriever_init_time
libs/partners/exa/tests/unit_tests/test_standard.py
Skipped
325.3 µs*
test_nomic_embeddings_init_time
libs/partners/nomic/tests/unit_tests/test_standard.py
Skipped
1.5 ms*
test_qdrant_vectorstore_init_time
libs/partners/qdrant/tests/unit_tests/test_standard.py
Skipped
224.2 ms*
test_init_time
libs/partners/xai/tests/unit_tests/test_chat_models_standard.py::TestXAIStandard
Skipped
3.3 s*
test_init_time
libs/partners/deepseek/tests/unit_tests/test_chat_models.py::TestChatDeepSeekUnit
Skipped
1.6 s*
test_init_time
libs/partners/fireworks/tests/unit_tests/test_standard.py::TestFireworksStandard
Skipped
6.6 s*
test_init_time
libs/partners/mistralai/tests/unit_tests/test_standard.py::TestMistralStandard
Skipped
9.1 ms*
test_init_time
libs/partners/ollama/tests/unit_tests/test_chat_models.py::TestChatOllama
Skipped
1.6 s*
test_stream_time
libs/partners/openai/tests/integration_tests/chat_models/test_responses_standard.py::TestOpenAIResponses
Skipped
858.1 ms*
test_stream_time
libs/partners/openai/tests/integration_tests/chat_models/test_base_standard.py::TestOpenAIStandard
Skipped
1.2 s*
test_stream_time
libs/partners/openai/tests/integration_tests/chat_models/test_responses_standard.py::TestOpenAIStandard
Skipped
1.1 s*
test_init_time
libs/partners/openai/tests/unit_tests/chat_models/test_responses_standard.py::TestOpenAIResponses
Skipped
12.1 ms*
test_init_time
libs/partners/openai/tests/unit_tests/chat_models/test_azure_standard.py::TestOpenAIStandard
Skipped
1.7 s*
test_init_time
libs/partners/openai/tests/unit_tests/chat_models/test_base_standard.py::TestOpenAIStandard
Skipped
12.1 ms*
test_init_time
libs/partners/perplexity/tests/unit_tests/test_chat_models_standard.py::TestPerplexityStandard
Skipped
837.4 ms*
test_chroma_init_time
libs/partners/chroma/tests/unit_tests/test_standard.py
Skipped
57.2 ms*
test_init_time
libs/partners/groq/tests/unit_tests/test_standard.py::TestGroqStandard
Skipped
1.6 s*
test_import_time[CallbackManager]
libs/core/tests/benchmarks/test_imports.py
Skipped
447.3 ms*
test_import_time[InMemoryRateLimiter]
libs/core/tests/benchmarks/test_imports.py
Skipped
172.5 ms*
test_import_time[InMemoryVectorStore]
libs/core/tests/benchmarks/test_imports.py
Skipped
599.5 ms*
test_async_callbacks_in_sync
libs/core/tests/benchmarks/test_async_callbacks.py
Skipped
23.8 ms*
test_import_time[LangChainTracer]
libs/core/tests/benchmarks/test_imports.py
Skipped
428 ms*
test_import_time[RunnableLambda]
libs/core/tests/benchmarks/test_imports.py
Skipped
478.1 ms*
test_import_time[tool]
libs/core/tests/benchmarks/test_imports.py
Skipped
504.8 ms*
test_import_time[HumanMessage]
libs/core/tests/benchmarks/test_imports.py
Skipped
261.6 ms*
test_import_time[Document]
libs/core/tests/benchmarks/test_imports.py
Skipped
185.4 ms*
test_import_time[PydanticOutputParser]
libs/core/tests/benchmarks/test_imports.py
Skipped
520.5 ms*
test_import_time[Runnable]
libs/core/tests/benchmarks/test_imports.py
Skipped
480.9 ms*
test_import_time[BaseChatModel]
libs/core/tests/benchmarks/test_imports.py
Skipped
509.6 ms*
test_import_time[ChatPromptTemplate]
libs/core/tests/benchmarks/test_imports.py
Skipped
581.3 ms*

Passed

test_init_time_with_client
libs/partners/anthropic/tests/unit_tests/test_standard.py
CodSpeed Performance Gauge
+1%
2.3 ms*2.3 ms
test_init_time
libs/partners/anthropic/tests/unit_tests/test_standard.py::TestAnthropicStandard
CodSpeed Performance Gauge
0%
764.4 µs*762.5 µs
test_stream_time
libs/partners/anthropic/tests/integration_tests/test_standard.py::TestAnthropicStandard
CodSpeed Performance Gauge
0%
34.8 ms*34.9 ms

Commits

Click on a commit to change the comparison range
Base
master
cc3af82
+0.13%
fix(anthropic): clean up cache_control in middleware to prevent fallback errors Fixes issue where AnthropicPromptCachingMiddleware's cache_control parameter persisted in model_settings when ModelFallbackMiddleware switched to non-Anthropic models (OpenAI, Google), causing TypeError. The fix uses try/finally blocks to ensure cache_control is always removed from model_settings after handler execution, regardless of success or failure. This prevents the Anthropic-specific parameter from being passed to fallback models. Changes: - Added cleanup logic in wrap_model_call() and awrap_model_call() - Updated existing tests to verify cleanup behavior - Added comprehensive tests for both success and error cases Fixes #33709
2cb902d
2 days ago
by yashwantbezawada
© 2025 CodSpeed Technology
Home Terms Privacy Docs