mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-17 23:51:30 +00:00
fix(guardrails): only cite message scoping in the not_run reason when scoping is on
A request whose messages carry no scannable content at all, with no skip flag set, now records the neutral reason no scannable content instead of blaming configuration Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
0519d86346
commit
52da64a45b
2 changed files with 20 additions and 1 deletions
|
|
@ -212,7 +212,11 @@ class OpenAIChatCompletionsHandler(BaseTranslation):
|
|||
|
||||
elif not images_to_check and not guardrail_to_apply.records_own_guardrail_information:
|
||||
guardrail_to_apply.add_standard_logging_guardrail_information_to_request_data(
|
||||
guardrail_json_response="no scannable content after message scoping",
|
||||
guardrail_json_response=(
|
||||
"no scannable content after message scoping"
|
||||
if skip_system or skip_tool or scan_only_tool_results
|
||||
else "no scannable content"
|
||||
),
|
||||
request_data=data,
|
||||
guardrail_status="not_run",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1917,6 +1917,21 @@ class TestNoScannableContentRecordsNotRun:
|
|||
assert len(entries) == 1
|
||||
assert entries[0]["guardrail_name"] == "skip-system-guardrail"
|
||||
assert entries[0]["guardrail_status"] == "not_run"
|
||||
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):
|
||||
handler = OpenAIChatCompletionsHandler()
|
||||
guardrail = MockGuardrail(guardrail_name="unscoped-guardrail")
|
||||
data = {"messages": [{"role": "user", "content": None}]}
|
||||
|
||||
await handler.process_input_messages(data=data, guardrail_to_apply=guardrail)
|
||||
|
||||
assert guardrail.last_inputs is None
|
||||
entries = self._recorded_entries(data)
|
||||
assert len(entries) == 1
|
||||
assert entries[0]["guardrail_status"] == "not_run"
|
||||
assert entries[0]["guardrail_response"] == "no scannable content"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_self_recording_guardrail_is_left_alone(self):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue