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)

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
22 hours ago
by yashwantbezawada
© 2025 CodSpeed Technology
Home Terms Privacy Docs