Agentic Research

Structured output

Also: 結構化輸出 · JSON 輸出 · JSON mode · schema 輸出 · 結構化回應

Asking the model to return data that conforms to a format you specify (usually a JSON schema) instead of free prose, so downstream code can parse it directly without guessing.

When you will meet it

Anything where "AI is followed by automation" depends on it. Given prose, your code cannot reliably extract fields; given a fixed-structure JSON, it can store straight to a database and trigger the next step. Without it, AI output stays "for humans to read" and never becomes "for machines to use".

An analogy

Like ordering food. Free prose is a customer saying "the spicy one, no scallions" — the kitchen guesses. Structured output is a fixed-field order ticket: spice=medium, scallions=no, and the kitchen executes without misreading. The difference is not content but whether the format is fixed enough to process automatically.

Minimal example

// 你要的 schema(簡化):
{
  "type": "object",
  "properties": {
    "company": { "type": "string" },
    "revenue_million": { "type": "number" },
    "is_profitable": { "type": "boolean" }
  },
  "required": ["company", "revenue_million", "is_profitable"]
}

// 模型被約束後回的東西(可直接 json.loads 解析):
{ "company": "某科技公司", "revenue_million": 25000.5, "is_profitable": true }

Look at two things. First, required lists fields that must be present — the model cannot omit them. Second, each field has a type, so revenue_million is always a number (never prose like "about 25,000" that you cannot compute with). Downstream code can then parse confidently without writing piles of error handling.

What people get wrong

  • Assuming writing "please reply in JSON" in the prompt is enough. The model can still add explanatory text, use wrong quotes, or drop fields. For reliability, use the API's JSON mode / structured output or a schema constraint, and validate once more in code.
  • Assuming structured output means "correct content". It only guarantees valid format (legal JSON, all fields present), not that the numbers inside are true. The model will happily fill a fabricated number neatly into a correct schema.

Related terms

Next