dspy icon indicating copy to clipboard operation
dspy copied to clipboard

[Bug] ChatAdapter fails to parse list[str] output fields

Open mfux opened this issue 3 weeks ago • 1 comments

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

mfux avatar Nov 19 '25 19:11 mfux

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']

isaacbmiller avatar Nov 19 '25 23:11 isaacbmiller

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.toml was pointing to different python version than my dockerfile
  • I had multiple versions installed in my devcontainer.
  • my uv metadata file i.e. .python-version was pointing to different python version.

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.

saibhaskerraju avatar Nov 22 '25 23:11 saibhaskerraju