liveBook · Manning

Output format

As explained in Data Analysis with LLMs

Structured output is a result organized according to an explicit schema or format so that its components can be processed programmatically.

An output format tells a language model how to present its answer. A prompt can specify not just the task and input, but also the exact labels or layout the answer should use. Consistent answers are easier to process across many inputs. section 1.3.2 section 4.2.2

One label per review

To classify a movie review, include the review, ask whether its sentiment is positive or negative, and end with `Answer ("Positive"/"Negative"):`. Without that constraint, the model might reply with `P` or a full sentence instead. Using the same two labels makes it simpler to count the results. section 4.2.1 section 4.2.2

For information extraction, specify the shape of a whole result rather than a single label. A prompt can request named attributes in a fixed order, table boundary markers, newline-separated rows, pipe-separated fields, no header, and `<NA>` for missing values. Python code can generate that prompt for each input, then postprocess the model’s raw answer into structured output and save the results to a CSV file. section 4.3.2 section 4.3.4

 #1
Extract the following properties into a table:
[List of attributes] 
 #2
Text source: [Email] 
 #3
Mark the beginning of the table with <BeginTable> and the end with <EndTable>.
Separate rows by newline symbols and separate fields by pipe symbols (|).
Omit the table header and insert values in the attribute order from above.
Use the placeholder <NA> if the value for an attribute is not available.

The extraction prompt template shows where the attribute list and source text go, followed by the rules that make the answer parseable. section 4.3.2

Choose a format that matches the next step: a fixed label for counting classifications, or delimited fields for extracting records. State it explicitly in every prompt template rather than relying on the model to choose it. section 4.2.2 section 4.3.2

How Data Analysis with LLMs covers it

How deep it goes
Works through fixed labels and a delimited extraction template, then describes postprocessing raw answers into structured output.
Examples
Uses positive-or-negative movie reviews and a table template with boundary markers, pipe-separated fields, and missing-value placeholders.
What it assumes
Starts with familiar review classification before introducing Python prompt generation and an OpenAI-and-pandas extraction workflow.
What you can do after
Build it from scratch by specifying answer labels or table rules in prompts and postprocessing extraction results into CSV.
How it connects
Links output formats to prompt templates, sentiment classification, information extraction, and postprocessing.

Also explained in

Compare how 10 books explain output format →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Analysis with LLMs. The section links point to the parts of the book it draws on.