|
| 1 | +import json |
1 | 2 | from abc import ABC, abstractmethod |
2 | 3 | from types import TracebackType |
3 | 4 | from typing import TYPE_CHECKING, Any, Callable, Optional, Self, Type |
@@ -365,7 +366,6 @@ def _log_evaluation( |
365 | 366 | context_id: str, |
366 | 367 | evaluation_passed: bool, |
367 | 368 | reason: str, |
368 | | - scenario_type: Optional[str], |
369 | 369 | **kwargs, |
370 | 370 | ) -> None: |
371 | 371 | """ |
@@ -395,7 +395,19 @@ def _log_evaluation( |
395 | 395 | "context_id": context_id, |
396 | 396 | }, |
397 | 397 | ) |
398 | | - scenario_dict = {"scenario": scenario} |
| 398 | + |
| 399 | + try: |
| 400 | + scenario_dict = json.loads(scenario) |
| 401 | + except json.JSONDecodeError: |
| 402 | + logger.warning( |
| 403 | + "⚠️ Failed to parse scenario dict as JSON - recovering", |
| 404 | + extra={ |
| 405 | + "scenario": scenario, |
| 406 | + "context_id": context_id, |
| 407 | + }, |
| 408 | + ) |
| 409 | + scenario_dict = {"scenario": scenario} |
| 410 | + return |
399 | 411 | elif isinstance(scenario, dict): |
400 | 412 | scenario_dict = scenario |
401 | 413 | else: |
@@ -423,7 +435,10 @@ def _log_evaluation( |
423 | 435 | ), |
424 | 436 | "evaluation_passed (from agent)": evaluation_passed, |
425 | 437 | "reason (from agent)": reason, |
426 | | - "scenario_type": scenario_type, |
| 438 | + "scenario_type": scenario_dict.get( |
| 439 | + "scenario_type", |
| 440 | + ScenarioType.POLICY.value, |
| 441 | + ), |
427 | 442 | "expected_outcome": scenario_dict.get( |
428 | 443 | "expected_outcome", |
429 | 444 | "None", |
|
0 commit comments