[GH-ISSUE #15595] Gemma 4 json output is fenced with markdown backticks #87640

Closed
opened 2026-05-10 06:11:46 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @CamJN on GitHub (Apr 15, 2026).
Original GitHub issue: https://github.com/ollama/ollama/issues/15595

Using ollama 0.20.7:

With the js library:

const response = await ollama.chat({
    model: "gemma4:e4b",
    stream: false,
    think: false,
    keep_alive: '24h',
    options: {
      temperature: 0.8,
    },
    format: JSON.stringify(z.toJSONSchema(InvoiceSchema)),
    messages: [
      { role: "system", content: t.my_message_string, },
      { role: "user", content: t.parse_template_string.replace('{context_str}', context), },
    ]
  });

The response.message.content is "```json\n{\n "json details": "elided"\n}\n```" which has erroneous ```json and ``` markers.

Originally posted by @CamJN in #15315

This is also true of gemma4:31b which as an additional problem doesn't follow the response schema.

Originally created by @CamJN on GitHub (Apr 15, 2026). Original GitHub issue: https://github.com/ollama/ollama/issues/15595 > Using ollama 0.20.7: > > With the js library: > ```javascript > const response = await ollama.chat({ > model: "gemma4:e4b", > stream: false, > think: false, > keep_alive: '24h', > options: { > temperature: 0.8, > }, > format: JSON.stringify(z.toJSONSchema(InvoiceSchema)), > messages: [ > { role: "system", content: t.my_message_string, }, > { role: "user", content: t.parse_template_string.replace('{context_str}', context), }, > ] > }); > ``` > > The `response.message.content` is <code>"\```json\n{\n "json details": "elided"\n}\n\```"</code> which has erroneous <code>\```json</code> and <code>\```</code> markers. _Originally posted by @CamJN in [#15315](https://github.com/ollama/ollama/issues/15315#issuecomment-4246914308)_ This is also true of gemma4:31b which as an additional problem doesn't follow the response schema.
Author
Owner

@rick-github commented on GitHub (Apr 15, 2026):

https://github.com/ollama/ollama/issues/15260

<!-- gh-comment-id:4248835577 --> @rick-github commented on GitHub (Apr 15, 2026): https://github.com/ollama/ollama/issues/15260
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#87640