@@ -649,6 +649,37 @@ class MySignature(dspy.Signature):
649649 assert result [0 ]["reasoning" ] == dspy .Reasoning (content = "Step-by-step thinking about the capital of France" )
650650
651651
652+ def test_chat_adapter_parses_float_with_underscores ():
653+ """
654+ This test verifies that ChatAdapter can parse float numbers with underscores.
655+ After json-repair version 0.54.1, floats like "123_456.789" are treated as normal float numbers.
656+ """
657+
658+ class Score (pydantic .BaseModel ):
659+ score : float
660+
661+ class MySignature (dspy .Signature ):
662+ question : str = dspy .InputField ()
663+ score : Score = dspy .OutputField ()
664+
665+ adapter = dspy .ChatAdapter ()
666+
667+ # Simulate a response with a float number containing underscores
668+ with mock .patch ("litellm.completion" ) as mock_completion :
669+ mock_completion .return_value = ModelResponse (
670+ choices = [
671+ Choices (message = Message (content = "[[ ## score ## ]]\n {'score': 123_456.789}\n [[ ## completed ## ]]" ))
672+ ],
673+ model = "openai/gpt-4o-mini" ,
674+ )
675+
676+ lm = dspy .LM ("openai/gpt-4o-mini" , cache = False )
677+ result = adapter (lm , {}, MySignature , [], {"question" : "What is the score?" })
678+
679+ # The underscore-separated float should be parsed as a normal float
680+ assert result [0 ]["score" ].score == 123456.789
681+
682+
652683def test_format_system_message ():
653684 class MySignature (dspy .Signature ):
654685 """Answer the question with multiple answers and scores"""
0 commit comments