#5374·PraisonAI

[BUG] EvalPort adapter output fails the EvalPort validators (to_evalport / report_to_evalport)

Author: adhabnr-uxCreated Sep 30, 2026Updated Sep 30, 2026
Labelsbugdocumentationclaude

Thanks for shipping the EvalPort adapter in #4667 (requested in #4275). It's great to see it land in praisonaiagents.eval.

When I ran the output through the reference validator, neither document validated. The Suite and ResultSet:

  • use key names that aren't in the spec (cases, evalport_version, kind, case_id, score, latency_ms, ...)
  • leave out required keys (id, test_cases, suite_id, run_id, started_at, grader_results, ...)

That's partly on me: the sketch in #4275 described the mapping loosely instead of spelling out the exact spec fields.

SDK / package

  • Python (praisonaiagents)

Environment

  • praisonaiagents 1.7.9 (main @ d9453cb)
  • evalport-sdk 1.3.1
  • Python 3.11, Linux

Reproduction

python
# pip install praisonaiagents evalport-sdk
from praisonaiagents.eval import (
    EvalCase, EvalPackage, EvalReport, EvalResult, to_evalport, report_to_evalport,
)
from openeval.validate import validate_suite, validate_result_set

pkg = EvalPackage(name="support", cases=[
    EvalCase(name="refund", input="refund policy?", expected="30 days", criteria=["answer_correct"]),
])
report = EvalReport(package_name="support", total_cases=1, passed_cases=1, failed_cases=0,
                    average_score=0.9, results=[EvalResult(case_name="refund", passed=True, score=0.9)])

for label, res in (("suite", validate_suite(to_evalport(pkg))),
                   ("result_set", validate_result_set(report_to_evalport(report)))):
    print(label, res.valid, [f"{e['path']}:{e['code']}" for e in res.errors])

Actual behavior

suite False ['$.id:REQUIRED', '$.test_cases:REQUIRED']
result_set False ['$.version:INVALID_VERSION', '$.suite_id:REQUIRED', '$.run_id:REQUIRED', '$.started_at:REQUIRED', '$.results[0].test_case_id:REQUIRED', '$.results[0].grader_results:REQUIRED']

