Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libs/giskard-llm/src/giskard/llm/translators/google_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ def _coerce_dict(cls, v: Any) -> Any:
"PROHIBITED_CONTENT",
"SPII",
"IMAGE_PROHIBITED_CONTENT",
"IMAGE_SAFETY",
"RECITATION",
"IMAGE_RECITATION",
}
)

Expand Down
24 changes: 24 additions & 0 deletions libs/giskard-llm/tests/translators/test_google_chat_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,30 @@ def test_from_google_safety_maps_to_refusal():
assert out.choices[0].message.refusal == "SAFETY"


@pytest.mark.parametrize("reason", ["IMAGE_SAFETY", "RECITATION", "IMAGE_RECITATION"])
def test_from_google_content_blocks_map_to_refusal(reason: str):
"""Every reason Gemini uses to block content maps to ``refusal``.

``IMAGE_SAFETY`` is the image-modality counterpart of ``SAFETY``, and the
two ``RECITATION`` reasons block output that reproduces protected content.
All three were absent from ``REFUSAL_REASONS``, so they fell through to the
default ``stop`` and a blocked generation was reported as a normal one.
"""
raw = _raw(
{
"candidates": [
{
"content": {"parts": [{"text": "blocked"}]},
"finish_reason": reason,
}
],
}
)
out = GoogleChatTranslator.from_google(raw, _MODEL, 1)
assert out.choices[0].finish_reason == "refusal"
assert out.choices[0].message.refusal == reason


def test_from_google_refusal_uses_finish_message_when_present():
"""When Gemini supplies a ``finish_message``, it becomes the refusal text.

Expand Down
Loading