From a99614740620987a11a7b11e16911306505ba93c Mon Sep 17 00:00:00 2001 From: Guy Davidson Date: Thu, 30 Oct 2025 14:29:20 -0400 Subject: [PATCH] Fixed a serialization bug in `dspy.Example` `Example.toDict()` did not account for the case in which the value is a tuple. This happens in `Evaluate.__call__()`, where the `results` is a list of tuples, where each tuple includes `Prediction` objects internally. Right now, the failure to parse tuples means the internal `Prediction` objects do not get serialized to dicts, which means that the resultant dict is not, for example, json-serializable. I opted for a minimal fix, but there could be other approaches, e.g. adding a dependency to handle the serialization, etc. --- dspy/primitives/example.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dspy/primitives/example.py b/dspy/primitives/example.py index 549da6bce7..afbae57912 100644 --- a/dspy/primitives/example.py +++ b/dspy/primitives/example.py @@ -195,6 +195,8 @@ def convert_to_serializable(value): return value.toDict() elif isinstance(value, list): return [convert_to_serializable(item) for item in value] + elif isinstance(value, tuple): + return tuple(convert_to_serializable(item) for item in value) elif isinstance(value, dict): return {k: convert_to_serializable(v) for k, v in value.items()} else: