[GH-ISSUE #3328] /set format json does not appear to work over the API. #27807

Closed
opened 2026-04-22 05:24:13 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @phalexo on GitHub (Mar 24, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/3328

What is the issue?

I would like to set JSON mode, via the API or in the model file. I tried to insert the command right after the system prompt in the template,

didn't work.

Then I made it part of the system prompt.

didn't work.

What did you expect to see?

When "/set format json" appears anywhere, either in the system prompt, or as part of user query, I expect the mode to be changed to JSON, and the output be in JSON format.

Steps to reproduce

It is obvious. I cannot put it anywhere in the model file to make it change the mode.

Are there any recent changes that introduced the issue?

no.

OS

Linux

Architecture

amd64

Platform

Docker

Ollama version

No response

GPU

No response

GPU info

No response

CPU

No response

Other software

No response

Originally created by @phalexo on GitHub (Mar 24, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/3328 ### What is the issue? I would like to set JSON mode, via the API or in the model file. I tried to insert the command right after the system prompt in the template, didn't work. Then I made it part of the system prompt. didn't work. ### What did you expect to see? When "/set format json" appears anywhere, either in the system prompt, or as part of user query, I expect the mode to be changed to JSON, and the output be in JSON format. ### Steps to reproduce It is obvious. I cannot put it anywhere in the model file to make it change the mode. ### Are there any recent changes that introduced the issue? no. ### OS Linux ### Architecture amd64 ### Platform Docker ### Ollama version _No response_ ### GPU _No response_ ### GPU info _No response_ ### CPU _No response_ ### Other software _No response_
GiteaMirror added the bug label 2026-04-22 05:24:13 -05:00
Author
Owner

@mxyng commented on GitHub (Mar 27, 2024):

/set commands in the CLI are not sent to ollama but instead mutate the active session. Therefore /set format json as a message in the API will not work. Instead, the API takes a format field you can set to json, e.g.

curl localhost:11434/api/generate -d '{"model":"mistral","prompt":"say hello in a format of {\"message\": \"response\"}","format":"json","stream":false}'
<!-- gh-comment-id:2024104574 --> @mxyng commented on GitHub (Mar 27, 2024): `/set` commands in the CLI are not sent to ollama but instead mutate the active session. Therefore `/set format json` as a message in the API will not work. Instead, the API takes a `format` field you can set to `json`, e.g. ``` curl localhost:11434/api/generate -d '{"model":"mistral","prompt":"say hello in a format of {\"message\": \"response\"}","format":"json","stream":false}' ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#27807