From 6181ba3d144ad93150bf9ec4329624166398e14e Mon Sep 17 00:00:00 2001 From: Richard Lundeen Date: Thu, 16 Jul 2026 09:06:07 -0700 Subject: [PATCH] FIX: CLI display underlying model Scenario pretty-printer showed the Azure deployment name (model_name) instead of the underlying model. Prefer underlying_model_name with fallback to model_name, matching the CLI target-list behavior in _output.py. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0647a5d9-1395-4980-8eac-2aa176160ed1 --- pyrit/output/scenario_result/pretty.py | 6 +++++- .../output/scenario_result/test_pretty.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pyrit/output/scenario_result/pretty.py b/pyrit/output/scenario_result/pretty.py index de38ed26fe..0584643ea5 100644 --- a/pyrit/output/scenario_result/pretty.py +++ b/pyrit/output/scenario_result/pretty.py @@ -170,7 +170,11 @@ async def render_async(self, result: ScenarioResult) -> str: lines.append(self._format_colored(f"{self._indent}🎯 Target Information", Style.BRIGHT)) target_id = result.objective_target_identifier target_type = target_id.class_name if target_id else "Unknown" - target_model = target_id.params.get("model_name", "Unknown") if target_id else "Unknown" + target_model = ( + (target_id.params.get("underlying_model_name") or target_id.params.get("model_name") or "Unknown") + if target_id + else "Unknown" + ) target_endpoint = target_id.params.get("endpoint", "Unknown") if target_id else "Unknown" lines.append(self._format_colored(f"{self._indent * 2}• Target Type: {target_type}", Fore.CYAN)) diff --git a/tests/unit/output/scenario_result/test_pretty.py b/tests/unit/output/scenario_result/test_pretty.py index dfcaefa9a5..ff870322de 100644 --- a/tests/unit/output/scenario_result/test_pretty.py +++ b/tests/unit/output/scenario_result/test_pretty.py @@ -96,6 +96,25 @@ async def test_write_async_with_unknown_target_when_no_params(printer, capsys): assert "Target Endpoint: Unknown" in out +async def test_write_async_prefers_underlying_model_over_deployment_name(printer, capsys): + result = _scenario_result( + target_params={"model_name": "pyrit-github-gpt4", "underlying_model_name": "gpt-4o"}, + ) + await printer.write_async(result) + out = capsys.readouterr().out + assert "Target Model: gpt-4o" in out + assert "pyrit-github-gpt4" not in out + + +async def test_write_async_falls_back_to_model_name_without_underlying_model(printer, capsys): + result = _scenario_result( + target_params={"model_name": "pyrit-github-gpt4"}, + ) + await printer.write_async(result) + out = capsys.readouterr().out + assert "Target Model: pyrit-github-gpt4" in out + + async def test_write_async_renders_scorer_section_when_scorer_identifier_present(printer, monkeypatch, capsys): # Stub the scorer printer's render_async so we don't depend on real evaluation data. async def fake_render_async(*, scorer_identifier, harm_category=None):