mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-08 22:21:35 +00:00
Merge ba097a7b8b into 3e2927de9a
This commit is contained in:
commit
aefbea2f2f
2 changed files with 27 additions and 2 deletions
|
|
@ -1866,7 +1866,7 @@ class CiscoAIDefenseGuardrail(_CiscoAIDefenseMcpMixin, CustomGuardrail):
|
|||
|
||||
tool_text: Final = CiscoAIDefenseGuardrail._extract_tool_definition_text(data)
|
||||
if tool_text:
|
||||
messages.append({"role": "system", "content": tool_text})
|
||||
messages.append({"role": "tool", "content": tool_text})
|
||||
|
||||
return messages
|
||||
|
||||
|
|
|
|||
|
|
@ -1832,6 +1832,31 @@ class TestCiscoAIDefenseToolDefinitionBypass:
|
|||
f"Sent: {sent!r}"
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pre_call_sends_tool_definitions_as_final_tool_message(self):
|
||||
g = _make_guardrail(event_hook="pre_call")
|
||||
data = self._tools_request("Fetch weather data")
|
||||
data["messages"] = [
|
||||
{"role": "system", "content": "Follow the security policy."},
|
||||
{"role": "user", "content": "First question"},
|
||||
{"role": "assistant", "content": "First answer"},
|
||||
{"role": "user", "content": "Current question"},
|
||||
]
|
||||
post_mock = AsyncMock(return_value=_safe_response())
|
||||
|
||||
with _patch_inspection_post(g, post_mock):
|
||||
await g.async_pre_call_hook(
|
||||
user_api_key_dict=UserAPIKeyAuth(),
|
||||
cache=DualCache(),
|
||||
data=data,
|
||||
call_type="completion",
|
||||
)
|
||||
|
||||
sent_messages = post_mock.call_args.kwargs["json"]["messages"]
|
||||
assert sent_messages[:-1] == data["messages"]
|
||||
assert sent_messages[-1]["role"] == "tool"
|
||||
assert "get_weather" in sent_messages[-1]["content"]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pre_call_scans_legacy_functions_definitions(self):
|
||||
g = _make_guardrail(event_hook="pre_call")
|
||||
|
|
@ -1883,7 +1908,7 @@ class TestCiscoAIDefenseToolDefinitionBypass:
|
|||
cisco_resp = _redact_response(
|
||||
sanitized_messages=[
|
||||
{"role": "user", "content": "what's the weather?"},
|
||||
{"role": "system", "content": "[REDACTED] tool description"},
|
||||
{"role": "tool", "content": "[REDACTED] tool description"},
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue