Skip to content

[Bug] Type Validation not enforced in Python 3.14 #9098

@timo-obrecht

Description

@timo-obrecht

What happened?

When using dspy.Signature classes to enforce structured data, the type are not correctly parsed and converted in Python 3.14. It works fine in 3.13.

Steps to reproduce

import os
import dspy


lm = dspy.LM(
    model="openrouter/openai/gpt-4o-mini",
    api_base="https://openrouter.ai/api/v1",
    api_key=os.getenv("OPENROUTER_API_KEY"),
    temperature=0.0,
)


class ObjectInfo(dspy.Signature):
    text: str = dspy.InputField(desc="A given object")
    is_blue: bool = dspy.OutputField(desc="Is this object blue ?")
    is_big: bool = dspy.OutputField(desc="Is this object big ?")


def main(padding: int) -> bool:
    module = dspy.Predict(
        ObjectInfo.with_instructions(
            "The user gives an object and you must return if the object is blue and if the object is big"
        )
    )
    with dspy.context(lm=lm, num_retries=0):
        object_info = module(text="The sky" + " " * padding)  # add padding to avoid prompt caching
    return not all((isinstance(object_info.is_blue, bool), isinstance(object_info.is_big, bool)))


if __name__ == "__main__":
    print(f"Got {sum(main(i) for i in range(10))} errors")

With this setup, I always get 100% errors in python 3.14. The object returned is

Prediction(
    is_blue='Yes',
    is_big='Yes'
)

I get 0 errors executing the same code in Python 3.13. The object returned is :

Prediction(
    is_blue=True,
    is_big=True
)

DSPy version

3.0.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions