ollama / ollama/ollama-python

Thinking with Structured Output does not work

Open
#523 1 comment 5 reactions 1 assignee View on GitHub

@ParthSareen is already working on this.

Since May 30, 2025.

thinking
Dominant language
Python
Stars
10.5k
Forks
1.2k
Avg merge
4m
Merged PRs (30d)
1

Description

Updated to the latest to use the new thinking mode along with structured outputs and ran into an error. I typically make the call using:

response = client.chat(
                    model=model,
                    messages=messages,
                    format=output_model.model_json_schema(),
                    think=True, # added this recently
                    options={"temperature": 0, "num_ctx": 16384}
                )

and process the output using:

output = output_model.model_validate_json(response.message.content)

This works still when think is omitted however with it added and set to True, I get the following output:

role='assistant' content='{\n\n{\n\n"vte_present": "uncertain",\n"reason_for_answer": "Positive study for acute upper extremity nonocclusive DVT in the axillary vein (deep vein) but evidence of occlusive superficial venous thrombus in the cephalic or basilic veins. Since superficial venous thrombosis is not considered VTE, and there\'s a possibility that the axillary vein finding might be chronic or uncertain, it should be classified as uncertain."\n}\n\n  ' thinking=None images=None tool_calls=None

Notice the double opening curly brace and that thinking is None. Please let me know if I can provide any other details.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.