While LLMs typically return responses in plain text, this format can be challenging to parse when specific information is needed for programmatic use. Certain models on the Gravix Layer platform support structured JSON outputs, ensuring that responses are predictable and machine-readable. To enable structured responses, specify the desired format in the
response_format parameter of the Chat Completions API. Gravix Layer supports two modes:
- JSON Mode: Forces the model to output a syntactically correct JSON object without a predefined structure.
- JSON with Schema: Forces the model to output a JSON object that strictly conforms to a provided JSON Schema definition.
JSON Mode
This mode guarantees that the model will produce a valid, well-formed JSON object. It does not enforce a specific schema, providing flexibility while ensuring the output is machine-readable. To enable it, setresponse_format to {"type": "json_object"}.
Request
The following examples demonstrate how to generate a product catalog by enabling JSON mode in cURL, Python, and JavaScript.- cURL
- Python - OpenAI
- Python - Gravix SDK
- JavaScript
- JavaScript - Gravix SDK
Response
The API returns amessage containing a string of valid JSON.
JSON with Schema
For maximum reliability, you can provide a specific JSON Schema to constrain the model’s output. The model is forced to generate a JSON object that strictly adheres to the defined types, formats, and properties.- cURL
- Python - OpenAI
- Python - Gravix SDK
- JavaScript
- JavaScript - Gravix SDK

