Skip to main content
Structured output lets you constrain LLM responses to valid JSON that follows a specific format. This is useful when you need to parse model output programmatically — for example, extracting entities, generating API payloads, or building data pipelines.

Overview

Eden AI supports two modes of structured output through the response_format parameter:
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: set response_format to {"type": "json_object"} and instruct the model to return JSON in your prompt.
Example response:

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.
Example response:

Supported Providers

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_format set, some providers require the prompt to mention JSON output.
  • Use json_schema for critical parsing. When your downstream code depends on exact field names and types, json_schema mode is more reliable than json_object.
  • Set additionalProperties: false in your schema to prevent the model from adding extra fields.
  • Always parse the response. The content field is still a string — use json.loads() (Python) or JSON.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.

Next Steps

LLMs vs Expert Models

When to use structured LLM output vs Expert Model schemas