AI & LLM

LLM Structured Output (JSON Schema) JSON Example

A JSON example of LLM structured outputs — a request with response_format json_schema and the guaranteed-valid JSON the model returns. Copy-ready for OpenAI JSON mode and reliable parsing.

{
  "sentiment": "positive",
  "score": 0.92,
  "topics": [
    "delivery",
    "packaging"
  ],
  "summary": "Customer is happy with fast delivery and secure packaging."
}

Field Reference

sentimentrequiredstringConstrained by the schema's enum — guaranteed to be one of the allowed values
scorerequirednumberModel-estimated confidence; schema can bound it to 0–1
topicsrequiredarray<string>Extracted topics; schema enforces the array-of-strings shape
summaryrequiredstringFree-text field still constrained to appear and be a string

Variants

Request with json_schemaSetting response_format forces the model to return JSON matching your schema exactly.
Request with json_schema
{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "system",
      "content": "Extract sentiment from the review."
    },
    {
      "role": "user",
      "content": "Super fast delivery and great packaging!"
    }
  ],
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "review_analysis",
      "strict": true,
      "schema": {
        "type": "object",
        "properties": {
          "sentiment": {
            "type": "string",
            "enum": [
              "positive",
              "neutral",
              "negative"
            ]
          },
          "score": {
            "type": "number"
          },
          "topics": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "summary": {
            "type": "string"
          }
        },
        "required": [
          "sentiment",
          "score",
          "topics",
          "summary"
        ],
        "additionalProperties": false
      }
    }
  }
}

Common Use Cases

  • Forcing an LLM to return parseable JSON instead of prose
  • Extracting structured fields (entities, classifications) from free text
  • Eliminating fragile regex parsing of model output in production
structured outputjson modeopenaijson schemaresponse_formatllm

Validate or format this JSON

One click loads this exact example into the tool — no copy-paste needed. Format it, validate it, explore the tree, or generate TypeScript types instantly.

Frequently Asked Questions

JSON mode only guarantees the output is valid JSON, not its shape. Structured outputs (response_format type json_schema with strict: true) guarantee the output matches your exact JSON Schema — correct keys, types, and enums — so you can parse it without defensive checks.

It tells the model the object may contain only the properties you defined, preventing extra hallucinated keys. Combined with strict mode and a required array listing every property, it makes the output fully deterministic in shape.

Yes. You can nest objects, arrays, enums, and unions (via anyOf). Keep schemas reasonable in depth — extremely deep or recursive schemas can hit provider limits — and always mark required fields explicitly.

Related JSON Examples