fix(logging): skip parsing redacted tool arguments

This commit is contained in:
hansu650 2026-08-12 20:13:44 +08:00
parent f64479e74d
commit ef422a26c4
2 changed files with 63 additions and 0 deletions

View file

@ -5371,6 +5371,8 @@ def _parse_tool_call_arguments(raw: Any, tool_name: str | None, context: str) ->
return raw
if not isinstance(raw, str):
return {}
if raw == "redacted-by-litellm":
return {}
from litellm.litellm_core_utils.prompt_templates.common_utils import (
parse_tool_call_arguments,
)

View file

@ -1,5 +1,6 @@
import base64
import json
import logging
import os
from unittest.mock import MagicMock, patch
@ -3200,6 +3201,66 @@ def test_get_tool_calls_from_response_include_all_choices_reads_every_choice():
assert names == ["tool_alpha", "tool_beta"]
def test_get_tool_calls_from_response_silences_redacted_arguments(caplog):
from litellm.litellm_core_utils.prompt_templates.factory import (
get_tool_calls_from_response,
)
response = {
"choices": [
{
"message": {
"tool_calls": [
{
"id": "call_1",
"function": {
"name": "Read",
"arguments": "redacted-by-litellm",
},
}
]
}
}
]
}
with caplog.at_level(logging.WARNING, logger="LiteLLM"):
tool_calls = get_tool_calls_from_response(response)
assert tool_calls == [{"id": "call_1", "name": "Read", "arguments": {}}]
assert "Failed to parse tool call arguments" not in caplog.text
def test_get_tool_calls_from_response_warns_for_malformed_arguments(caplog):
from litellm.litellm_core_utils.prompt_templates.factory import (
get_tool_calls_from_response,
)
response = {
"choices": [
{
"message": {
"tool_calls": [
{
"id": "call_1",
"function": {
"name": "Read",
"arguments": "not-json",
},
}
]
}
}
]
}
with caplog.at_level(logging.WARNING, logger="LiteLLM"):
tool_calls = get_tool_calls_from_response(response)
assert tool_calls == [{"id": "call_1", "name": "Read", "arguments": {}}]
assert "Failed to parse tool call arguments" in caplog.text
def test_group_tool_exchanges_pairs_assistant_with_its_tool_rows():
from litellm.litellm_core_utils.prompt_templates.factory import group_tool_exchanges