mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-16 23:41:43 +00:00
fix(guardrails): cite message scoping only when an unscoped pass finds content
The not_run reason now says after message scoping only when the same messages carry text or tool calls without the skip flags applied. A request that is empty to begin with, whatever the flags, records no scannable content Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
52da64a45b
commit
5ceec4c21e
2 changed files with 16 additions and 2 deletions
|
|
@ -211,10 +211,22 @@ class OpenAIChatCompletionsHandler(BaseTranslation):
|
|||
)
|
||||
|
||||
elif not images_to_check and not guardrail_to_apply.records_own_guardrail_information:
|
||||
unscoped_texts: Final[list[str]] = []
|
||||
unscoped_tool_calls: Final[list[ChatCompletionToolParam]] = []
|
||||
for unscoped_idx, unscoped_message in enumerate(messages):
|
||||
self._extract_inputs(
|
||||
message=unscoped_message,
|
||||
msg_idx=unscoped_idx,
|
||||
texts_to_check=unscoped_texts,
|
||||
images_to_check=[],
|
||||
tool_calls_to_check=unscoped_tool_calls,
|
||||
text_task_mappings=[],
|
||||
tool_call_task_mappings=[],
|
||||
)
|
||||
guardrail_to_apply.add_standard_logging_guardrail_information_to_request_data(
|
||||
guardrail_json_response=(
|
||||
"no scannable content after message scoping"
|
||||
if skip_system or skip_tool or scan_only_tool_results
|
||||
if unscoped_texts or unscoped_tool_calls
|
||||
else "no scannable content"
|
||||
),
|
||||
request_data=data,
|
||||
|
|
|
|||
|
|
@ -1920,9 +1920,11 @@ class TestNoScannableContentRecordsNotRun:
|
|||
assert entries[0]["guardrail_response"] == "no scannable content after message scoping"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_empty_content_without_scoping_does_not_blame_scoping(self):
|
||||
@pytest.mark.parametrize("skip_system", [False, True])
|
||||
async def test_empty_content_does_not_blame_scoping(self, skip_system: bool):
|
||||
handler = OpenAIChatCompletionsHandler()
|
||||
guardrail = MockGuardrail(guardrail_name="unscoped-guardrail")
|
||||
guardrail.skip_system_message_in_guardrail = skip_system
|
||||
data = {"messages": [{"role": "user", "content": None}]}
|
||||
|
||||
await handler.process_input_messages(data=data, guardrail_to_apply=guardrail)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue