Skip to content
API referenceStructured outputs

Structured outputs

JSON, schemas, and output validation: support depends on the model and API.

Model protocol

Messages: JSON Schema

In Claude /v1/messages, output_config.format constrains the final response text to a JSON Schema. Find the type: "text" block in content and parse its text as JSON: the first block may contain thinking.

json
{
  "model": "claude-opus-5",
  "max_tokens": 1024,
  "messages": [{"role": "user", "content": "Extract the name and age: Anna, 29"}],
  "output_config": {
    "format": {
      "type": "json_schema",
      "schema": {
        "type": "object",
        "properties": {
          "name": {"type": "string"},
          "age": {"type": "integer"}
        },
        "required": ["name", "age"],
        "additionalProperties": false
      }
    }
  }
json
{"name":"Anna","age":29}

Chat Completions: response_format

json
{
  "model": "claude-opus-5",
  "messages": [{"role": "user", "content": "Extract the name and age: Anna, age 29"}],
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "person",
      "strict": true,
      "schema": {
        "type": "object",
        "properties": {
          "name": {"type": "string"},
          "age": {"type": "integer"}
        },
        "required": ["name", "age"],
        "additionalProperties": false
      }
    }

Kimi, Composer and Grok

  • Kimi. The response_format field is accepted on /v1/chat/completions and passed to the model as it is. Guard does not inject a schema of its own and does not validate the answer against yours, so parse the result on your side and handle the case where no JSON came back.
  • Composer and Grok. They have no response_format field: a request carrying it gets 400 cursor_parameter_unavailable before any charge. Ask for the format in the request text and check the answer on your side.

Structured GLM output

Guard does not currently declare a separate strict JSON Schema guarantee for GLM. Do not copy response_format or schema fields from another family without your own verification.

The confirmed way to receive typed data is a client tool with JSON Schema: the model returns function arguments, and the application validates them before execution.

json
{
  "type": "function",
  "function": {
    "name": "save_invoice",
    "description": "Save a validated invoice",
    "parameters": {
      "type": "object",
      "properties": {
        "code": {"type": "string"},
        "amount": {"type": "number"}
      },
      "required": ["code", "amount"]
    }
  }
}
  1. Describe the function and schema in the native shape for the selected API.
  2. Receive the tool call and parse its arguments as JSON.
  3. Validate the schema in your application; model output is not a validation boundary.
  4. Execute the action only after validation, then return the tool result.

See Client tools for the full roundtrip and ID-preservation rules.

Structured Gemini output

Gemini returns JSON that follows a schema in all three APIs. Chat Completions uses response_format with type: "json_object" or type: "json_schema" and the schema in json_schema.schema; Responses uses text.format of the same form; Messages uses output_config.format. Google applies the schema.

Gemini does not accept the strict function mode strict: true: the request gets the error gemini_strict_tools_unsupported.

Structured Muse output

Guard passes the structured output fields to Meta unchanged: response_format in Chat Completions and text.format in Responses. The JSON schema mode is described in the Meta Model API documentation.

Sections

On this page