Skip to content

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

@malusamayo

Description

@malusamayo

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

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