Avatar for the langchain-ai user
langchain-ai
langchain
BlogDocsChangelog

Performance History

Latest Results

fix(langchain): sanitize anthropic cache markers on fallback retries (#37867) ## Summary Fixes #33709. When `AnthropicPromptCachingMiddleware` runs before `ModelFallbackMiddleware`, Anthropic-specific `cache_control` markers can leak into fallback attempts targeting non-Anthropic models. This change makes fallback retries sanitize those markers only on non-primary attempts, preserving primary-call behavior and avoiding API changes. Related: langchain-ai/deepagentsjs#551. ## Changes ### libs/langchain_v1 - Added a private fallback sanitizer in `model_fallback.py` to remove Anthropic `cache_control` markers from fallback requests. - Sanitization covers `model_settings`, system/content message blocks, and tool payloads (`BaseTool.extras` plus dict-style tools/extras). - Applied sanitization in both sync and async fallback retry paths (`wrap_model_call` and `awrap_model_call`) while leaving the primary attempt unchanged. ### libs/langchain_v1 tests - Added sync and async regression tests in `test_model_fallback.py` that simulate primary failure and assert fallback calls only succeed when cache markers are stripped. - Verified non-cache settings (for example `temperature` and `top_p`) are preserved on fallback. - Preserved existing fallback behavior coverage (ordering, exhaustion, and error propagation). ## Compatibility with `BedrockPromptCachingMiddleware` The sanitizer also covers `BedrockPromptCachingMiddleware`, which injects `cache_control` into `model_settings` only. Bedrock-specific markers (`cachePoint` blocks, content-block `cache_control`) are applied by the chat model classes at API-call time and never appear in the `ModelRequest`, so no additional handling is needed. --------- Co-authored-by: Mason Daugherty <mason@langchain.dev> Co-authored-by: Mason Daugherty <github@mdrxy.com>
master
9 hours ago
cr
hunter/fix-model-fallback-cache-control-leak
9 hours ago
cr
hunter/fix-model-fallback-cache-control-leak
10 hours ago
fix for content blocks and block extras/meta
hunter/fix-model-fallback-cache-control-leak
10 hours ago
Merge branch 'master' into hunter/fix-model-fallback-cache-control-leak
hunter/fix-model-fallback-cache-control-leak
11 hours ago
Merge branch 'master' into fix/openai-file-block-mime-type
anmolg1997:fix/openai-file-block-mime-type
23 hours ago

Latest Branches

CodSpeed Performance Gauge
0%
fix(langchain): sanitize anthropic cache markers on fallback retries#37867
9 hours ago
6253c68
hunter/fix-model-fallback-cache-control-leak
CodSpeed Performance Gauge
0%
fix(core): use parsed mime_type for base64 file blocks in openai translator#36940
23 hours ago
c123363
anmolg1997:fix/openai-file-block-mime-type
CodSpeed Performance Gauge
0%
1 day ago
a435d9f
cbornet:ruff-core-preview-4
© 2026 CodSpeed Technology
Home Terms Privacy Docs