Overview
Eden AI supports two modes of structured output through theresponse_format parameter:
| Mode | Description |
|---|---|
json_object | The model returns valid JSON. You guide the structure via your system prompt. |
json_schema | The model returns JSON that conforms to a specific JSON Schema you provide. |
When using
response_format, always include a system or user message that instructs the model to respond in JSON. Some providers require this instruction to be present.JSON Object Mode
The simplest approach: setresponse_format to {"type": "json_object"} and instruct the model to return JSON in your prompt.
JSON Schema Mode
For stricter control, provide a JSON Schema that the model’s response must conform to. This guarantees the output matches your expected structure.Supported Providers
| Provider | json_object | json_schema |
|---|---|---|
| OpenAI (GPT-4o, GPT-4 Turbo) | Yes | Yes |
| Anthropic (Claude 3.5+, Claude 4) | Yes | Yes |
| Google (Gemini 1.5+, Gemini 2.5) | Yes | Yes |
Provider support for structured output varies. If a provider does not support
json_schema, use json_object mode with a detailed system prompt describing the expected format.Best Practices
- Always include JSON instructions in your prompt. Even with
response_formatset, some providers require the prompt to mention JSON output. - Use
json_schemafor critical parsing. When your downstream code depends on exact field names and types,json_schemamode is more reliable thanjson_object. - Set
additionalProperties: falsein your schema to prevent the model from adding extra fields. - Always parse the response. The
contentfield is still a string — usejson.loads()(Python) orJSON.parse()(JavaScript) to convert it to a structured object. - Handle parsing errors gracefully. In rare cases, the model may return malformed JSON. Wrap your parsing in a try/catch block.