01Chapter 1: Why free text is a poor interface for codeLanguage models write text. Programs need data in a known shape. This chapter explains where the two collide, what breaks when you ignore the gap, and what the rest of this tutorial does about it.7 min read
02Chapter 2: Describing the shape you want with JSON SchemaThis chapter assumes you can read and write JSON, you know basic Python classes and exceptions, and you have called an LLM API at least once. By the end you will be able to write a JSON Schema for the output you want. You will also know which keywords providers usually accept and which mistakes caus7 min read
03Chapter 3: Defining the schema as Pydantic modelsThis chapter assumes you know Python classes, type hints, and exceptions, and that you have read the previous chapter on JSON Schema. You should also be able to call an LLM API. Pydantic v2 and Python 3.10 or newer are assumed. Install it with pip install pydantic.6 min read
04Chapter 4: Asking for a format in the promptThis chapter covers the cheapest way to get structured output: describing the format in the prompt and parsing the reply yourself. It assumes you can read basic Python (classes, exceptions), know what JSON looks like, and have called an LLM API at least once. It also assumes you know the Pydantic `T7 min read
05Chapter 5: JSON mode: valid JSON, not necessarily your schemaThis chapter assumes you can write basic Python with classes and exceptions, read JSON, and have called an LLM API at least once. It also assumes you know what a Pydantic model and a JSON Schema are from the earlier chapters.6 min read
06Chapter 6: Schema-constrained structured outputsThis chapter assumes you can read a JSON Schema and a Pydantic model (covered earlier in this tutorial), and that you have called a chat-completion API before. The code uses the OpenAI Python SDK because its structured-output feature is widely copied. Other providers use different parameter names fo6 min read
07Chapter 7: Using function and tool calling to return dataThis chapter assumes you can write basic Python with classes and exceptions, read JSON, and have called an LLM API at least once. It also assumes you have seen JSON Schema and Pydantic models from earlier chapters. Here you will use tool calling, a feature built for running functions, as a way to ge8 min read
08Chapter 8: Validating output before you use itThis chapter assumes you can write basic Python classes and handle exceptions, and that you can read JSON. It also assumes you have called an LLM API at least once. It uses Pydantic v2 and the TicketTriage model from earlier in the tutorial.7 min read
09Chapter 9: Retrying with the validation error as feedbackThis chapter assumes you can write a Pydantic model, catch exceptions in Python, and have called an LLM API at least once. It also assumes you have read the previous chapter on validating output. Validation tells you that a reply is wrong. A retry loop gives the model a chance to fix it.6 min read
10Chapter 10: Designing schemas that models fill in wellThis chapter assumes you can write a Pydantic model, have read the chapters on JSON Schema and schema-constrained decoding, and run Python 3.10 or newer. It covers how to shape a schema so the model's output is accurate, not only valid.7 min read
11Chapter 11: What still goes wrong: truncation, refusals, and wrong valuesThis chapter assumes you can define a Pydantic model, call an LLM API, and read a JSON Schema. It also assumes you know the basics of validation and retry loops from earlier chapters. Even with schema-constrained decoding, three kinds of failure remain: the output is cut off, the model declines to a7 min read
12Chapter 12: Testing and monitoring the pipelineThis chapter assumes you can write a Pydantic model, call an LLM API, and have read the earlier chapters on validation and retry loops. Those chapters gave you an extraction step that validates output and retries on failure. Here you will check that the step works, and keep checking after it ships.7 min read