Skip to main content

Structured Outputs

GoingMerry supports enforcing structured JSON output formats. By passing a JSON Schema, you can guarantee that the model's completion response conforms to a specific data format.


1. Using JSON Schemas

To request structured output, pass the schema in the format parameter of the /api/chat or /api/generate request.

curl Example

curl -X POST http://localhost:11434/api/generate -H "Content-Type: application/json" -d '{
"model": "gemma4",
"prompt": "Tell me about a fictional solar system. Respond using JSON.",
"stream": false,
"format": {
"type": "object",
"properties": {
"name": { "type": "string" },
"planets_count": { "type": "integer" },
"has_life": { "type": "boolean" },
"stars": {
"type": "array",
"items": { "type": "string" }
}
},
"required": ["name", "planets_count", "has_life", "stars"]
}
}'

2. JSON Mode

If you do not require a strict schema but want the output to be a valid JSON object, set the format parameter to "json":

curl Example

curl http://localhost:11434/api/generate -d '{
"model": "gemma4",
"prompt": "List the top 3 programming languages in 2026. Respond using JSON.",
"format": "json",
"stream": false
}'
important

When using JSON mode or JSON schemas, always instruct the model to output JSON in your prompt as well. If omitted, the model might experience logic loops or generate leading/trailing whitespace.