Guaranteed valid JSON
Structured output guarantees the model returns valid JSON. Set
Output:
Structured output is not supported in thinking mode. As a workaround, parse the thinking-mode output and fall back to a fast model for JSON repair.
response_format to {"type": "json_object"} and include the word "JSON" in your prompt.
- OpenAI compatible
- DashScope
For more reliable results, describe the expected fields, types, required/optional status, and provide examples in your prompt.
Thinking mode workaround
Structured output is not supported in thinking mode. As a workaround, parse the thinking-mode output and fall back to a fast model for JSON repair.
Python
Notes
- Supported models: Qwen3.6, Qwen3.5, Qwen3, Qwen3-Coder, Qwen2.5, and legacy (Plus/Max/Flash/Turbo) — non-thinking mode. Also works with vision models (qwen3-vl-plus, etc.) when passing images or video as described in Image and video understanding.
- Don't set
max_tokens: Truncated output produces invalid JSON that breaks downstream parsing. Use the default (model's maximum output limit). - Validate output: JSON Object mode guarantees valid JSON but not schema conformance. Validate with jsonschema (Python), Ajv (JavaScript), or Everit (Java) before passing to downstream systems.