Skip to content

Commit 14e459b

Browse files
committed
update the protocol + add unit tests
Signed-off-by: Peter Jausovec <peter.jausovec@solo.io>
1 parent 6320394 commit 14e459b

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

src/agentevals/_protocol.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from __future__ import annotations
1616

17+
from enum import Enum
1718
from typing import Any, Optional
1819

1920
from pydantic import BaseModel, Field
@@ -62,13 +63,21 @@ class EvalInput(BaseModel):
6263
expected_invocations: Optional[list[InvocationData]] = None
6364

6465

66+
class EvalStatus(str, Enum):
67+
"""Allowed ``status`` values on the evaluator JSON wire format (matches evaluator-sdk)."""
68+
69+
PASSED = "PASSED"
70+
FAILED = "FAILED"
71+
NOT_EVALUATED = "NOT_EVALUATED"
72+
73+
6574
class EvalResult(BaseModel):
6675
"""Output payload expected from a custom evaluator on stdout."""
6776

6877
score: float = Field(ge=0.0, le=1.0)
69-
status: Optional[str] = Field(
78+
status: Optional[EvalStatus] = Field(
7079
default=None,
71-
description='One of "PASSED", "FAILED", "NOT_EVALUATED". Derived from score vs threshold if omitted.',
80+
description="Derived from score vs threshold if omitted.",
7281
)
7382
per_invocation_scores: list[Optional[float]] = Field(default_factory=list)
7483
details: Optional[dict[str, Any]] = None

tests/test_protocol.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Tests for the custom evaluator JSON protocol models."""
2+
3+
import pytest
4+
from pydantic import ValidationError
5+
6+
from agentevals._protocol import EvalResult, EvalStatus
7+
8+
9+
def test_eval_result_accepts_valid_status_strings() -> None:
10+
raw = '{"score":1.0,"status":"PASSED","per_invocation_scores":[1.0]}'
11+
r = EvalResult.model_validate_json(raw)
12+
assert r.status == EvalStatus.PASSED
13+
assert r.score == 1.0
14+
15+
16+
def test_eval_result_rejects_invalid_status() -> None:
17+
raw = '{"score":1.0,"status":"MAYBE","per_invocation_scores":[]}'
18+
with pytest.raises(ValidationError):
19+
EvalResult.model_validate_json(raw)
20+
21+
22+
def test_eval_result_omitted_status_ok() -> None:
23+
raw = '{"score":0.5,"per_invocation_scores":[]}'
24+
r = EvalResult.model_validate_json(raw)
25+
assert r.status is None

0 commit comments

Comments
 (0)