From 83e2027e2a6730e6cb749bad5776c31fa98e642f Mon Sep 17 00:00:00 2001 From: mottopanikeiku <176798723+mottopanikeiku@users.noreply.github.com> Date: Thu, 22 Oct 2026 04:52:21 -0700 Subject: [PATCH] fix(nemotron3): render later system messages instead of raising The Nemotron 3 chat templates render a system message that is not first as its own system turn, and bridge_to_next_turn already does the same, but render() raised ValueError. I render it through the user branch like the template does and run the later-system parity scenario for the Nemotron renderers. Assisted-by: Claude Assisted-by: GPT-6 Astra Signed-off-by: mottopanikeiku <176798723+mottopanikeiku@users.noreply.github.com> --- renderers/nemotron3.py | 10 +++++----- tests/parity.py | 8 +++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/renderers/nemotron3.py b/renderers/nemotron3.py index 53276ed25..e3b372862 100644 --- a/renderers/nemotron3.py +++ b/renderers/nemotron3.py @@ -428,16 +428,16 @@ def emit_text_segments( content = self._render_content(msg.get("content")) msg_orig_idx = orig_idx(i) - if role == "system": - if i != 0: - raise ValueError("System message must be at the beginning.") + if role == "system" and i == 0: continue # Already handled above - elif role == "user": + elif role in ("user", "system"): + # The template renders a later system message through the + # user branch, under its own role header. emit_special( self._im_start, msg_orig_idx, is_sampled=False, is_content=False ) - user_segments: list[tuple[str, bool]] = [("user\n", False)] + user_segments: list[tuple[str, bool]] = [(f"{role}\n", False)] if content: user_segments.append((content, True)) # Reasoning-effort hint rides on the LAST user message only, diff --git a/tests/parity.py b/tests/parity.py index ac34e11cc..2b75fb493 100644 --- a/tests/parity.py +++ b/tests/parity.py @@ -660,7 +660,13 @@ def _call(city: str, *, id: str | None = None) -> dict: {"role": "system", "content": "Late instruction"}, {"role": "user", "content": "B"}, ], - only_renderers={"laguna-xs-2.1", "laguna-s-2.1"}, + only_renderers={ + "laguna-xs-2.1", + "laguna-s-2.1", + "nemotron-3", + "nemotron-3-ultra", + "nemotron-3.5", + }, ), _scenario( "tool-declare-message",