Skip to content

Docs

Structured output

Force a model's response to match a JSON schema — guaranteed-shape output for code that has to parse it.

When your code needs to parse a model’s answer, you don’t want prose — you want JSON that matches a known shape every time. Bedrova supports OpenAI-style structured output: you pass a JSON schema, and generation is constrained to produce conforming JSON.

The request

Set response_format to a json_schema on any chat completion:

curl http://127.0.0.1:1337/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "qwen35-7b-4bit",
    "messages": [{"role": "user", "content": "Extract the person from: Ada Lovelace, born 1815, London."}],
    "response_format": {
      "type": "json_schema",
      "json_schema": {
        "name": "person",
        "schema": {
          "type": "object",
          "properties": {
            "name": {"type": "string"},
            "born": {"type": "integer"},
            "city": {"type": "string"}
          },
          "required": ["name", "born", "city"],
          "additionalProperties": false
        }
      }
    }
  }'

The response content is JSON that satisfies the schema:

{ "name": "Ada Lovelace", "born": 1815, "city": "London" }

How it works

Generation is constrained as it decodes, so tokens that would break the schema are never produced — this is stronger than asking the model nicely and hoping. It works the same in the app’s chat view (turn on structured output in the model’s profile) and over the API.

Writing schemas that behave

  • Set additionalProperties: false and list required fields — it keeps the model from inventing keys.
  • Prefer flat, named fields over deeply nested or recursive schemas; very deep schemas cost more and constrain harder.
  • Describe enums explicitly ("enum": [...]) when you want a fixed set of values.
  • Keep prompts and schemas consistent — if the prompt implies a field the schema forbids, the model is forced toward the schema.

Limits

  • Structured output applies to chat/responses text generation, not to image or audio endpoints.
  • Constrained decoding can slow generation slightly versus free text, and extremely large or recursive schemas more so.
  • Tool calling is a related-but-separate mechanism — see Tool calling & MCP.

See also