fix: normalize Anthropic server tool usage#26904
Conversation
|
|
Greptile SummaryThis PR fixes a bug where Anthropic passthrough responses that construct Confidence Score: 5/5Safe to merge — targeted, well-tested fix with no backwards-incompatible changes. The change is minimal and follows an established pattern already used for other nested usage fields. Both the conversion logic and the round-trip are directly tested. Unused imports (including a rule-violating fastapi.testclient import) are cleaned up as a side effect. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/types/utils.py | Adds dict-to-ServerToolUse normalization in Usage.init; field annotation stays typed as Optional[ServerToolUse] and conversion happens correctly after super().init(). |
| tests/test_litellm/litellm_core_utils/llm_cost_calc/test_tool_call_cost_tracking.py | Adds test covering the dict server_tool_use path through StandardBuiltInToolCostTracking; removes unused imports including the fastapi TestClient import that violated the no-FastAPI-outside-proxy rule. |
| tests/test_litellm/types/test_types_utils.py | Adds test for dict-to-ServerToolUse conversion and model_dump round-trip; cleans up unused imports. |
Reviews (1): Last reviewed commit: "fix: normalize Anthropic server tool usa..." | Re-trigger Greptile
Merging this PR will not alter performance
Comparing |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Summary
server_tool_usevalues intoServerToolUseinsideUsageusage.server_tool_use.web_search_requestsFixes #26749.
Tests
/tmp/uv-0.10.9-env/bin/uv run --extra proxy pytest tests/test_litellm/types/test_types_utils.py tests/test_litellm/litellm_core_utils/llm_cost_calc/test_tool_call_cost_tracking.py -q/tmp/uv-0.10.9-env/bin/uv run --extra proxy ruff check --ignore PLR0915 litellm/types/utils.py tests/test_litellm/types/test_types_utils.py tests/test_litellm/litellm_core_utils/llm_cost_calc/test_tool_call_cost_tracking.pygit diff --checkNote: full touched-file ruff still reports the existing
PLR0915limit onDelta.__init__; the targeted lint command above keeps the check focused on actionable findings for this patch.