fix(guardrails): label the diff-mode round with the choice it inspected

The ended-stream path labelled every inspection, including a single choice, while a diff-mode round only labelled the per-choice rounds of an n>1 stream. A single-choice round logged no choice at all. Label it with the choice its texts came from.
This commit is contained in:
Alessandro Pignati 2026-11-01 22:24:57 +01:00
parent e53c6fc8bf
commit e54d4b8d12
2 changed files with 3 additions and 1 deletions

View file

@ -951,6 +951,8 @@ class OpenAIChatCompletionsHandler(BaseTranslation):
prior_responses: Final = resolved_request_data.get("responses", missing)
prior_choice_index: Final = resolved_request_data.get("guardrail_choice_index", missing)
resolved_request_data.pop("guardrail_choice_index", None)
if len(indices) == 1:
resolved_request_data["guardrail_choice_index"] = indices[0]
if "responses" not in resolved_request_data:
resolved_request_data["responses"] = responses_so_far
self.merge_user_api_key_metadata_into_request(resolved_request_data, user_api_key_dict)

View file

@ -1702,7 +1702,7 @@ class TestOpenAIChatCompletionsHandlerStreamingOutput:
request_data=request_data,
stream_transform_sink=StreamTransformSink(),
)
assert LabelReadingGuardrail.seen == [None]
assert LabelReadingGuardrail.seen == [0]
assert request_data["guardrail_choice_index"] == 7
@pytest.mark.asyncio