mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 09:05:23 -04:00
Structured Output - Literal Validation Error #228
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @XanderBrooks on GitHub (Feb 26, 2025).
I am able to run tools, but structured outputs are giving me an issue.
It seems like ollama version (0.5.12) that I have installed only accepts a literal for the format arg. Take a look:
Docstring output:
chat?
So I am basically able to get NON-specified json out (if i set it to 'json', it will output json, but NOT within a pre-defined structure.) This means that it likely fails during validation because there isn't a specified structure going into the chat instance.
If I run the basic code included on the blog post (and most tutorials, the 'tell me more about Canada' example), it fails. I am also using llama3.2:8b (same as Parth Sareen's recent video here [https://www.youtube.com/watch?v=UoZkkz1oXgQ]). I tried both pydantic as in the example, and multiple attempts to see if loading the json in using json.loads or just a direct py object. Same error every time, which is why I checked the docstring.
I understand I could reinforce the structure within the prompt, but I was curious why this was not natively working.
Curious if this is a 0.5.12 bug or a windows/mac vs linux limitation.
Example code and error:
Output
Thanks for any help.
@ParthSareen commented on GitHub (Feb 26, 2025):
What's your ollama python version?
pip show ollama@XanderBrooks commented on GitHub (Feb 26, 2025):
Thanks for the quick reply!
Version: 0.4.2
Name: ollama
Version: 0.4.2
Summary: The official Python client for Ollama.
Home-page: https://ollama.com
Author: Ollama
Author-email: hello@ollama.com
License: MIT
Location: C:\Users...\AppData\Local\Programs\Python\Python312\Lib\site-packages
Requires: httpx, pydantic
Required-by: langchain-ollama
@ParthSareen commented on GitHub (Feb 26, 2025):
Yup that's the issue. Structured outputs support came in 0.4.3+
pip install ollama --upgradeHope it helps!
@XanderBrooks commented on GitHub (Feb 26, 2025):
Cured! Thank you! Sorry I thought updating the other day to 0.5.12 was enough. Makes complete sense why that is NOT the case. I'll be sure to upgrade both sides consistently.