response_format. The most
common surprise is that a model silently ignores it. See
Structured Output for the full guide.
I get plain text instead of JSON (no error)
Not every model enforcesresponse_format. On many models that don’t
support it, the request still succeeds and returns ordinary text. It does
not error. On Amazon Bedrock, response_format is also dropped when the request
carries tools.
- Switch to a model with first-class support, e.g. OpenAI models or
google/gemini-2.5-flash. - Always parse defensively and handle the case where the content isn’t valid JSON.
4xx response_format rejected
Mesh forwardsresponse_format without validating its contents, so a bad one is
rejected by the provider (usually 400), not by Mesh. Only a response_format
that isn’t a JSON object gets a 422 from Mesh. Check:
typeis one of"text","json_object","json_schema".- For
json_schema, thejson_schemaobject has both anameand aschema. - The
schemais valid JSON Schema (no trailing commas, correct types). - The model supports
json_schema. DeepSeek, Arcee and ILMU accept onlyjson_object.
Valid JSON but the wrong keys
json_object only guarantees syntactically valid JSON — not which keys
appear. The structure follows your prompt, not a contract.
- Describe the exact keys you expect in the prompt, or
- Use
json_schemafor a guaranteed shape. SetadditionalProperties: falseto forbid extra fields, and list every required field inrequired.
JSON is truncated / won’t parse
If the output is cut off mid-object,max_tokens was too low — the model ran
out of room before closing the JSON.
- Raise
max_tokens. - Check
finish_reason:"length"means truncated,"stop"means complete.
content is a string, not an object
The JSON is returned as a string inchoices[0].message.content. You must
parse it yourself:
Output isn’t deterministic across runs
Sampling introduces variation even with a schema.- Set
temperature: 0for the most deterministic, schema-faithful output. - Note that for Gemini models,
response_formatis translated server-side to Gemini’s nativeresponseMimeType/responseSchema, so enforcement happens on the provider — behavior can differ subtly from OpenAI.