You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I faced this simple error today about type coercion. The error is raised when an int are passed into str type in signature. Below is my signature class.
{
"reasoning": "The laptop is suitable for general use and office work due to its Intel Core i5 processor, 16GB of RAM, and 512GB SSD storage.",
"brand": "HP",
"series_model": "14",
"processor": "Intel Core i5-1235U (up to 4.4 GHz with Intel Turbo Boost Technology)",
"memory": "16GB DDR4-3200 MHz RAM",
"storage": "512GB PCIe NVMe M.2 SSD",
"graphics_card": "Intel Iris Xe Graphics"
}
I guess the problem is this: because the series_model is just the string 14, the adapter incorrectly parsed it into an int and then the error is raised in this line:
For Pydantic models, we can do coerce_numbers_to_str=True to solve this type coercion problem, but currently I can't find any documentation in DSPy that allows me to set the model_config of a signature nor the DSPy respect the model_config in the signature class.
I agree, the issue might lie somewhere else, and passing a custom ConfigDict is a temporary fix in this case.
I think it would be beneficial to also expose a way to set a custom ConfigDict for a signature. It would offer more control of the signature parsing behavior.
Hello, I faced this simple error today about type coercion. The error is raised when an
int
are passed intostr
type in signature. Below is my signature class.Below is the result from
dspy.inspect_history()
I guess the problem is this: because the
series_model
is just the string 14, the adapter incorrectly parsed it into anint
and then the error is raised in this line:dspy/dspy/adapters/json_adapter.py
Line 139 in 526bc19
For Pydantic models, we can do
coerce_numbers_to_str=True
to solve this type coercion problem, but currently I can't find any documentation in DSPy that allows me to set themodel_config
of a signature nor the DSPy respect themodel_config
in the signature class.For now, this is my hack to solve this number coercion problem.
Is there a plan to allow signature class to accept a
ConfigDict
or specify it somewhere to control this behavior?Thanks
Edit:
Python: 3.11
Package manager: uv 0.5.9
DSPy: 2.5.43
The text was updated successfully, but these errors were encountered: