Structured Output

BytapaScript

What it means

Asking an AI model to return information in a predefined format, such as JSON.

💡 Asking someone to fill out a standard form instead of writing an unstructured paragraph.

Code example

const res = await openai.chat.completions.create({
  model: "gpt-4o",
  response_format: { type: "json_object" },
  messages: [{ role: "user", content: "Return {name, age} for Alice, 30" }],
});
console.log(JSON.parse(res.choices[0].message.content));

Why it matters

It makes responses easier to consume programmatically and integrate into frontends, APIs and databases.

Common misconception

Structured output constrains the format, not the accuracy of the content.

When to use it

  • Extracting JSON from text
  • Filling forms
  • Generating config files

Related terms

Learn Full Stack

with tapaScript

By clicking Sign Up you re confirming that you agree with our Terms and Conditions.

newsletter

Don't forget to connect with us on