Skip to main content
Guaranteed JSON output — critical for form digitization, KYC extraction, and data parsing.

JSON schema mode

Returns JSON that conforms to a specific schema you define. Best for production pipelines where downstream consumers expect a fixed structure.
response = client.chat.completions.create(
    model="forii/deepseek-v3",
    messages=[{
        "role": "user",
        "content": "Extract: राहुल शर्मा, उम्र 34, मुंबई"
    }],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "person",
            "schema": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
                    "age": {"type": "integer"},
                    "city": {"type": "string"}
                },
                "required": ["name", "age", "city"]
            }
        }
    }
)

print(response.choices[0].message.content)
# {"name": "राहुल शर्मा", "age": 34, "city": "मुंबई"}

Response

{
  "id": "chatcmpl-forii-abc123",
  "object": "chat.completion",
  "model": "forii/deepseek-v3",
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "{\"name\": \"राहुल शर्मा\", \"age\": 34, \"city\": \"मुंबई\"}"
    },
    "finish_reason": "stop"
  }]
}
The json_schema mode guarantees the output matches your schema. If the model cannot produce valid JSON matching the schema, it will retry internally. Use this for production pipelines where downstream consumers expect a fixed structure.

JSON object mode

For arbitrary JSON without a specific schema. The model will return valid JSON, but the shape is not guaranteed.
response = client.chat.completions.create(
    model="forii/deepseek-v3",
    messages=[{"role": "user", "content": "List 3 Indian cities with population"}],
    response_format={"type": "json_object"}
)

print(response.choices[0].message.content)
With json_object mode, you must include “JSON” or “json” in the system or user message, otherwise the request will fail. The model decides the output shape — use json_schema mode when you need a guaranteed structure.

Parameters

ParameterTypeDescription
response_format.typestring"json_object" or "json_schema"
response_format.json_schema.namestringSchema name (required for json_schema mode)
response_format.json_schema.schemaobjectJSON Schema definition (required for json_schema mode)