A prompt that says “reply in JSON” leaves the shape to chance. A JSON Schema writes the shape down so a machine can check it.
How it works
The specification has two main parts: Core, which “defines the basic foundation of JSON Schema”, and Validation, which “defines the validation keywords”. The current version is 2020-12; the one before was 2019-09.
{
"type": "object",
"properties": {
"name": {"type": "string"},
"amount": {"type": "number", "minimum": 0},
"currency": {"type": "string", "enum": ["SAR", "AED", "USD"]},
"note": {"type": ["string", "null"]}
},
"required": ["name", "amount", "currency", "note"],
"additionalProperties": false
}
LLM APIs use schemas in two places. Tool definitions put one in parameters to describe the arguments. Structured output sends one in response_format as {"type": "json_schema", "json_schema": {...}}, which OpenAI says “ensures the model will match your supplied JSON schema”.
OpenAI’s strict mode accepts only a subset. From its supported-schemas section:
- Types: string, number, boolean, integer, object, array, enum and anyOf.
- The root must be an object and cannot use
anyOf. additionalProperties: falseand every field listed inrequired; make a field optional by allowingnull, asnotedoes above.- Up to 5000 object properties and 10 levels of nesting, and up to 1000 enum values in total.
- Not supported:
allOf,not,dependentRequired,dependentSchemas,if,then,else.
Why it matters
- Validation. The same schema that guides the model checks its reply in your code. A failed check gives an exact error to send back.
- Portability. A schema written to the strict subset works across more providers than one using every keyword.
- Tokens. Schemas in tool definitions are sent as input on every request. Long descriptions cost tokens each turn.
On BroadNet Inference
BroadNet’s API reference documents tool calling and structured output for GLM 5.3 and Qwen3.8 27B, but not which schema keywords are enforced. Keep schemas to the simple subset above and validate every reply. Build a schema with the JSON Schema generator, check replies with the LLM JSON output validator, and see the structured output post for a full example. On other models, ask for JSON in the prompt and validate the reply; JSON mode is not documented by BroadNet, so test before relying on it.
Common mistakes
- Using
allOfor conditional keywords and assuming the server enforces them. - Making fields optional by leaving them out of
requiredin strict mode, instead of allowingnull.