Skip to content

Structured output (JSON mode)#

To guarantee JSON-parseable output:

resp = client.chat.completions.create(
    model="siati/mistral-small-24b",
    messages=[
        {"role": "system", "content":
         "Return ONLY a valid JSON object."},
        {"role": "user", "content":
         "Extract name, amount, date from: 'Invoice 2026-001 from SIATI to "
         "Bank XYZ, 1500 CHF, May 3 2026'"},
    ],
    response_format={"type": "json_object"},
)
import json
data = json.loads(resp.choices[0].message.content)
print(data)
# {'invoice_number': '2026-001', 'sender': 'SIATI', ...}

Combine with an explicit system prompt about the expected schema. For strict-schema validation, parse with Pydantic or a JSON Schema validator on your side.