Skip to main content
AI / MLLLM FundamentalsDiagramBeginner

Structured Output

KO: 구조화 출력·EN: Structured Output·JA: 構造化出力

A technique using constrained decoding to guarantee that an LLM's output strictly conforms to a predefined JSON Schema or formal grammar for reliable software integration

Table of Contents

Structure Diagram

Constrained Decoding Structured Output Loop
JSON Schema1. Compile S…2. Mask Logi…3. Sample Va…4. Typed Par…
2/42. Mask Logits
Ban invalid tokens
Quick Answer

What is Structured Output?

A technique using constrained decoding to guarantee that an LLM's output strictly conforms to a predefined JSON Schema or formal grammar for reliable software integration. It is a core concept in LLM Fundamentals within AI / ML.

Core Principles

Structured Output goes beyond asking an LLM to "reply in JSON." Under the hood, it compiles a JSON Schema into a Finite State Machine (FSM) or grammar and applies Constrained Decoding, masking out invalid tokens (-∞ logit) at every generation step.

This guarantees syntactically valid, schema-compliant output without broken brackets, markdown wrappers, or hallucinated keys, allowing LLMs to integrate cleanly with typed backend code.

Practical Takeaways

  • Place a reasoning field before the final answer: Forcing an immediate label degrades accuracy on complex judgments. Put a brief reasoning string first in the schema so the model can think before committing.
  • Use enum and nullable fields deliberately: Allow null for missing information so the model does not fabricate values just to satisfy required keys.
  • Keep schemas flat and concise: Deeply nested unions and complex regex patterns increase grammar compilation latency and hurt model adherence.

Notable Examples

  • Invoice & Contract Extraction: Parse unstructured PDFs into strongly typed Pydantic/Zod objects ready for database insertion.
  • Support Ticket Triage: Classify incoming messages into { intent, priority, team, summary } JSON payloads.
  • Generative UI: Return validated widget specs that frontend components render deterministically.