@@ -619,6 +619,48 @@ class ScoredSignature(dspy.Signature):
619619 Proposed Signature: Output""" )
620620
621621
622+ def test_custom_reasoning_field ():
623+ class Question (pydantic .BaseModel ):
624+ value : str
625+
626+ class QuestionSignature (dspy .Signature ):
627+ topic : str = dspy .InputField ()
628+ question : Question = dspy .OutputField ()
629+
630+ reasoning = dspy .OutputField (
631+ prefix = "Custom Reasoning: Let's break this down. To generate a question about" ,
632+ desc = "${topic}, we should ..." ,
633+ )
634+
635+ program = TypedChainOfThought (QuestionSignature , reasoning = reasoning )
636+
637+ expected = "What is the speed of light?"
638+ lm = DummyLM (["Thoughts" , f'{{"value": "{ expected } "}}' ])
639+ dspy .settings .configure (lm = lm )
640+
641+ output = program (topic = "Physics" )
642+
643+ assert isinstance (output .question , Question )
644+ assert output .question .value == expected
645+
646+ assert lm .get_convo (- 1 ) == textwrap .dedent ("""\
647+ Given the fields `topic`, produce the fields `question`.
648+
649+ ---
650+
651+ Follow the following format.
652+
653+ Topic: ${topic}
654+ Custom Reasoning: Let's break this down. To generate a question about ${topic}, we should ...
655+ Question: ${question}. Respond with a single JSON object. JSON Schema: {"properties": {"value": {"title": "Value", "type": "string"}}, "required": ["value"], "title": "Question", "type": "object"}
656+
657+ ---
658+
659+ Topic: Physics
660+ Custom Reasoning: Let's break this down. To generate a question about Thoughts
661+ Question: {"value": "What is the speed of light?"}""" )
662+
663+
622664def test_generic_signature ():
623665 T = TypeVar ("T" )
624666
0 commit comments