Structured Outputs

Generate JSON that matches your exact schema — every time. 100% guaranteed schema compliance with automatic validation.

Why Structured Outputs?

100% Compliance

Outputs always match your schema — no more parsing errors

No Post-Processing

Eliminate regex, retry logic, and validation code

🔧

Type Safety

Generate data that integrates directly with your code

Before vs After

❌ Without Structured Outputs

Hope the model returns valid JSON:

  • Parse errors at runtime
  • Missing required fields
  • Wrong data types
  • Retry logic needed
  • Complex validation code
✓ With Structured Outputs

Guaranteed valid JSON every time:

  • Schema-compliant output
  • All required fields present
  • Correct data types
  • No retry needed
  • Direct integration

Quick Start

Define your schema using JSON Schema and pass it to the API:

Python
from mythicdot import MythicDot client = MythicDot() response = client.chat.completions.create( model="mythic-4", messages=[ {"role": "user", "content": "Extract info: John is 30, works at Acme Inc as an engineer"} ], response_format={ "type": "json_schema", "json_schema": { "name": "person", "schema": { "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "integer"}, "company": {"type": "string"}, "role": {"type": "string"} }, "required": ["name", "age", "company", "role"] } } } ) # Output is guaranteed to match schema person = response.choices[0].message.parsed print(person.name) # "John" print(person.age) # 30

Schema Example

Person Schema

name string Full name of the person required
age integer Age in years required
company string Current employer required
role string Job title or position required
email string | null Email address if provided

Use Cases

📝 Data Extraction

Extract structured information from documents, emails, or any text into a consistent format.

🗃️ Database Population

Generate records that match your database schema exactly, ready for insertion.

🔄 API Responses

Build APIs that return consistent, typed responses from AI-generated content.

📊 Form Generation

Create form data, configuration files, or any structured content automatically.

Supported Types

Type Description Example
string Text values "Hello"
integer Whole numbers 42
number Floating-point 3.14
boolean True/false true
array Ordered lists ["a", "b"]
object Nested structures {"key": "value"}
enum Fixed set of values "draft" | "published"

💡 Pro Tip: Use Enums for Constrained Values

When you need the model to output only specific values (like status codes, categories, or ratings), use the enum type to guarantee valid outputs.

Start Building

Try structured outputs with your first API call.

Get Started →