JSON schema generator for LLM structured output
Updated
In short: To make an LLM return JSON in a fixed shape, send a JSON Schema as response_format with strict: true. Strict mode needs an object root, additionalProperties: false on every object and every key listed in required, with optional fields typed as a union with null. Paste sample JSON and this tool writes that schema, plus Pydantic, Zod and a request.
The strict-mode rules come from OpenAI's structured outputs guide (checked 2026-11-14). Other OpenAI-compatible servers implement structured output with their own decoders and may accept more or fewer keywords, so send one test request before you ship. The schema is inferred from one sample; check types such as integer vs number and which fields can be null.
Report a wrong price or number (email to info@broadnet.ai, with this page's link and your inputs filled in).
How it works
- Paste a sample of the JSON you want the model to return. If you paste an array of examples, tick "Top-level array is several examples" to merge them.
- Choose options: merge array items or use the first one, detect string formats, and turn repeated string values into enums.
- Read the strict-mode check under the output. It flags keywords that strict structured-output modes reject and rules the schema breaks.
- Copy the result as a raw JSON Schema, a ready
response_formatrequest, Pydantic v2 classes or a Zod schema.
How the schema is inferred
| Sample value | Schema |
|---|---|
"text" | {"type": "string"}, or with a format if detection is on |
42 / 4.2 | integer / number; mixed values become number |
true | boolean |
null | ["string", "null"], because a value that is always null tells nothing about its type |
| Object | object, every key in required, additionalProperties: false |
| Array | array; items merged from every element (or the first) |
| Key missing from some array items | Still required, but its type also allows null |
| Mixed types, e.g. 1 and "1" | ["integer", "string"], or anyOf for objects and arrays |
Keywords the strict-mode checker flags
Based on the "Supported schemas" section of OpenAI's structured outputs guide, checked 2026-11-14:
- Error, not supported:
allOf,not,dependentRequired,dependentSchemas,if,then,else. - Error, structure: root not an object or root
anyOf; an object withoutadditionalProperties: false; a property missing fromrequired; more than 10 levels of nesting, 5,000 properties or 1,000 enum values. - Warning, not in the supported list:
minLength,maxLength,patternProperties,propertyNames,minProperties,maxProperties,uniqueItems,contains,prefixItems,unevaluatedProperties,defaultandformatvalues other than date-time, time, date, duration, email, hostname, ipv4, ipv6 and uuid. - Note:
pattern,format,minimum,maximum,multipleOf,minItemsandmaxItemsare supported, except on fine-tuned models.
Worked example
For the sample invoice above, line_items has three objects and only one has a note. The generator keeps note in required (strict mode needs that) but types it ["string", "null"], so the model writes null when there is no note. unit_price is 18.5 in one item and 240 in another, so it becomes number. Tick "Repeated strings become enums" and category becomes enum: ["office", "shipping"]; only do that if the list really is closed.
Use it in a request
POST https://inference.broadnet.ai/v1/chat/completions
{
"model": "broadnet/glm-5.3",
"messages": [...],
"response_format": {
"type": "json_schema",
"json_schema": { "name": "invoice", "strict": true, "schema": { ... } }
}
}The reply's choices[0].message.content is a JSON string that matches the schema. Parse it, then validate with the Pydantic or Zod model. Set max_tokens high enough for reasoning models, or the JSON can be cut off; see why answers come back empty.
Questions
How do I generate a JSON schema from JSON?
Paste an example of the JSON you want and the generator infers a type for every value: objects become objects with all their keys, arrays take the type of their items, and numbers become integer or number. In strict mode every key is required and extra keys are forbidden.
What does strict mode require in a JSON schema?
OpenAI's structured outputs docs list the rules: the root must be an object (not anyOf), every object needs additionalProperties: false, and every property must be in required. Optional fields are written as a union with null, e.g. "type": ["string", "null"]. Limits: up to 5,000 properties, 10 levels of nesting and 1,000 enum values.
Which JSON Schema keywords are not supported in strict mode?
OpenAI lists allOf, not, dependentRequired, dependentSchemas, if, then and else as not supported, and fine-tuned models also reject minLength, maxLength, pattern, format, minimum, maximum, multipleOf, patternProperties, minItems and maxItems. Other OpenAI-compatible servers may support more or less, so test your schema.
How do I make a field optional in structured output?
In strict mode you cannot leave a key out of required. Instead, keep it required and allow null: "type": ["string", "null"]. The model then always returns the key and writes null when it has no value. The generator does this automatically for keys that are missing from some array items.
How do I use the schema with an OpenAI-compatible API?
Send it as response_format with type: "json_schema", a name, strict: true and the schema. The "Request" tab writes the full body for https://inference.broadnet.ai/v1/chat/completions. On BroadNet Inference, GLM 5.3 and Qwen3.8 27B are listed with structured output. See structured output.
Can I get Pydantic or Zod models instead?
Yes. The Pydantic tab writes Pydantic v2 classes with extra="forbid", and the Zod tab writes a z.object(...).strict() schema. Both match the JSON Schema, so you can validate the reply in Python or TypeScript.