Guarantee: Structured Outputs guarantees 100% schema compliance. Every response will match your defined schema exactly.

What are Structured Outputs?

Structured Outputs is a feature that ensures model responses always conform to a developer-supplied JSON Schema. Unlike JSON mode, which only guarantees valid JSON, Structured Outputs validates against your exact schema before returning a response.

Feature JSON Mode Structured Outputs
Outputs valid JSON Yes Yes
Schema enforcement No Yes
Type checking No Yes
Required fields guaranteed No Yes
Refusal handling No Yes
Supported models All chat models GlomaxGPT Pro and GlomaxGPT Ultra

How to enable

Set response_format to {"type": "json_schema", "json_schema": {...}} in your API request. Provide a name and a JSON Schema definition for the output you expect.

structured-outputs.py
from GlomaxGPT import GlomaxGPT

client = GlomaxGPT()

response = client.responses.create(
    model="glomaxgpt-ultra",
    input=[{
        "role": "user",
        "content": "Extract the event details from: 'Meeting on Friday at 3pm in Room 4B.'"
    }],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "calendar_event",
            "strict": True,
            "schema": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
                    "date": {"type": "string"},
                    "time": {"type": "string"},
                    "location": {"type": "string"}
                },
                "required": ["name", "date", "time", "location"],
                "additionalProperties": False
            }
        }
    }
)

import json
event = json.loads(response.output_text)
print(event)
structured-outputs.js
import GlomaxGPT from "GlomaxGPT";

const client = new GlomaxGPT();

const response = await client.responses.create({
  model: "glomaxgpt-ultra",
  input: [{
    role: "user",
    content: "Extract the event details from: 'Meeting on Friday at 3pm in Room 4B.'"
  }],
  response_format: {
    type: "json_schema",
    json_schema: {
      name: "calendar_event",
      strict: true,
      schema: {
        type: "object",
        properties: {
          name: { type: "string" },
          date: { type: "string" },
          time: { type: "string" },
          location: { type: "string" }
        },
        required: ["name", "date", "time", "location"],
        additionalProperties: false
      }
    }
  }
});

const event = JSON.parse(response.output_text);
console.log(event);

Defining your schema

Structured Outputs supports a subset of JSON Schema. Understanding what is and isn't supported helps you design schemas that work reliably.

Requirements: additionalProperties must be false. All fields listed in properties must also appear in required.

Supported types

  • string — plain text values
  • number — integers and floats
  • boolean — true / false
  • array — lists with typed items
  • object — nested objects
  • enum — fixed set of string values
  • anyOf — union types (nullable fields)

Unsupported features

  • $ref and recursive schemas
  • allOf, oneOf, not
  • if / then / else
  • minLength, maxLength, pattern
  • minimum, maximum
  • additionalProperties: true
  • Optional properties (all must be required)

Nullable fields with anyOf

Use anyOf with {"type": "null"} to make a field optional in value (but still required in structure).

nullable-field.json
{
  "type": "object",
  "properties": {
    "name": {"type": "string"},
    "nickname": {
      "anyOf": [
        {"type": "string"},
        {"type": "null"}
      ]
    }
  },
  "required": ["name", "nickname"],
  "additionalProperties": false
}

Using Pydantic (Python)

The Python SDK integrates with Pydantic models for a type-safe, ergonomic experience. Use client.responses.parse() to automatically validate and parse the response into your Pydantic model.

pydantic-parse.py
from GlomaxGPT import GlomaxGPT
from pydantic import BaseModel
from typing import Optional

client = GlomaxGPT()

class CalendarEvent(BaseModel):
    name: str
    date: str
    time: str
    location: str
    attendees: list[str]
    notes: Optional[str]

response = client.responses.parse(
    model="glomaxgpt-ultra",
    input=[{
        "role": "user",
        "content": "Team standup on Monday at 9am in the main office. Attendees: Alice, Bob."
    }],
    response_format=CalendarEvent
)

event = response.output_parsed
print(event.name)       # Team standup
print(event.date)       # Monday
print(event.attendees)  # ['Alice', 'Bob']

How it works

The SDK automatically converts your Pydantic model to a JSON Schema, sends it to the API with strict: true, and parses the JSON response back into a typed Pydantic instance. If parsing fails, an exception is raised rather than returning invalid data.

Refusal handling

Sometimes the model refuses to answer — for safety or content policy reasons. Structured Outputs surfaces refusals in a dedicated refusal field so you can handle them gracefully without breaking your schema parsing.

refusal-handling.py
response = client.responses.parse(
    model="glomaxgpt-ultra",
    input=[{"role": "user", "content": user_message}],
    response_format=CalendarEvent
)

message = response.output[0]

if message.refusal:
    # Model refused to answer — handle gracefully
    print(f"Refused: {message.refusal}")
else:
    event = message.parsed
    print(event.name)
refusal-handling.js
const response = await client.responses.parse({
  model: "glomaxgpt-ultra",
  input: [{ role: "user", content: userMessage }],
  response_format: CalendarEventSchema
});

const message = response.output[0];

if (message.refusal) {
  console.log(`Refused: ${message.refusal}`);
} else {
  const event = message.parsed;
  console.log(event.name);
}

Using Structured Outputs with function calling

Enable strict: true on your function definitions to apply Structured Outputs guarantees to function arguments. This combines the power of tool use with guaranteed schema compliance.

strict-function-calling.py
tools = [
    {
        "type": "function",
        "strict": True,  # Enable Structured Outputs for this tool
        "function": {
            "name": "create_event",
            "description": "Create a new calendar event.",
            "parameters": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
                    "date": {"type": "string"},
                    "time": {"type": "string"},
                    "location": {"type": "string"}
                },
                "required": ["name", "date", "time", "location"],
                "additionalProperties": False
            }
        }
    }
]

response = client.responses.create(
    model="glomaxgpt-ultra",
    input=[{"role": "user", "content": "Schedule a review meeting for tomorrow at 2pm."}],
    tools=tools
)
With strict: true

Guaranteed compliance

Arguments always match your schema. All required fields present. No unexpected keys. Safe to use without validation.

Without strict: true

Best effort

Arguments usually match but may occasionally deviate. Requires manual validation before use in production systems.