fix(evaluator): reject non-boolean notification decisions
This commit is contained in:
1 parent
03b880f256
commit
e2cd6908c7
2 files changed
+26
-1
No files matched your search
@@ -129,9 +129,15 @@ async def evaluate_response(
|
|||||||
|
|
||||||
args = llm_response.tool_calls[0].arguments
|
args = llm_response.tool_calls[0].arguments
|
||||||
should_notify = args.get("should_notify", default_notify)
|
should_notify = args.get("should_notify", default_notify)
|
||||||
|
if not isinstance(should_notify, bool):
|
||||||
|
logger.warning(
|
||||||
|
"evaluate_response: non-boolean should_notify, defaulting to notify={}",
|
||||||
|
default_notify,
|
||||||
|
)
|
||||||
|
return default_notify
|
||||||
reason = args.get("reason", "")
|
reason = args.get("reason", "")
|
||||||
logger.info("evaluate_response: should_notify={}, reason={}", should_notify, reason)
|
logger.info("evaluate_response: should_notify={}, reason={}", should_notify, reason)
|
||||||
return bool(should_notify)
|
return should_notify
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("evaluate_response failed, defaulting to notify={}", default_notify)
|
logger.exception("evaluate_response failed, defaulting to notify={}", default_notify)
|
||||||
|
|||||||
@@ -95,6 +95,25 @@ async def test_should_notify_false() -> None:
|
|||||||
assert result is False
|
assert result is False
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@pytest.mark.parametrize("decision", ["false", "true", 0, 1, None, [], {"notify": True}])
|
||||||
|
@pytest.mark.parametrize("default_notify", [False, True])
|
||||||
|
async def test_invalid_notification_decision_uses_default(decision, default_notify) -> None:
|
||||||
|
response = LLMResponse(
|
||||||
|
content="",
|
||||||
|
tool_calls=[ToolCallRequest(
|
||||||
|
id="eval_1", name="evaluate_notification",
|
||||||
|
arguments={"should_notify": decision},
|
||||||
|
)],
|
||||||
|
)
|
||||||
|
result = await evaluate_response(
|
||||||
|
"All clear", "check status", DummyProvider([response]), "m",
|
||||||
|
evaluator_prompt=_EVAL_PROMPT, default_notify=default_notify,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result is default_notify
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_fallback_on_error() -> None:
|
async def test_fallback_on_error() -> None:
|
||||||
class FailingProvider(DummyProvider):
|
class FailingProvider(DummyProvider):
|
||||||
|
|||||||
Reference in new issue
Block a user