Skip to content

[BUG CLIENT]: client.chat.parse throws an error #282

@augho

Description

@augho

Python -VV

Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)]

Pip Freeze

annotated-types==0.7.0

anyio==4.11.0

certifi==2025.10.5

charset-normalizer==3.4.4

dotenv==0.9.9

eval_type_backport==0.2.2

h11==0.16.0

httpcore==1.0.9

httpx==0.28.1

idna==3.11

invoke==2.2.1

mistralai==1.9.11

pydantic==2.12.3

pydantic_core==2.41.4

python-dateutil==2.9.0.post0

python-dotenv==1.1.1

PyYAML==6.0.3

requests==2.32.5

six==1.17.0

sniffio==1.3.1

typing-inspection==0.4.2

typing_extensions==4.15.0

urllib3==2.5.0

Reproduction Steps

I followed the documentation and got a json decode error

Expected Behavior

Return an output without throwing

Additional Context

On the following line

response = self.client.chat.parse(

        model="codestral-latest",

        messages=[{"role": "user", "content": "I recently read 'To kill a Mockingbird' by Harper Lee"}],

        response_format=BookModel

    )

Error:

File "<path>\.venv\Lib\site-packages\mistralai\chat.py", line 42, in parse

    parsed_response = convert_to_parsed_chat_completion_response(

        response, response_format

    )

  File "<path>\.venv\Lib\site-packages\mistralai\extra\struct_chat.py", line 27, in convert_to_parsed_chat_completion_response

    parsed_message.parsed = pydantic_model_from_json(json.loads(parsed_message.content), response_format)

                                                     ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^

  File "C:\Program Files\Python313\Lib\json\__init__.py", line 346, in loads

    return _default_decoder.decode(s)

           ~~~~~~~~~~~~~~~~~~~~~~~^^^

  File "C:\Program Files\Python313\Lib\json\decoder.py", line 344, in decode

    obj, end = self.raw_decode(s, idx=_w(s, 0).end())

               ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^

  File "C:\Program Files\Python313\Lib\json\decoder.py", line 362, in raw_decode

    raise JSONDecodeError("Expecting value", s, err.value) from None

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The model is codestral-2503 and the class BookModel is the same as in the documentation

Suggested Solutions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions