Skip to content

Conversation

@guydav
Copy link

@guydav guydav commented Oct 30, 2025

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.

`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.
Copy link
Collaborator

@chenmoneygithub chenmoneygithub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

I am a bit confused about the case where you see errors though, are you trying to serialize the entire evaluation result? That shouldn't be a dspy.Example. Could you include a reproduce code snippet?

@guydav
Copy link
Author

guydav commented Nov 1, 2025

Hi @chenmoneygithub -- tl:dr; everything inherits from dspy.Example. Evaluate.__call__ returns the following:

EvaluationResult(
    score=round(100 * ncorrect / ntotal, 2),
    results=results,
)

EvaluationResult subclasses Prediction, which subclasses Example.
In the structure above, results has the type signature list[tuple["dspy.Example", "dspy.Example", Any]].
This is how we get an Example with, eventually, tuples that include Examples within them.

If this doesn't make sense, I can generate a minimal example, but the thing that failed for me is cherry-picking the save_as_json logic implemented in Example.__call__ in the current main (here)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants