[Bug] ChatAdapter fails to parse list[str] output fields
What happened?
ChatAdapter.parse() incorrectly returns a JSON string instead of a parsed list when the signature has a list[str] output field. The string '["I10", "Z79.4"]' is returned instead of the list ["I10", "Z79.4"].
Steps to reproduce
import dspy
from dspy.utils.dummies import DummyLM
class Coder(dspy.Signature):
"""Extract ICD-10 codes from a medical document"""
document: str = dspy.InputField(desc="The medical document to analyze")
codes: list[str] = dspy.OutputField(desc="The list of ICD-10 codes")
adapter = dspy.ChatAdapter()
lm = DummyLM([{"codes": ["I10", "Z79.4"]}], adapter=adapter)
dspy.configure(lm=lm, adapter=adapter)
predictor = dspy.Predict(Coder)
prediction = predictor(document="some medical document text")
print(f"Type: {type(prediction.codes)}") # <class 'str'>
print(f"Value: {prediction.codes}") # '["I10", "Z79.4"]'
assert isinstance(prediction.codes, list) # FAILS!
Debug Output
Raw LM output: ['[[ ## codes ## ]]\n["I10", "Z79.4"]']
Prediction.codes type: <class 'str'>
Prediction.codes value: ["I10", "Z79.4"]
DSPy version
3.0.4
Can you share more about your version?
I have tested this on 3.0.4 and main and both give the correct output:
Type: <class 'list'>
Value: ['I10', 'Z79.4']
Hello @mfux
I faced the same issue today and these are my versions and configs
dspy== 3.0.4
mlflow == 3.6.0
I tried to downgrade to 2.6.27 and still faced the same problem. thats when, I tried checking my python env versions and venv path.
my problem was ,
- my
pyproject.tomlwas pointing to different pythonversionthan my dockerfile - I had multiple versions installed in my
devcontainer. - my
uvmetadata file i.e..python-versionwas pointing to different pythonversion.
solution: make sure all the python versions match and only one version is installed and later verify the .venv path.
my repo: https://github.com/saibhaskerraju/dspy-optimization
@isaacbmiller , I can confirm that its a false alarm.