[GH-ISSUE #14734] docs: ZodToJsonSchema library is deprecated #9529

Closed
opened 2026-04-12 22:27:05 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @wahyusttrn on GitHub (Mar 9, 2026).
Original GitHub issue: https://github.com/ollama/ollama/issues/14734

What is the issue?

*Update for JavaScript user who's trying to integrate Ollama in their applications.

As of November 2025, "ZodToJsonSchema" library is no longer being maintained. Zod v4 natively supports JSON schema. These are written in their official documentation:

ZodToJsonSchema: https://www.npmjs.com/package/zod-to-json-schema
(Official) Zod's JSON Schema: https://zod.dev/json-schema

That being said, the structured outputs from line 101-120 (for JavaScript) should be updated. This is what came to my mind:

    import ollama from 'ollama'
    import * as z from "zod"    

    const Country = z.object({
      name: z.string(),
      capital: z.string(),
      languages: z.array(z.string()),
    })

    const response = await ollama.chat({
      model: 'gpt-oss',
      messages: [{ role: 'user', content: 'Tell me about Canada.' }],
      format: z.toJSONSchema(Country),
    })

    const country = Country.parse(JSON.parse(response.message.content))
    console.log(country)

Relevant log output


OS

MacOS Tahoe

GPU

CPU

Apple M3

Ollama version

0.17.7

Originally created by @wahyusttrn on GitHub (Mar 9, 2026). Original GitHub issue: https://github.com/ollama/ollama/issues/14734 ### What is the issue? *Update for **JavaScript** user who's trying to integrate Ollama in their applications. As of November 2025, "ZodToJsonSchema" library is **no longer being maintained**. Zod v4 natively supports JSON schema. These are written in their official documentation: ZodToJsonSchema: https://www.npmjs.com/package/zod-to-json-schema (Official) Zod's JSON Schema: https://zod.dev/json-schema That being said, the [structured outputs](https://github.com/ollama/ollama/blob/main/docs/capabilities/structured-outputs.mdx) from line 101-120 (for JavaScript) should be updated. This is what came to my mind: ```javascript import ollama from 'ollama' import * as z from "zod" const Country = z.object({ name: z.string(), capital: z.string(), languages: z.array(z.string()), }) const response = await ollama.chat({ model: 'gpt-oss', messages: [{ role: 'user', content: 'Tell me about Canada.' }], format: z.toJSONSchema(Country), }) const country = Country.parse(JSON.parse(response.message.content)) console.log(country) ``` ### Relevant log output ```shell ``` ### OS MacOS Tahoe ### GPU - ### CPU Apple M3 ### Ollama version 0.17.7
GiteaMirror added the bug label 2026-04-12 22:27:05 -05:00
Author
Owner

@mvanhorn commented on GitHub (Mar 9, 2026):

I've submitted a fix in the PR above. Updated the structured outputs example to use Zod v4's native z.toJSONSchema() instead of the deprecated zod-to-json-schema library.

<!-- gh-comment-id:4024395235 --> @mvanhorn commented on GitHub (Mar 9, 2026): I've submitted a fix in the PR above. Updated the structured outputs example to use Zod v4's native `z.toJSONSchema()` instead of the deprecated `zod-to-json-schema` library.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#9529