litellm/litellm
netbrah 5d1106f018 fix(anthropic): deduplicate tool_result messages by tool_call_id
Anthropic requires exactly one tool_result per tool_use. When
conversation history (e.g. from session resume/checkpoint restore)
contains duplicate tool result messages with the same tool_call_id,
the API rejects with: 'each tool_use must have a single result.
Found multiple tool_result blocks with id: <id>'.

This is already handled for Bedrock via _deduplicate_bedrock_tool_content()
but was missing from the Anthropic direct and Vertex AI partner paths,
which share sanitize_messages_for_tool_calling().

Fix: Add Case D to sanitize_messages_for_tool_calling() — after the
existing orphan detection passes, scan for duplicate tool_call_ids
and keep only the last occurrence (most complete result).

Added 3 unit tests: dedup with duplicates, no-op with unique IDs,
and behavior when modify_params=False.

Related issues: #11804, #11029, #6836, #1782, #151
2026-03-08 10:02:45 -04:00
..
a2a_protocol CircleCI test stability (#23055) 2026-03-07 15:19:39 -08:00
anthropic_interface fix: prompt registry 2026-02-18 00:34:54 +05:30
assistants
batch_completion fix: prompt registry 2026-02-18 00:34:54 +05:30
batches Agents - add max budget + tpm/rpm limiting per agent AND per agent session (#22849) 2026-03-07 19:12:42 -08:00
caching fix(caching): check REDIS_CLUSTER_NODES env var in Cache and Router class selection (#22790) 2026-03-06 17:31:30 -08:00
completion_extras Merge remote-tracking branch 'upstream/main' into pr-22553 2026-03-03 09:48:39 +00:00
containers fix: prompt registry 2026-02-18 00:34:54 +05:30
endpoints/speech/speech_to_completion_bridge
evals fix: prompt registry 2026-02-18 00:34:54 +05:30
experimental_mcp_client added configurable env for mcp timeouts (#22287) 2026-03-02 13:13:41 -08:00
files Merge pull request #22765 from BerriAI/main 2026-03-04 17:40:42 +05:30
fine_tuning Agents - add max budget + tpm/rpm limiting per agent AND per agent session (#22849) 2026-03-07 19:12:42 -08:00
google_genai fix: prompt registry 2026-02-18 00:34:54 +05:30
images Merge branch 'litellm_oss_staging_02_27_2026' of https://github.com/BerriAI/litellm into litellm_oss_staging_02_27_2026 2026-02-28 09:54:56 -03:00
integrations feat: allow multiple calls from tags 2026-03-07 11:24:18 +05:30
interactions fix: prompt registry 2026-02-18 00:34:54 +05:30
litellm_core_utils fix(anthropic): deduplicate tool_result messages by tool_call_id 2026-03-08 10:02:45 -04:00
llms fix(bedrock): strip output_config from Bedrock Invoke requests (#23042) 2026-03-07 19:33:53 -08:00
ocr Enable local file support for OCR (#22133) 2026-02-27 10:50:02 -08:00
passthrough fix(passthrough): propagate Azure 429/5xx errors in async streaming instead of silent HTTP 200 (#22913) 2026-03-05 10:12:43 -08:00
proxy fix: missing closing paren in agent_endpoints get_agents Query() 2026-03-07 23:13:42 -08:00
proxy_auth fix: prompt registry 2026-02-18 00:34:54 +05:30
rag fix: prompt registry 2026-02-18 00:34:54 +05:30
realtime_api fix(azure): forward realtime_protocol from config and relax api_version check for GA path (#22369) 2026-03-02 19:21:27 +05:30
rerank_api fix(bedrock): pass timeout param to bedrock rerank http client (#22021) 2026-02-24 09:32:11 -08:00
responses fix(lint): resolve PLR0915 too-many-statements in 4 files 2026-03-04 20:34:15 -03:00
router_strategy fix: complexity_router crashes on list-format message content (OpenAI multi-part messages) (#22761) 2026-03-04 16:18:49 -08:00
router_utils Fix encrypted content streaming affinity issue 2026-03-03 18:37:22 +05:30
search
secret_managers feat: Hashicorp Vault config override backend endpoints 2026-03-05 16:57:08 -08:00
skills fix: prompt registry 2026-02-18 00:34:54 +05:30
types Agents - add max budget + tpm/rpm limiting per agent AND per agent session (#22849) 2026-03-07 19:12:42 -08:00
vector_store_files
vector_stores
videos fix(ollama): thread api_base to get_model_info + graceful fallback (#21970) 2026-02-23 21:00:37 -08:00
__init__.py feat: feature flag on validate key alias 2026-03-07 12:32:21 +05:30
_lazy_imports.py fix: prompt registry 2026-02-18 00:34:54 +05:30
_lazy_imports_registry.py Merge pull request #22866 from mubashir1osmani/feat/bedrock-mantle-provider-clean 2026-03-05 18:24:00 +05:30
_logging.py fix: prompt registry 2026-02-18 00:34:54 +05:30
_redis.py fix: close leaked Redis connection pools on cache eviction and disconnect 2026-02-20 17:09:32 -08:00
_service_logger.py fix: prompt registry 2026-02-18 00:34:54 +05:30
_uuid.py
_version.py
anthropic_beta_headers_config.json fix: enable context-1m-2025-08-07 beta header for vertex_ai provider (#21867) 2026-02-21 20:12:23 -08:00
anthropic_beta_headers_manager.py fix: prompt registry 2026-02-18 00:34:54 +05:30
blog_posts.json fix(ollama): thread api_base to get_model_info + graceful fallback (#21970) 2026-02-23 21:00:37 -08:00
budget_manager.py
constants.py feat(spend-logs): add truncation note when error logs are truncated for DB storage (#22936) 2026-03-05 16:58:46 -08:00
cost.json
cost_calculator.py feat(azure_ai): add router flat cost when response contains actual model 2026-03-06 18:18:06 +05:30
exceptions.py Remove nit 2026-02-26 13:44:06 -08:00
main.py Merge pull request #22866 from mubashir1osmani/feat/bedrock-mantle-provider-clean 2026-03-05 18:24:00 +05:30
model_prices_and_context_window_backup.json fix: guard prisma import in config_override_endpoints (#23058) 2026-03-07 15:57:57 -08:00
mypy.ini
policy_templates_backup.json feat(add-new-block_code_execution-guardrail): prevent agent from executing code (#22154) 2026-02-25 22:02:14 -08:00
provider_endpoints_support_backup.json fix: add 12 missing endpoint keys to _ENDPOINT_METADATA, fix stale _schema keys in backup JSON 2026-02-26 19:18:17 -08:00
py.typed
router.py Agents - add max budget + tpm/rpm limiting per agent AND per agent session (#22849) 2026-03-07 19:12:42 -08:00
scheduler.py fix: prompt registry 2026-02-18 00:34:54 +05:30
timeout.py
utils.py fix: use DeepSeekChatConfig instead of OpenAIConfig for deepseek provider (#22971) 2026-03-06 18:16:27 -08:00