Structured output
Malibu accepts OpenAI’sresponse_formatjson_schemaandjson_object, validated against your schema before success.
response_format on /v1/chat/completions:
How the guarantee works. The provider adds your schema to the system prompt to steer the model. After inference, it parses and validates the output before it returns success. This is validation, not constrained decoding: the model can still produce invalid output. When it does, you get a retryable error instead of bad JSON. See Failure modes.
It works on every catalog model and with both
stream: false and stream: true. Larger instruct models such as mlx-community/Qwen3.6-27B-4bit follow schemas more reliably than small ones. GET https://api.malibu.tech/v1/status lists the models that are serving right now.
JSON Schema (strict)
json_schema.nameis required and must match^[A-Za-z0-9_-]{1,64}$.json_schema.schemais required.json_schema.descriptionis optional. The model sees it as prompt text only.strictdefaults totrue.strict: falsereturns400 json_schema_non_strict_unsupported.
Supported schema subset
Malibu checks your schema before inference. Anything outside this subset returns400 with a json_schema_* error code. param is null on these errors.
Allowed keywords
type: one ofobject,array,string,number,integer,boolean,null. Required on every schema node.propertiesandrequired, onobjectnodes only.additionalProperties: false, required on everyobjectnode, nested ones included.items, required onarraynodes.enumandconst. Values must be JSON scalars that match the node’stype.minimum,maximum, andmultipleOf, onnumber/integernodes only.multipleOfmust be greater than 0.descriptionandtitle. The model sees these as prompt text. They don’t affect validation.$schema, at the top level only. It is ignored for validation.
- Every key in
propertiesmust also appear inrequired. Otherwise you get400 json_schema_strict_requires_all_properties_required. Optional fields have no special form. Make the field required and let the model return an empty value, such as"". - A missing
additionalProperties: falsereturns400 json_schema_strict_requires_additional_properties_false. - An
enumorconstvalue that doesn’t matchtypereturns400 json_schema_invalid_const_or_enum_type.
400 json_schema_unsupported_keyword): oneOf, anyOf, allOf, not, $ref, $defs, definitions, pattern, format, minLength, maxLength, minItems, maxItems, uniqueItems, exclusiveMinimum, exclusiveMaximum, if / then / else, default, examples, and any other keyword not listed above. Inline repeated sub-schemas instead of using $ref.
Caps
Pydantic and Zod generate schemas with
$ref, anyOf (for Optional), string formats, and length constraints. Flatten those before you send, or the request is rejected with 400.json_object: top-level JSON without a schema
json_object is enforced, not a hint. If the output isn’t valid JSON with an object or array at the top level, you get 502 malformed_json_response instead of prose. If your client relied on getting best-effort text back under json_object, switch to {"type": "text"}.
Streaming + structured output
Bothjson_schema and json_object work with stream: true. You receive normal delta.content chunks as the model generates. They are not constrained token by token. Malibu validates the full concatenated content once the stream finishes:
- Valid: the stream ends with
data: [DONE]as usual. - Invalid: the stream ends with a terminal
data: {"error": …}event (malformed_json_responseorjson_schema_validation_failed), followed bydata: [DONE].
provider_timeout. On the stable provider release, a structured request that produces no content within 60 seconds also ends with 504 provider_timeout.
Tools and structured output together
When a request has bothtools and response_format, a valid tool call takes precedence. You get a normal tool_calls[] response, and the tool’s own parameters schema governs its arguments, not response_format. If the model answers without calling a tool, the content must satisfy response_format.
Failure modes
Every error body includes
retryable, so your client can decide whether to retry. If validation fails often, simplify the schema, raise max_tokens so the JSON isn’t cut off, or state the format in your own system prompt as well.
Malibu checks syntax and schema conformance only. Whether the values are safe to store or act on is still your call. See Buyer-side validation.