Skip to content

Commit efaa5b7

Browse files
jsonbaileyclaude
andcommitted
refactor: move legacy judge message stripping to client._judge_config()
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 775aaca commit efaa5b7

3 files changed

Lines changed: 11 additions & 16 deletions

File tree

packages/sdk/server-ai/src/ldai/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ldai import log
1010
from ldai.agent_graph import AgentGraphDefinition
1111
from ldai.evaluator import Evaluator
12-
from ldai.judge import Judge
12+
from ldai.judge import Judge, _strip_legacy_judge_messages
1313
from ldai.managed_agent import ManagedAgent
1414
from ldai.managed_agent_graph import ManagedAgentGraph
1515
from ldai.managed_model import ManagedModel
@@ -237,6 +237,10 @@ def _extract_evaluation_metric_key(variation: Dict[str, Any]) -> Optional[str]:
237237

238238
evaluation_metric_key = _extract_evaluation_metric_key(variation)
239239

240+
# strip legacy judge template messages before creating config
241+
if messages:
242+
messages = _strip_legacy_judge_messages(messages)
243+
240244
config = AIJudgeConfig(
241245
key=key,
242246
enabled=bool(enabled),

packages/sdk/server-ai/src/ldai/judge/__init__.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,6 @@ def get_model_runner(self) -> Runner:
160160
return self._model_runner
161161

162162
def _build_evaluation_input(self, input_text: str, output_text: str) -> str:
163-
"""
164-
Build the string input for the judge runner.
165-
166-
Legacy messages (assistant/user messages containing ``{{message_history}}``
167-
or ``{{response_to_evaluate}}``) are stripped from the config; the runner
168-
was already created from the judge AI config (which carries the system
169-
message), so only the plain-text evaluation payload is needed here.
170-
171-
:param input_text: The input text (message history)
172-
:param output_text: The output text to evaluate
173-
:return: Formatted evaluation input string
174-
"""
175-
_strip_legacy_judge_messages(self._ai_config.messages or [])
176163
return f"MESSAGE HISTORY:\n{input_text}\n\nRESPONSE TO EVALUATE:\n{output_text}"
177164

178165
def _parse_evaluation_response(self, data: Dict[str, Any]) -> Optional[Tuple[float, str]]:

packages/sdk/server-ai/tests/test_judge.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,14 @@ async def test_evaluate_string_input_format(
292292
assert input_arg == expected
293293

294294
@pytest.mark.asyncio
295-
async def test_evaluate_legacy_config_strips_template_messages(
295+
async def test_evaluate_legacy_config_passes_string_input_to_runner(
296296
self, tracker: LDAIConfigTracker, mock_runner
297297
):
298-
"""Legacy config with assistant/user template messages: runner still gets string input."""
298+
"""
299+
Judge built directly with legacy messages (bypassing the client) still passes
300+
a formatted string to the runner. Legacy message stripping is the client's
301+
responsibility; the Judge itself does not strip.
302+
"""
299303
legacy_messages = [
300304
LDMessage(role='system', content='You are a strict judge.'),
301305
LDMessage(role='assistant', content='{{message_history}}'),

0 commit comments

Comments
 (0)