Vibeleaderboard
← All Intel
Intel / post

Three routes to structured LLM output, including constrained decoding

Source
x.com
Date
Andrew Ng@AndrewYNg

New Short Course: Getting Structured LLM Output! Learn how to get structured outputs from your LLM applications in this course, built in partnership with @dottxtai, and taught by @willkurt, a Founding Engineer, and @just_cameron , Developer Relations Engineer. It's challenging for software to automatically parse through an LLM's freeform text outputs. Structured outputs—like JSON—solve this by converting natural language into consistent, clear, data that a machine can read and process. This course teaches you how to generate structured outputs while building several use cases, including a social media analysis agent. You’ll learn about structured outputs and efficient ways to generate outputs in your defined schema or format. You’ll begin by using structured output APIs, then use re-prompting libraries like “instructor” to generate structured output. Finally, you’ll learn how constrained decoding works; this is a very clever technique in which constraints are applied on each subsequent token generated, blocking any tokens that don’t fit your defined schema. In detail, you’ll: - Learn why structured outputs are important, how they allow for scalable software development, and…

Read the full post on X

Context

Software can process a model's answer more predictably when the answer follows a defined structure. The Getting Structured LLM Output announcement compares requesting through a provider's API, checking a generated answer and requesting corrections, and constraining generation itself.

The last approach restricts which text units the model may generate next, excluding choices that would violate the required structure. Retrying instead checks an answer after generation. These approaches help applications obtain consistently shaped records, while whether the values in those records are factually correct remains a separate question.

Terms in this piece · Glossary
  • LLM — A large language model — the neural network behind tools like Claude and ChatGPT, trained on huge amounts of text to predict what comes next.
  • structured output — Forcing a model's response to match a schema, so downstream code can parse it instead of guessing at prose.
  • token — The chunk of text a model reads and writes in — roughly three-quarters of a word — and the unit AI usage is billed in.
  • AI agent — An AI system that doesn't just answer once but works toward a goal in a loop — taking actions, reading the results, and deciding what to do next.
More from Andrew Ng
Recommended reads
Comments

Checking sign-in…

Loading comments…