Home/Glossary/Structured Output
Prompting

Structured Output

Constraining model generation to produce valid, machine-parseable formats like JSON or XML.

Full Definition

Structured output goes beyond instructing a model to 'respond in JSON' — it uses constrained decoding, grammar-guided generation, or function-calling APIs to guarantee that the model's output conforms to a specified schema. OpenAI's JSON mode, Anthropic's tool-use feature, and libraries like Outlines or Guidance implement this at the token sampling level, making schema-invalid tokens impossible to generate. This is essential in production pipelines where model output is parsed programmatically — an unparseable response breaks the application. Structured output removes the need for fragile regex post-processing and makes model responses reliably consumable by downstream code.

Examples

1

Using OpenAI's function-calling API to guarantee a model returns a JSON object matching a Pydantic schema when extracting entities from text.

2

Using the Guidance library to constrain a model to output a valid SQL SELECT statement with no free-form text.

Apply this in your prompts

PromptIt automatically uses techniques like Structured Output to build better prompts for you.

✦ Try it free

Related guides

What is Prompt Engineering?How to Use Role in AI PromptsHow to Add Context to AI PromptsDefining the Task in Your AI Prompt

Related Terms

Output Format

Specifying the exact structure, length, or schema the model should use when resp

View →

Function Calling

A model feature that allows it to request the execution of developer-defined fun

View →

Tool Use

The ability of a model to invoke external tools — APIs, code executors, search —

View →
← Browse all 100 terms