fix(predict-rlm): serialize Pydantic values at JSON boundaries - #60
Draft
taogaetz wants to merge 1 commit into
Draft
fix(predict-rlm): serialize Pydantic values at JSON boundaries#60taogaetz wants to merge 1 commit into
taogaetz wants to merge 1 commit into
Conversation
taogaetz
commented
Jul 30, 2026
|
|
||
| from dspy.primitives.code_interpreter import CodeInterpreterError, FinalOutput | ||
| from dspy.primitives.python_interpreter import PythonInterpreter | ||
| from pydantic import BaseModel |
Author
|
One concern before this moves out of draft: although the code diff is small, changing the shared Pydantic normalizer from We should confirm that converting rich Python values to JSON-native forms at this layer is the intended contract, and consider narrowing the change or adding broader compatibility coverage if it is not. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale
PredictRLM could fail after otherwise successful typed agent work when Pydantic outputs contained JSON-native domain types such as
dateandDecimal. The same values could also make a subsequent JSPI-backed agent step unusable when a typed result was passed forward as input. This breaks chained typed workflows even though the values have valid Pydantic JSON representations.Two focused reproductions exposed the violated behavior:
TypeError: Object of type date is not JSON serializable.datetime.date(...)into the pre-execution state, causing sandbox iterations to fail before user code could run.The root cause was Python-mode Pydantic dumping at both JSON/transport boundaries. Nested rich scalars survived normalization and were later handed to JSON serialization or embedded into generated Python source.
Summary
dateandDecimalvalues.Test Plan
uv run pytest -o addopts= tests/test_interpreter.py::TestNoneValueSerialization::test_pydantic_model_with_date_and_decimal_injected_as_plain_data tests/test_interpreter.py::TestNoneValueSerialization::test_pydantic_model_with_none_fields_injected_as_variable tests/test_small_kernel.py::test_strict_evidence_serializes_pydantic_dates_and_decimals -quv run ruff check src/predict_rlm/serialization.py src/predict_rlm/backends/jspi/backend.py tests/test_small_kernel.py tests/test_interpreter.py