Skip to main content
Structured outputs give you machine-readable JSON directly from a model rather than freeform prose that you must parse yourself. This is particularly useful for data extraction pipelines, classification tasks, form filling, automated scoring, and any workflow where downstream code needs to consume the model’s output programmatically. Meliai supports two levels of structure enforcement through the response_format parameter: a permissive JSON mode that guarantees valid JSON, and a strict schema mode that validates against a JSON Schema you supply.

JSON Mode

Set response_format to {"type": "json_object"} to instruct the model to always respond with a valid JSON object. You are responsible for describing the expected shape in your system or user prompt — JSON mode only guarantees syntactic validity, not a particular structure.
Python
Always include a clear instruction in the system or user message that specifies the expected keys. Without guidance, the model will produce valid JSON but the structure may vary between calls.

JSON Schema Mode

Set response_format to {"type": "json_schema", "json_schema": {...}} to enforce a precise structure. The json_schema object requires a name, an optional strict flag, and a schema that follows the JSON Schema specification. When strict: true, the model is constrained to produce output that exactly matches the schema with no extra properties.
Python
Setting "additionalProperties": False alongside "strict": True gives the strongest guarantee: the output will contain exactly the fields you declared and nothing else.

Choosing Between the Two Modes

Best for: exploratory extraction, prompts where the schema may vary, or models that do not support strict JSON schema.
  • Guarantees syntactically valid JSON
  • Schema is described in natural language in the prompt
  • Supported by a wider range of models
Not all models support strict JSON schema mode. Retrieve model metadata from GET /v1/models/<MODEL_ID> and check the supported_parameters array for "response_format" before using json_schema in production. Models that do not support it will fall back to best-effort JSON or return an error, depending on the model.