Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Wrong field order with typed fields in dspy.Signature #7759

Open
malusamayo opened this issue Feb 4, 2025 · 1 comment
Open

[Bug] Wrong field order with typed fields in dspy.Signature #7759

malusamayo opened this issue Feb 4, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@malusamayo
Copy link

What happened?

When adding type annotations to some of the output fields, the final parsed field orders are wrong:

class ExampleSignature(dspy.Signature):
    """Evaluate the text as "good" or "bad"."""
    
    text = dspy.InputField(desc="The text to evaluate.")
    output = dspy.OutputField(desc="The evaluation of the text.")
    pass_evaluation: bool = dspy.OutputField(desc="The evaluation result, True if the text is good, False otherwise.") 

print(ExampleSignature.fields)

In the output, the orders of two output fields are swapped:

{'text': FieldInfo(annotation=str, required=True, json_schema_extra={'desc': 'The text to evaluate.', '__dspy_field_type': 'input', 'prefix': 'Text:'}),
 'pass_evaluation': FieldInfo(annotation=bool, required=True, json_schema_extra={'desc': 'The evaluation result, True if the text is good, False otherwise.', '__dspy_field_type': 'output', 'prefix': 'Pass Evaluation:'}),
 'output': FieldInfo(annotation=str, required=True, json_schema_extra={'desc': 'The evaluation of the text.', '__dspy_field_type': 'output', 'prefix': 'Output:'})}

This only happens when output fields are partially typed. If all output fields are typed, the order is correct.

Steps to reproduce

See above.

DSPy version

2.6.0

@malusamayo malusamayo added the bug Something isn't working label Feb 4, 2025
@okhat
Copy link
Collaborator

okhat commented Feb 4, 2025

Yes, I believe it's a bug upstream in pydantic as far as @isaacbmiller discovered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants