Strict JSON output with the ModelFold OpenAI Responses API
Author note: I work on ModelFold.
When an application needs data rather than prose, asking a model to return JSON is not enough. A JSON Schema defines the fields and types your code expects. ModelFold supports strict schema output on its OpenAI-compatible Responses endpoint.
Send a schema with the request
This example asks for a boolean and an integer, and rejects extra properties:
curl https://modelfold.ai/openai/v1/responses \
-H "Authorization: Bearer $MODEL_FOLD_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-2-sol",
"input": [{"role":"user","content":"Return a JSON object with ok true and count 3."}],
"text": {"format": {
"type": "json_schema",
"name": "sample",
"strict": true,
"schema": {
"type": "object",
"properties": {"ok": {"type":"boolean"}, "count": {"type":"integer"}},
"required": ["ok", "count"],
"additionalProperties": false
}
}}
}'
I sent this request and received HTTP 200. The exact output_text value returned was:
{"ok":true,"count":3}
Parse that value as JSON and validate it against the same schema before using it. Structured output constrains the shape; your application still needs to handle refusal, incomplete, and error states, and to check whether the values make sense for your use case.
The Chat Completions equivalent
Chat Completions puts the schema under response_format:
{
"model": "gpt-6-2-sol",
"messages": [{"role":"user","content":"Return a JSON object with ok true and count 3."}],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "sample",
"strict": true,
"schema": {
"type": "object",
"properties": {"ok": {"type":"boolean"}, "count": {"type":"integer"}},
"required": ["ok", "count"],
"additionalProperties": false
}
}
}
}
Both requests use https://modelfold.ai/openai/v1. Responses puts the format in text.format; Chat Completions puts it in response_format.json_schema. Keep the schema small and version it with the code that consumes the result.
For a broader overview of ModelFold, visit modelfold.ai.
Top comments (0)