[GH-ISSUE #12726] JSON Schema with pattern not working #8444

Open
opened 2026-04-12 21:07:34 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @Christian24 on GitHub (Oct 21, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/12726

Originally assigned to: @ParthSareen on GitHub.

What is the issue?

Hi,

I am using the Ollama TypeScript library with a zod schema that I convert to a JSON schema.
I am using z.string().startsWith("K") which leads to my JSON schema having a pattern key like so:

 properties: {
    kundennummer: {
      description: "Eine Kundennummer gehört zu genau einem Kunden",
      type: "string",
      pattern: "^K.*"
    },

As soon as I remove startsWith, the pattern is removed and my code executes fine.

Relevant log output

error: Uncaught (in promise) ResponseError: invalid JSON schema in format
    at checkOk (file:///Users/sec/Documents/work/ollama-blog/node_modules/.pnpm/ollama@0.6.0/node_modules/ollama/dist/browser.mjs:73:9)
    at eventLoopTick (ext:core/01_core.js:179:7)
    at async post (file:///Users/sec/Documents/work/ollama-blog/node_modules/.pnpm/ollama@0.6.0/node_modules/ollama/dist/browser.mjs:156:3)
    at async Ollama.processStreamableRequest (file:///Users/sec/Documents/work/ollama-blog/node_modules/.pnpm/ollama@0.6.0/node_modules/ollama/dist/browser.mjs:296:22)
    at async file:///Users/sec/Documents/work/ollama-blog/brief.ts:36:18
 ELIFECYCLE  Command failed with exit code 1.

OS

macOS

GPU

Apple

CPU

Apple

Ollama version

0.12.6

Originally created by @Christian24 on GitHub (Oct 21, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/12726 Originally assigned to: @ParthSareen on GitHub. ### What is the issue? Hi, I am using the Ollama TypeScript library with a zod schema that I convert to a JSON schema. I am using `z.string().startsWith("K")` which leads to my JSON schema having a `pattern` key like so: ```json properties: { kundennummer: { description: "Eine Kundennummer gehört zu genau einem Kunden", type: "string", pattern: "^K.*" }, ``` As soon as I remove `startsWith`, the `pattern` is removed and my code executes fine. ### Relevant log output ```shell error: Uncaught (in promise) ResponseError: invalid JSON schema in format at checkOk (file:///Users/sec/Documents/work/ollama-blog/node_modules/.pnpm/ollama@0.6.0/node_modules/ollama/dist/browser.mjs:73:9) at eventLoopTick (ext:core/01_core.js:179:7) at async post (file:///Users/sec/Documents/work/ollama-blog/node_modules/.pnpm/ollama@0.6.0/node_modules/ollama/dist/browser.mjs:156:3) at async Ollama.processStreamableRequest (file:///Users/sec/Documents/work/ollama-blog/node_modules/.pnpm/ollama@0.6.0/node_modules/ollama/dist/browser.mjs:296:22) at async file:///Users/sec/Documents/work/ollama-blog/brief.ts:36:18  ELIFECYCLE  Command failed with exit code 1. ``` ### OS macOS ### GPU Apple ### CPU Apple ### Ollama version 0.12.6
GiteaMirror added the bug label 2026-04-12 21:07:34 -05:00
Author
Owner

@rick-github commented on GitHub (Oct 21, 2025):

The pattern needs to be fully anchored: pattern: "^K.*$".

<!-- gh-comment-id:3429451527 --> @rick-github commented on GitHub (Oct 21, 2025): The pattern needs to be fully anchored: `pattern: "^K.*$"`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#8444