Developer Tool

JSON to Structured Output Schema for OpenAI, Claude & Gemini

Convert example JSON into strict LLM schemas, Pydantic v2, Zod & TypeScript. Runs in your browser. Nothing is uploaded.
Automatic Format Detection Reset

Sample JSON

2 samples

Drop JSON File Here

Instant local parsing in your browser

strict: true Enforces additionalProperties: false on all object hierarchies
Schema Field Customization

Add property descriptions (guides model reasoning), define enum sets, or change required status. Changes propagate to all tabs instantly.

// Generating schema...
Validate LLM Completion Against Active Schema

Paste an actual model completion below to test type validity, required keys, enum adherence, and strict mode compliance.

Click "Run Conformance Check" to evaluate JSON paths and types.

How to Use the JSON to LLM Schema Generator

Modern Large Language Model (LLM) APIs support constrained grammar decoders that mathematically guarantee the output conforms to a strict JSON Schema without missing properties, invalid data types, or hallucinated fields. Follow these steps to generate production-ready schemas in seconds:

01

Paste JSON Examples

Paste one or more representative JSON objects into the editor. If certain fields are optional or have alternating types, separate multiple sample objects with a line containing ---.

02

Inspect & Annotate

Click "Edit Fields" to provide descriptions for the model. Semantic field descriptions dramatically boost extraction precision during complex agentic workflows.

03

Select Provider Target

Switch tabs between OpenAI strict mode, Anthropic Claude tool calling, Google Gemini responseSchema, Pydantic v2 models, Zod schemas, or TypeScript interfaces.

04

Validate Real Outputs

Use the built-in "Test LLM Output" panel to paste real completions from your LLM prompt and verify 100% adherence to all type and enum boundaries.

Example: From Raw JSON to OpenAI Strict Schema

Notice how our deterministic compiler handles strict constraints: additionalProperties is locked to false at all object depths, all keys are registered in the required array, and optional keys (like discountCode) are converted into safe nullable unions.

Input Sample (JSON)
{
  "orderId": "ord_8829104",
  "status": "delivered",
  "totalAmount": 9.00,
  "discountCode": null
}
OpenAI Strict Output (response_format)
{
  "type": "json_schema",
  "json_schema": {
    "name": "OrderPayload",
    "strict": true,
    "schema": {
      "type": "object",
      "properties": {
        "orderId": { "type": "string" },
        "status": {
          "type": "string",
          "enum": ["delivered", "pending"]
        },
        "totalAmount": { "type": "number" },
        "discountCode": {
          "type": ["string", "null"]
        }
      },
      "required": ["orderId", "status", "totalAmount", "discountCode"],
      "additionalProperties": false
    }
  }
}

Explanation: Why Strict Structured Outputs Matter

When interacting with LLMs for production software, standard prompting strategies (such as "Please return valid JSON only") are inherently fragile. Even frontier models frequently output trailing commas, omit closing braces, hallucinate undocumented property names, or wrap responses in conversational markdown code fences like ```json.

Modern inference engines solve this using Constrained Grammar Sampling. During every token prediction step, the API converts your target schema into a Context-Free Grammar (CFG) or Finite State Automaton (FSA). Any token that would violate the schema syntax is given a probability of zero, ensuring that every completed token stream is mathematically guaranteed to parse without error.

However, each AI lab enforces its own strict subset of JSON Schema. OpenAI requires every property to be listed in required with additionalProperties: false. Google Gemini requires uppercase type descriptors like OBJECT and STRING without unsupported draft keywords. MafLabs automatically adapts your payload into the exact specification required by your provider of choice.

Common Problems with LLM Structured Outputs

Frequently Asked Questions

What is OpenAI strict mode?
OpenAI Strict Mode is a feature in OpenAI's API (specifically for GPT-4o and later models) that enforces strict compliance with a provided JSON Schema. When strict: true is passed in response_format, OpenAI compiles the schema into a formal Context-Free Grammar (CFG) at request time, mathematically guaranteeing that the completion will adhere 100% to your schema.
Why must every field be required in OpenAI strict mode?
OpenAI's grammar generator requires all properties to appear in the required array so the state machine can evaluate a deterministic branching path during token decoding. If a key is not in required, the state machine cannot evaluate deterministic transitions for missing properties. To represent an optional field in OpenAI strict mode, the property must remain in required, but typed as a union with "null" (e.g. type: ["string", "null"]).
How do I make a field optional?
There are two convenient methods: either supply multiple JSON samples separated by --- where the field is omitted from at least one sample (the engine automatically detects it as optional), or click the "Edit Fields" button on the output pane and uncheck the "Required" checkbox for that field.
Is my JSON uploaded to any server or remote service?
No. All parsing, schema inference, format detection, code serialization, and validation execute 100% locally inside your browser's JavaScript engine. No content, telemetry, or analytics ever leaves your computer. This tool works completely offline without network access.
Which LLM models support structured outputs?
OpenAI models including gpt-4o-2024-08-06, gpt-4o-mini, and later support native strict structured outputs. Anthropic Claude 3.5 Sonnet and Haiku support strict tool calling via input_schema. Google Gemini 1.5 Pro and Gemini 1.5 Flash support native responseSchema in their generation configurations.
Can I export directly to Pydantic v2 and TypeScript?
Yes! Select the "Pydantic v2", "Zod", or "TypeScript" tabs above the output panel. The generator outputs clean, idiomatic class definitions inheriting from BaseModel with Field(...) metadata, or recursive TypeScript interfaces with JSDoc comments.
How does format detection work?
The engine analyzes string values across all samples against standardized regular expressions for ISO 8601 timestamps (date-time), calendar dates (date), RFC 5322 emails, URIs, and UUIDs. When a recurring set of distinct strings is observed across samples, the engine automatically suggests them as an enum.

More Free Developer Tools by MafLabs