Skip to content
All docs

Guides

JSON output

Ask DeepSeek for JSON with response_format and describe the shape you want in the prompt. Always parse the reply and check it before you trust it.

Checked 26 October 2026

Ask for JSON

Python
import json
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://nokeep.ai/v1",
    api_key=os.environ["NOKEEP_API_KEY"],
)

reply = client.chat.completions.create(
    model="deepseek-v4.1-flash-uncensored",
    response_format={"type": "json_object"},
    messages=[
        {"role": "system", "content": 'Answer as JSON: {"title": string, "tags": string[]}'},
        {"role": "user", "content": "A short story about a lighthouse keeper's last night."},
    ],
)
data = json.loads(reply.choices[0].message.content)
print(data["title"], data["tags"])

response_format reaches DeepSeek as you send it, including json_schema. Describe the shape in the prompt as well: it is what the model reads.

With GLM

glm-5.3-flash-uncensored doesn’t take response_format; it is dropped and named in x-nokeep-ignored. Ask for JSON in the system message, and parse the reply the same way.

Check what comes back

  • Parse with json.loads or JSON.parse inside a try, and retry once on a parse error.
  • Check the fields you need are there and have the right types. A schema validator such as Pydantic or Zod does this in one line.
  • Give the reply room: a max_tokens too small cuts the JSON off before it closes.