fix(guardrails): label llm_as_a_judge logging_only verdicts with their mode

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
yucheng 2026-09-14 21:53:20 +00:00
parent b93f22265c
commit 28bd00a004
2 changed files with 20 additions and 0 deletions

View file

@ -277,6 +277,8 @@ class LLMAsAJudgeGuardrail(CustomGuardrail):
)
def _event_type_for(self, input_type: JudgeInputType) -> GuardrailEventHooks:
if self._event_hook_is_event_type(GuardrailEventHooks.logging_only):
return GuardrailEventHooks.logging_only
if input_type == "response":
return GuardrailEventHooks.post_call
if self._event_hook_is_event_type(GuardrailEventHooks.pre_call):

View file

@ -285,6 +285,24 @@ async def test_apply_guardrail_request_multi_turn_keeps_roles_and_focuses_latest
) in judge_messages[1]["content"]
@pytest.mark.asyncio
@pytest.mark.parametrize("input_type", ["request", "response"])
async def test_apply_guardrail_logging_only_labels_both_sides_logging_only(input_type: str):
router: Final = _judge_router(50.0)
guardrail: Final = _make_guardrail(
on_failure="log",
event_hook=GuardrailEventHooks.logging_only,
router_provider=lambda: router,
)
request_data: Final[dict[str, object]] = {"messages": [{"role": "user", "content": "hi"}], "metadata": {}}
assert guardrail.should_run_guardrail(request_data, GuardrailEventHooks.pre_call) is False
assert guardrail.should_run_guardrail(request_data, GuardrailEventHooks.post_call) is False
await guardrail.apply_guardrail({"texts": ["hi"]}, request_data, input_type)
assert request_data["metadata"]["standard_logging_guardrail_information"][0]["guardrail_mode"] == "logging_only"
@pytest.mark.asyncio
async def test_apply_guardrail_response_prompt_unchanged():
router: Final = _judge_router(90.0)