The JSON Schemas (spec/schemas/*.json, which set additionalProperties: false) also reject these extra keys:

Object Rejected keys
Suite (top level) cases, evalport_version, kind, seed, thresholds
ResultSet (top level) evalport_version, kind, suite_name
Each result case_id, score, latency_ms
summary average_score, thresholds_met

Expected behavior

Both functions emit documents that pass validate_suite() / validate_result_set() and the JSON Schemas, as the module docstring says.

Proposed fix

The patch below changes only eval/evalport.py and its test file. It stays dependency-free and keeps the public API: to_evalport, from_evalport and report_to_evalport are unchanged, and report_to_evalport gains two optional keyword-only args, run_id and started_at.

  • Suite
    • version is the spec version (1.0.0-rc.5, same as openeval.types.OPENEVAL_VERSION).
    • The package name becomes id (and name), and cases becomes test_cases.
    • timeout_seconds becomes the spec's timeout_ms.
    • Each criterion becomes a suite-level grader (type: "custom", params.handler: "praisonaiagents.eval").
    • Cases with no criteria reference a praisonai_verdict grader, because the spec requires at least one grader per case.
  • ResultSet
    • Adds suite_id, run_id (defaults to a UUID), started_at (defaults to now in UTC, RFC 3339) and runner.
    • Each result gets test_case_id, duration_ms (int), and one grader_results entry carrying EvalResult.passed/score.
    • A score outside [0,1] is clamped, and the original is kept in metadata["openeval.raw_score"] as the spec asks. A NaN score becomes null + passed: false.
    • error becomes {"type": "runner_error", "message": ...}, and summary.average_score becomes avg_score.
  • Nothing dropped. PraisonAI-only data with no spec field is kept under metadata.praisonai: package version, thresholds, seed, criteria_scores, record, thresholds_met.
  • Old suites still import. from_evalport() still accepts suites emitted by the current version (cases, evalport_version, top-level thresholds/seed, timeout_seconds).

Two judgement calls you may want to change:

  • criteria_scores go into metadata rather than becoming per-criterion grader_results, because EvalResult has no per-criterion pass/fail.
  • A criterion literally named praisonai_verdict would be dropped on re-import.

The spec also requires at least one test case and one result, so an empty package or report still won't validate.

Patch (git diff against main @ d9453cb)
diff
diff --git a/src/praisonai-agents/praisonaiagents/eval/evalport.py b/src/praisonai-agents/praisonaiagents/eval/evalport.py
index b9b23f2..1e4e428 100644
--- a/src/praisonai-agents/praisonaiagents/eval/evalport.py
+++ b/src/praisonai-agents/praisonaiagents/eval/evalport.py
@@ -7,9 +7,13 @@ another tool's harness, and results can be diffed/aggregated across tools.
 
 Mapping (1:1 with EvalPort's ``Suite`` / ``ResultSet`` concepts):
 
-    EvalPackage <-> EvalPort Suite      (name/description/version + cases + thresholds)
-    EvalCase    <-> EvalPort test case  (input / expected_output / grader refs)
-    EvalReport   -> EvalPort ResultSet  (aggregate + per-case pass/score/latency)
+    EvalPackage <-> EvalPort Suite      (id/name/description + test_cases + graders)
+    EvalCase    <-> EvalPort TestCase   (id / input / expected_output / grader refs)
+    EvalReport   -> EvalPort ResultSet  (summary + per-case grader_results)
+
+PraisonAI-only fields with no EvalPort slot (package version, thresholds, seed,
+per-criterion scores, trajectory records, ...) are kept under the ``praisonai``
+key of the relevant ``metadata`` object so round trips stay lossless.
 
 Design: this module is intentionally **dependency-free**. It emits and consumes
 plain spec-shaped dicts (JSON), so the core SDK does not take on ``evalport-sdk``
@@ -27,53 +31,75 @@ Example:
     >>> pkg2.name == pkg.name
     True
 """
-from typing import Any, Dict, List
+import uuid
+from datetime import datetime, timezone
+from typing import Any, Dict, List, Optional
 
 from .package import EvalCase, EvalPackage, EvalReport
 
-EVALPORT_SPEC_VERSION = "1.0"
+# EvalPort spec version the emitted documents conform to (semver, per spec).
+EVALPORT_SPEC_VERSION = "1.0.0-rc.5"
+
+# Grader that carries PraisonAI's own per-case verdict (EvalResult.passed/score).
+# EvalPort requires every test case to reference at least one grader.
+VERDICT_GRADER_ID = "praisonai_verdict"
+_HANDLER = "praisonaiagents.eval"
+_META_KEY = "praisonai"
+
+
+def _grader_def(grader_id: str, description: str) -> Dict[str, Any]:
+    return {
+        "id": grader_id,
+        "type": "custom",
+        "params": {"handler": _HANDLER},
+        "description": description,
+    }
 
 
 def _case_to_evalport(case: EvalCase) -> Dict[str, Any]:
-    """Map an ``EvalCase`` to an EvalPort test-case dict.
+    """Map an ``EvalCase`` to an EvalPort TestCase dict.
 
-    The native ``timeout_seconds`` is emitted as a dedicated top-level field so
-    it never collides with a user-supplied ``metadata["timeout_seconds"]`` key,
-    keeping round trips lossless for both.
+    ``criteria`` become grader references (defined at suite level); a case
+    without criteria references the verdict grader. ``timeout_seconds`` maps to
+    the spec's ``timeout_ms``; user ``metadata`` is passed through untouched.
     """
     item: Dict[str, Any] = {
         "id": case.name,
         "input": case.input,
+        "graders": list(case.criteria) or [VERDICT_GRADER_ID],
     }
     if case.expected is not None:
         item["expected_output"] = case.expected
-    if case.criteria:
-        item["graders"] = list(case.criteria)
-    if case.timeout_seconds is not None:
-        item["timeout_seconds"] = case.timeout_seconds
-    metadata = dict(case.metadata or {})
-    if metadata:
-        item["metadata"] = metadata
+    if case.timeout_seconds is not None and case.timeout_seconds > 0:
+        item["timeout_ms"] = max(1, int(round(case.timeout_seconds * 1000)))
+    if case.metadata:
+        item["metadata"] = dict(case.metadata)
     return item
 
 
 def _case_from_evalport(item: Dict[str, Any]) -> EvalCase:
-    """Map an EvalPort test-case dict to an ``EvalCase``.
+    """Map an EvalPort TestCase dict to an ``EvalCase``.
 
-    Prefers the dedicated top-level ``timeout_seconds`` field; falls back to a
-    ``metadata["timeout_seconds"]`` value for suites emitted by other tools,
-    without mutating the caller's metadata.
+    Reads ``timeout_ms`` (spec); falls back to a legacy top-level or
+    ``metadata["timeout_seconds"]`` value, without mutating caller metadata.
     """
     metadata = dict(item.get("metadata") or {})
-    if "timeout_seconds" in item:
+    if "timeout_ms" in item:
+        timeout = item["timeout_ms"] / 1000.0
+    elif "timeout_seconds" in item:
         timeout = item["timeout_seconds"]
     else:
         timeout = metadata.get("timeout_seconds", 30.0)
+    criteria = []
+    for g in item.get("graders") or item.get("criteria") or []:
+        gid = g.get("id") if isinstance(g, dict) else g
+        if gid and gid != VERDICT_GRADER_ID:
+            criteria.append(gid)
     return EvalCase(
         name=item.get("id") or item.get("name") or "case",
         input=item.get("input", ""),
         expected=item.get("expected_output", item.get("expected")),
-        criteria=list(item.get("graders") or item.get("criteria") or []),
+        criteria=criteria,
         metadata=metadata,
         timeout_seconds=timeout,
     )
@@ -88,16 +114,28 @@ def to_evalport(package: EvalPackage) -> Dict[str, Any]:
     Returns:
         A spec-shaped dict suitable for ``openeval.validate.validate_suite()``.
     """
-    return {
-        "evalport_version": EVALPORT_SPEC_VERSION,
-        "kind": "suite",
+    criteria = dict.fromkeys(c for case in package.cases for c in case.criteria)
+    criteria.pop(VERDICT_GRADER_ID, None)
+    graders = [_grader_def(VERDICT_GRADER_ID, "PraisonAI per-case verdict (EvalResult.passed/score)")]
+    graders += [_grader_def(c, f"PraisonAI criterion: {c}") for c in criteria]
+
+    suite: Dict[str, Any] = {
+        "version": EVALPORT_SPEC_VERSION,
+        "id": package.name,
         "name": package.name,
-        "description": package.description,
-        "version": package.version,
-        "cases": [_case_to_evalport(c) for c in package.cases],
-        "thresholds": dict(package.thresholds or {}),
-        "seed": package.seed,
+        "graders": graders,
+        "test_cases": [_case_to_evalport(c) for c in package.cases],
+        "metadata": {
+            _META_KEY: {
+                "version": package.version,
+                "thresholds": dict(package.thresholds or {}),
+                "seed": package.seed,
+            }
+        },
     }
+    if package.description:
+        suite["description"] = package.description
+    return suite
 
 
 def from_evalport(suite: Dict[str, Any]) -> EvalPackage:
@@ -110,22 +148,49 @@ def from_evalport(suite: Dict[str, Any]) -> EvalPackage:
         An ``EvalPackage`` whose cases can be run via ``EvalSuite`` /
         ``HarnessEvaluator`` as native ``EvalCase`` objects.
     """
-    cases: List[EvalCase] = [_case_from_evalport(c) for c in suite.get("cases", [])]
+    items = suite.get("test_cases", suite.get("cases", []))
+    cases: List[EvalCase] = [_case_from_evalport(c) for c in items]
+    meta = (suite.get("metadata") or {}).get(_META_KEY) or {}
+    legacy = "evalport_version" in suite  # documents emitted before spec alignment
     return EvalPackage(
-        name=suite.get("name", "suite"),
+        name=suite.get("name") or suite.get("id") or "suite",
         description=suite.get("description", ""),
-        version=suite.get("version", "1.0.0"),
+        version=meta.get("version") or (suite.get("version") if legacy else None) or "1.0.0",
         cases=cases,
-        thresholds=dict(suite.get("thresholds") or {}),
-        seed=suite.get("seed"),
+        thresholds=dict(meta.get("thresholds") or suite.get("thresholds") or {}),
+        seed=meta.get("seed", suite.get("seed")),
     )
 
 
-def report_to_evalport(report: EvalReport) -> Dict[str, Any]:
+def _unit_score(value: Any) -> Optional[float]:
+    if isinstance(value, bool) or not isinstance(value, (int, float)) or value != value:
+        return None
+    return min(1.0, max(0.0, float(value)))
+
+
+def _runner_info() -> Dict[str, str]:
+    runner = {"name": "praisonaiagents"}
+    try:
+        from importlib.metadata import version
+
+        runner["version"] = version("praisonaiagents")
+    except Exception:
+        pass
+    return runner
+
+
+def report_to_evalport(
+    report: EvalReport,
+    *,
+    run_id: Optional[str] = None,
+    started_at: Optional[str] = None,
+) -> Dict[str, Any]:
     """Convert an ``EvalReport`` to an EvalPort ``ResultSet`` dict.
 
     Args:
         report: The aggregated report from running an eval package.
+        run_id: Unique run identifier (defaults to a random UUID).
+        started_at: RFC 3339 run start time (defaults to now, UTC).
 
     Returns:
         A spec-shaped dict suitable for
@@ -133,33 +198,57 @@ def report_to_evalport(report: EvalReport) -> Dict[str, Any]:
     """
     results: List[Dict[str, Any]] = []
     for r in report.results:
+        grader: Dict[str, Any] = {
+            "grader_id": VERDICT_GRADER_ID,
+            "type": "custom",
+            "score": _unit_score(r.score),
+            "passed": bool(r.passed),
+        }
+        if grader["score"] is None:
+            grader["passed"] = False  # spec: null score means "not verified"
+        elif grader["score"] != r.score:
+            grader["metadata"] = {"openeval.raw_score": r.score}  # clamped
+
         item: Dict[str, Any] = {
-            "case_id": r.case_name,
-            "passed": r.passed,
-            "score": r.score,
-            "latency_ms": r.latency_ms,
+            "test_case_id": r.case_name,
+            "passed": grader["passed"],
+            "grader_results": [grader],
         }
         if r.actual_output is not None:
-            item["actual_output"] = r.actual_output
+            item["actual_output"] = str(r.actual_output)
+        if r.latency_ms is not None and r.latency_ms >= 0:
+            item["duration_ms"] = int(round(r.latency_ms))
         if r.error is not None:
-            item["error"] = r.error
+            item["error"] = {"type": "runner_error", "message": str(r.error)}
+        extra: Dict[str, Any] = {}
         if r.criteria_scores:
-            item["grader_scores"] = dict(r.criteria_scores)
+            extra["criteria_scores"] = dict(r.criteria_scores)
         if r.record is not None:
-            item["record"] = r.record
+            extra["record"] = r.record
+        if extra:
+            item["metadata"] = {_META_KEY: extra}
         results.append(item)
 
+    summary: Dict[str, Any] = {
+        "total": report.total_cases,
+        "passed": report.passed_cases,
+        "failed": report.failed_cases,
+        "pass_rate": report.pass_rate,
+    }
+    meta: Dict[str, Any] = {"thresholds_met": dict(report.thresholds_met or {})}
+    avg = _unit_score(report.average_score)
+    if avg is not None:
+        summary["avg_score"] = avg
+        if avg != report.average_score:
+            meta["average_score"] = report.average_score  # clamped
+
     return {
-        "evalport_version": EVALPORT_SPEC_VERSION,
-        "kind": "result_set",
-        "suite_name": report.package_name,
-        "summary": {
-            "total": report.total_cases,
-            "passed": report.passed_cases,
-            "failed": report.failed_cases,
-            "pass_rate": report.pass_rate,
-            "average_score": report.average_score,
-            "thresholds_met": dict(report.thresholds_met or {}),
-        },
+        "version": EVALPORT_SPEC_VERSION,
+        "suite_id": report.package_name,
+        "run_id": run_id or uuid.uuid4().hex,
+        "started_at": started_at or datetime.now(timezone.utc).isoformat(),
+        "runner": _runner_info(),
         "results": results,
+        "summary": summary,
+        "metadata": {_META_KEY: meta},
     }
diff --git a/src/praisonai-agents/tests/unit/eval/test_evalport.py b/src/praisonai-agents/tests/unit/eval/test_evalport.py
index 523ee7d..7a6150b 100644
--- a/src/praisonai-agents/tests/unit/eval/test_evalport.py
+++ b/src/praisonai-agents/tests/unit/eval/test_evalport.py
@@ -4,7 +4,10 @@ Covers the dependency-free round-trip between PraisonAI eval models and the
 EvalPort spec dicts. A real agentic test (gated by RUN_LIVE_TESTS=1) runs a live
 Agent and exports its EvalReport as an EvalPort ResultSet.
 """
+import json
 import os
+import re
+from datetime import datetime
 
 import pytest
 
@@ -17,6 +20,7 @@ from praisonaiagents.eval import (
     report_to_evalport,
     to_evalport,
 )
+from praisonaiagents.eval.evalport import EVALPORT_SPEC_VERSION, VERDICT_GRADER_ID
 
 
 class TestEvalPortImports:
@@ -52,20 +56,25 @@ class TestSuiteConversion:
 
     def test_to_evalport_shape(self):
         suite = to_evalport(self._pkg())
-        assert suite["kind"] == "suite"
+        assert suite["version"] == EVALPORT_SPEC_VERSION
+        assert suite["id"] == "support_agent_eval"
         assert suite["name"] == "support_agent_eval"
-        assert suite["version"] == "2.1.0"
-        assert suite["thresholds"] == {"accuracy": 0.9}
-        assert suite["seed"] == 7
-        assert "evalport_version" in suite
+        assert suite["description"] == "Support agent suite"
+        native = suite["metadata"]["praisonai"]
+        assert native == {"version": "2.1.0", "thresholds": {"accuracy": 0.9}, "seed": 7}
 
-        case = suite["cases"][0]
+        grader_ids = [g["id"] for g in suite["graders"]]
+        assert grader_ids == [VERDICT_GRADER_ID, "answer_correct"]
+        for g in suite["graders"]:
+            assert g["type"] == "custom" and g["params"]["handler"]
+
+        case = suite["test_cases"][0]
         assert case["id"] == "refund_policy"
         assert case["input"] == "What's your refund policy?"
         assert case["expected_output"] == "30 days, unused, receipt required"
         assert case["graders"] == ["answer_correct"]
         assert case["metadata"]["tier"] == "gold"
-        assert case["timeout_seconds"] == 15.0
+        assert case["timeout_ms"] == 15000
         assert "timeout_seconds" not in case["metadata"]
 
     def test_from_evalport_shape(self):
@@ -106,9 +115,11 @@ class TestSuiteConversion:
 
     def test_case_without_expected_or_criteria(self):
         pkg = EvalPackage(name="p", cases=[EvalCase(name="c", input="x")])
-        case = to_evalport(pkg)["cases"][0]
+        case = to_evalport(pkg)["test_cases"][0]
         assert "expected_output" not in case
-        assert "graders" not in case
+        # EvalPort requires >= 1 grader per test case: fall back to the verdict grader.
+        assert case["graders"] == [VERDICT_GRADER_ID]
+        assert from_evalport(to_evalport(pkg)).cases[0].criteria == []
 
     def test_metadata_timeout_key_does_not_corrupt_native_timeout(self):
         """A user ``metadata['timeout_seconds']`` must not clobber the native one."""
@@ -123,8 +134,8 @@ class TestSuiteConversion:
                 )
             ],
         )
-        case = to_evalport(pkg)["cases"][0]
-        assert case["timeout_seconds"] == 15.0
+        case = to_evalport(pkg)["test_cases"][0]
+        assert case["timeout_ms"] == 15000
         assert case["metadata"]["timeout_seconds"] == 999
 
         round_tripped = from_evalport(to_evalport(pkg)).cases[0]
@@ -141,6 +152,43 @@ class TestSuiteConversion:
         assert case.timeout_seconds == 45
         assert case.metadata["timeout_seconds"] == 45
 
+    def test_external_spec_suite_imports(self):
+        """A spec-shaped suite from another tool (test_ca