How do I get guaranteed-shape JSON using a tool?
schema_tool = {"type": "function", "function": {
"name": "save_contact",
"description": "Save the contact details found in the text.",
"parameters": {"type": "object", "properties": {
"name": {"type": "string"}, "email": {"type": "string"}, "phone": {"type": "string"}},
"required": ["name"]}}}
r = client.chat.completions.create(
model="supercosmos-flash",
messages=[{"role": "user", "content": "Reach Sara at sara@example.com or 0100 000 0000."}],
tools=[schema_tool],
tool_choice={"type": "function", "function": {"name": "save_contact"}},
)
import json
print(json.loads(r.choices[0].message.tool_calls[0].function.arguments))
Still validate the JSON in your code: the schema guides the model, it doesn't replace validation.
Good to know#
- Each key has its own limit: 10, 30 (default), 60 or 120 requests per minute. Rate limits
- Every call shows in Console › Logs and Usage as Model API, with its price. See what you spent
- New accounts get $5 of free credit; top up from $1 to $800 per purchase in Console › Billing › Credits. Billing
Still need help?#
- General support: support@clatterlabs.com or team@clatterlabs.xyz
- Infrastructure questions, or permanent deletion of your data (your whole account or one service): infrastructure@clatterlabs.xyz
We usually reply within the first hour, and always within 24 hours. A full support team is with you.
Related articles
Still need help?
Tried the steps above and still stuck? Email us. We usually reply within the first hour, and always within 24 hours. A full support team is with you.
Infrastructure questions, or permanent deletion of your data
infrastructure@clatterlabs.xyzFor deleting your whole account or the data of one service.