mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-13 08:52:02 +00:00
fix(logging): skip parsing redacted tool arguments
This commit is contained in:
parent
f64479e74d
commit
ef422a26c4
2 changed files with 63 additions and 0 deletions
|
|
@ -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,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue