-
[OPIK-3810] [BE] Fix JSON serialization for complex objects in Python online scoring (#4713)
发布于
2026-01-12 15:00:48 +00:00 - [OPIK-3810] [BE] Fix JSON serialization for complex objects in Python online scoring
When extracting nested JSON objects from trace data for Python evaluators,
the code was using Java's toString() method which produces {key=value} format
instead of valid JSON {"key":"value"}.This caused json.loads() to fail in Python with:
JSONDecodeError: Expecting property name enclosed in double quotesFix: Added serializeToJsonString() helper that properly serializes complex
objects (Maps, Lists) to JSON while preserving simple types (String, Number,
Boolean) as-is for backward compatibility.This also improves LLM-as-Judge by providing cleaner JSON format in prompts.
- Revision 2: Add test for Python evaluator JSON serialization
Added testToReplacementsProducesValidJsonForComplexObjects to verify that
toReplacements() produces valid JSON for complex nested objects, which is
what Python evaluators receive directly (without Mustache rendering).This addresses the code review feedback to add a test verifying valid JSON
is sent to the Python scorer.下载附件