ollama - ✅(Solved) Fix docs: ZodToJsonSchema library is deprecated [2 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
ollama/ollama#14734Fetched 2026-04-08 00:32:19
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Participants
Timeline (top)
cross-referenced ×2closed ×1commented ×1labeled ×1

Fix Action

Fixed

PR fix notes

PR #14735: docs: replace deprecated zod-to-json-schema with Zod v4 native

Description (problem / solution / changelog)

Fixes #14734

Summary

  • Replaced deprecated zod-to-json-schema library with Zod v4's native z.toJSONSchema() method in the structured outputs documentation
  • Updated import from import { z } from 'zod' to import { z } from 'zod/v4'
  • The zod-to-json-schema package is deprecated as Zod v4 includes built-in JSON Schema support

This contribution was developed with AI assistance (Claude Code).

Changed files

  • docs/capabilities/structured-outputs.mdx (modified, +3/-4)

PR #14746: docs: update Zod example to use native toJSONSchema

Description (problem / solution / changelog)

Summary

Updates the JavaScript structured outputs example to use Zod v4's native z.toJSONSchema() method instead of the deprecated zod-to-json-schema library.

Changes

  • Updated import to use import * as z from "zod"
  • Changed zodToJsonSchema(Country) to z.toJSONSchema(Country)
  • Removed deprecated zod-to-json-schema import

Testing

  • Verified the syntax is correct for Zod v4
  • Documentation change only, no code changes required

Fixes ollama/ollama#14734

Changed files

  • docs/capabilities/structured-outputs.mdx (modified, +3/-4)

Code Example

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)

---
RAW_BUFFERClick to expand / collapse

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

extent analysis

Fix Plan

To fix the issue, we need to update the code to use Zod's native JSON schema support.

Step-by-Step Solution

  1. Remove the ZodToJsonSchema library: Remove the zod-to-json-schema package from your project.
  2. Update the import statement: Import Zod's toJSONSchema function from the zod package.
  3. Update the format option: Use the toJSONSchema function to generate the JSON schema for the Country object.

Example Code

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);

Verification

To verify that the fix worked, run the updated code and check that the country object is parsed correctly from the response.

Extra Tips

  • Make sure to update your Zod version to the latest version that supports native JSON schema generation.
  • If you encounter any issues, check the Zod documentation for the latest information on JSON schema generation.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

ollama - ✅(Solved) Fix docs: ZodToJsonSchema library is deprecated [2 pull requests, 1 comments, 2 participants]