mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 17:15:23 -04:00
Simple Enums missing from structured outputs #257
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 @suprateembanerjee on GitHub (Apr 6, 2025).
Structured outputs currently only support Pydantic models (which are very useful), but is presently missing support for simple Enums, and requires redundant wrapping into a Pydantic model.
I want to be able to perform queries such as:
@ParthSareen commented on GitHub (Apr 8, 2025):
Can't promise we'll support that just yet but will check it out!
@xuzexin-hz commented on GitHub (May 2, 2025):
I think this is not a problem with the framework. You can call the API directly as long as it complies with the OpenAI specification. The standard json should be Pydantic models, otherwise everyone's coding style will be very different.
@gruenbergera commented on GitHub (May 6, 2025):
I have to say that I have had some level of difficulty having models follow a pydantic schema's model_json_schema() as the output format (temperature set to 0). There are field descriptions as well. This is for unstructured to structured data purposes. Many of the fields have enum values that are not followed even if prompted to specifically select enum values.
I feel a bit silly as a programmer telling a black box to do something, but, we're experimenting. I have been using instruct models of around 12B, but the responses tend to make up field names not in the schema, and for the enum fields, they ignore that aspect and elect to use their own value-- however more correct it might be (albeit verbose).
Whereas when using structured output on proprietary models, it's generally flawless. Again, I'm not sure what level the expectations should be in this regard.
To the question of this "issue" it's entirely possible to use Pydantic or JSON (in openAPI format) to use enums.
I have not seen a lot of chatter about structured output shortcomings, though.