fix(prompt_templates): keep argument content out of the repair warning

parse_tool_call_arguments logged up to 200 characters of the original
arguments when it repaired truncated JSON. That warning is written even
when message logging is turned off, so tool arguments with personal or
confidential data could reach the logs. Log only the tool name, context
and length.
This commit is contained in:
Yuxiang Zhou 2026-11-04 01:57:18 -05:00
parent 6b51246630
commit e776b3d96f
2 changed files with 15 additions and 3 deletions

View file

@ -3261,12 +3261,10 @@ def parse_tool_call_arguments(
repaired: Final = _attempt_json_repair(arguments)
if repaired is not None:
verbose_logger.warning(
"Repaired truncated tool call arguments for tool '%s' (%s). Original (%d chars): %.200s%s",
"Repaired truncated tool call arguments for tool '%s' (%s). Original length: %d chars",
tool_name or "<unknown>",
context or "unknown context",
len(arguments),
arguments,
"..." if len(arguments) > 200 else "",
)
return repaired

View file

@ -297,6 +297,20 @@ def test_parse_tool_call_arguments_rejects_concatenated_json() -> None:
parse_tool_call_arguments('{"a":1}{"b":2}')
def test_parse_tool_call_arguments_repair_warning_omits_argument_content() -> None:
from unittest.mock import patch
secret: Final = "patient-record-4471"
with patch("litellm.litellm_core_utils.prompt_templates.common_utils.verbose_logger") as logger:
result: Final = parse_tool_call_arguments('{"note": "' + secret + '"', tool_name="save_note", context="test")
assert result == {"note": secret}
logger.warning.assert_called_once()
logged: Final = " ".join(str(arg) for arg in logger.warning.call_args.args)
assert "save_note" in logged
assert secret not in logged
def _distinct_json_objects(count: int) -> str:
return "".join(json.dumps({"n": index}, separators=(",", ":")) for index in range(count))