Structured Output
Hand a large model an information-extraction or structured-data generation task, and the raw reply frequently arrives with surplus text wrapped around the payload — stray json fence markers, for example. That surplus text is enough to break whatever parses the output downstream.
How to fix it
Structured output is switched on with response_format, a parameter that forces the model to emit nothing but a pure JSON string in a standard format.
Model support
GLM
- GLM-5.1
- GLM-5
- GLM-4.7
MiniMax
- MiniMax-M2.5
- MiniMax-M2.1
Enabling JSON mode
Set response_format in the request body to {"type": "json_object"} — that single field is the switch for JSON mode.
Worked examples
Python
import requests
url = "https://api.watt-cloud.com/v1/chat/completions"
payload = {
"model": "${MODEL_NAME}",
"messages": [
{
"role": "system",
"content": "Extract company full name, city, contact phone number as JSON. Keys: company_full_name, city, contact_phone. If info missing, set value to null."
},
{
"role": "user",
"content": "Global Cloud Solution Co., Ltd. is based in Singapore, no phone number provided."
}
],
"response_format": {
"type": "json_object"
}
}
headers = {
"Authorization": "Bearer ${API_KEY}",
"Content-Type": "application/json"
}
response = requests.request("POST", url, json=payload, headers=headers)
print(response.text)
curl
curl --location --request POST 'https://api.watt-cloud.com/v1/chat/completions' \
--header 'Authorization: Bearer ${API_KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "${MODEL_NAME}",
"messages": [
{
"role": "system",
"content": "Extract company full name, city, contact phone number as JSON. Keys: company_full_name, city, contact_phone. If info missing, set value to null."
},
{
"role": "user",
"content": "Global Cloud Solution Co., Ltd. is based in Singapore, no phone number provided."
}
],
"response_format": {
"type": "json_object"
}
}'
Result
{
"company_full_name": "Global Cloud Solution Co., Ltd.",
"city": "Singapore",
"contact_phone": null
}