Step by Step
J
JSON mode — telling the model to output JSON
JSON mode simply tells the model to output JSON directly, a feature most modern LLM APIs support.
Example: enabling JSON mode in an API call and instructing the model to return its response strictly as valid JSON.
F
Function calling / tool use — the most reliable approach
Function calling (or tool use) defines a function schema, and the model fills in the parameters according to that schema — this is generally considered the most reliable of the three approaches.
Example: defining a function schema for "extract_invoice_data" with specific typed parameters (vendor_name: string, amount: number, date: string), and having the model reliably fill in those exact parameters.
P
Pydantic with instructor — Python dataclass validation
Using the Pydantic library combined with the instructor library, a Python dataclass is defined, and the LLM populates it with automatic validation ensuring the output actually conforms to the expected types and structure.
Example: defining a Pydantic dataclass with typed fields, then using the instructor library to have an LLM populate an instance of that dataclass, with automatic validation catching any type mismatches.
⭐
Why this matters — production applications need structured data
Raw LLM output is inherently unpredictable free text, but production applications need reliably structured data to parse and act on programmatically — making structured output essential for any real LLM-powered application beyond simple conversational display.
Example: a production application that needs to programmatically extract and act on specific fields from an LLM's response, requiring one of these structured output approaches rather than trying to parse unpredictable free text directly.
Applied Walkthrough
1
A developer builds a production application that needs to reliably extract specific fields (vendor name, amount, date) from invoices processed by an LLM.
2
Using plain, unstructured text prompting alone, the output format varies unpredictably between different invoices, making reliable programmatic parsing difficult.
3
Switching to function calling / tool use, they define a specific function schema with typed parameters for vendor name, amount, and date, and the model reliably fills in those exact parameters in a consistent, parseable format.
4
This function-calling approach, being the most reliable of the three structured output methods, ensures the production application can consistently and reliably parse and act on the LLM's output, rather than dealing with the unpredictability of raw free text.
Exam Application
Exams test whether you can name and distinguish the three approaches to structured output (JSON mode, function calling/tool use, Pydantic with instructor) and whether you know function calling is generally considered the most reliable of the three approaches.
⚠ Common Trap
The most common trap is assuming raw, unstructured text prompting alone is sufficient for production applications that need to parse and act on LLM output programmatically. Production applications specifically require one of these structured output approaches (JSON mode, function calling, or Pydantic validation) to reliably parse and act on responses, since raw free text is inherently unpredictable.
✓ Quick Self-Check
1. What does JSON mode do?
Tells the model to output JSON directly, a feature most modern LLM APIs support.
Tap to reveal / hide
2. What does function calling / tool use involve?
Defining a function schema, with the model filling in the parameters according to that schema.
Tap to reveal / hide
3. Which of the three structured output approaches is generally considered the most reliable?
Function calling / tool use.
Tap to reveal / hide
4. What does using Pydantic with the instructor library provide?
A Python dataclass that the LLM populates, with automatic validation ensuring the output conforms to expected types and structure.
Tap to reveal / hide
5. Why is structured output essential for production LLM applications?
Because raw LLM output is inherently unpredictable free text, while production applications need reliably structured data to parse and act on programmatically.
Tap to reveal / hide