Official example MathResponse raise invalid json

I am using official response_format example,when i run this code i got error :pydantic_core._pydantic_core.ValidationError: 1 validation error for MathResponse

Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value=‘To solve the equation \…lution": -3.625\n}\n```’,input_type=str]

below is my code:


from pydantic import BaseModel

from openai import OpenAI

class Step(BaseModel):
    explanation: str
    output: str


class MathResponse(BaseModel):
    steps: list[Step]
    final_answer: str

def test_response_json():
    config = Config()
    client = OpenAI(base_url=config.OPENAI_BASE_URL, api_key=config.OPENAI_API_KEY)
    completion = client.beta.chat.completions.parse(
        model="gpt-4o-2024-08-06",
        messages=[
            {"role": "system", "content": "You are a helpful math tutor. retusn jso"},
            {"role": "user", "content": "solve 8x + 31 = 2"},
        ],
        response_format=MathResponse,
    )

    message = completion.choices[0].message
    if message.parsed:
        print(message.parsed.steps)
        print(message.parsed.final_answer)
    else:
        print(message.refusal)



python package version:

openai:1.42.0
pyandic:2.8.2