[GH-ISSUE #8796] BUG: Deserialization for JSON Schema is incorrect #52223

Closed
opened 2026-04-28 22:33:39 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @ssddOnTop on GitHub (Feb 3, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/8796

Originally assigned to: @ParthSareen on GitHub.

What is the issue?

I was trying to use /v1 route where req/response is OpenAI compatible

In ad22ace439/api/types.go (L170)

Type is of type string, however, according to https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-02 it could be a string or an array of strings

OS

No response

GPU

No response

CPU

No response

Ollama version

0.5.7

Originally created by @ssddOnTop on GitHub (Feb 3, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/8796 Originally assigned to: @ParthSareen on GitHub. ### What is the issue? I was trying to use `/v1` route where req/response is [OpenAI compatible](https://github.com/ollama/ollama/blob/main/docs/openai.md) In https://github.com/ollama/ollama/blob/ad22ace439eb3fab7230134e56bb6276a78347e4/api/types.go#L170 `Type` is of type string, however, according to https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-02 it could be a string or an array of strings ### OS _No response_ ### GPU _No response_ ### CPU _No response_ ### Ollama version 0.5.7
GiteaMirror added the bug label 2026-04-28 22:33:39 -05:00
Author
Owner

@ParthSareen commented on GitHub (Feb 7, 2025):

Was this blocking for use with a specific schema? Could you provide the schema you were using.

<!-- gh-comment-id:2644147137 --> @ParthSareen commented on GitHub (Feb 7, 2025): Was this blocking for use with a specific schema? Could you provide the schema you were using.
Author
Owner

@ssddOnTop commented on GitHub (Feb 7, 2025):

I was using schemars crate to generate JSON schema for structs.

However if I had an Optional field in a struct like:

struct Foo {
  bar: Option<String>,
}

the crate generated a schema in which the Parameters' Type field is an array ["string", "null"] which is compatible with OpenRouter and handrews-json-schema-02 but Ollama only supports string for now.

<!-- gh-comment-id:2644321322 --> @ssddOnTop commented on GitHub (Feb 7, 2025): I was using [schemars](https://github.com/GREsau/schemars) crate to generate JSON schema for structs. However if I had an Optional field in a struct like: ```rs struct Foo { bar: Option<String>, } ``` the crate generated a schema in which the `Parameters'` `Type` field is an array `["string", "null"]` which is compatible with [OpenRouter](https://openrouter.ai/) and [handrews-json-schema-02](https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-02) but Ollama only supports string for now.
Author
Owner

@ParthSareen commented on GitHub (Feb 7, 2025):

@ssddOnTop From my understanding that's not an official spec. Optional values tend to be defined with an anyOf for JSON. If you do find docs differing this please let me know.

<!-- gh-comment-id:2644336135 --> @ParthSareen commented on GitHub (Feb 7, 2025): @ssddOnTop From my understanding that's not an official spec. Optional values tend to be defined with an `anyOf` for JSON. If you do find docs differing this please let me know.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#52223