Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Building with LLMs

Structured outputs

Getting reliable JSON and other schema-shaped output from a model, and validating it.

Beginner
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark
On this page

Overview

Most applications need model output they can parse: a JSON object with known fields, a list of labels, an extracted table. Structured outputs is the skill of getting that reliably, using a provider's schema-constrained output mode where available, and validating everything you receive either way.

You define the shape once, usually as a Pydantic model or Zod schema, pass it to the model, and validate the response before your code uses it. Practitioners also design schemas that are easy for a model to fill in: clear field names, descriptions on each field, enums instead of free text, and an explicit way to say "not found" so the model does not invent values.

What you will practise

  • Define the output shape as a Pydantic model or Zod schema
  • Use a provider's schema-constrained output mode where it exists
  • Validate every response before your code relies on it
  • Design fields with enums, descriptions and an explicit "not found"

Learning paths

  • AI foundations

    A free AI foundations course: the working vocabulary of modern AI, from prompting and structured output to retrieval, MCP, Agent Skills and prompt injection.

    Beginner3 h9 steps

  • AI for data analysts

    An AI course for data analysts: clean spreadsheets, profile data with skills, go from SQL to a dashboard, extract PDF tables and catch invented numbers.

    Beginner9 h10 steps

  • Building with the Claude API

    Learn to build with the Claude API from your own code: the Messages API, tool use, structured output and prompt caching, then evaluate and trace what you built.

    Intermediate5 h9 steps

  • Prompt and context engineering

    A prompt and context engineering course: go from single prompts to deciding what a model sees at each step, from instructions and examples to files and tools.

    Intermediate3 h8 steps

Tutorials

Workflow recipes

  • Extract structured data from PDFs

    Turn a folder of PDF invoices into validated JSON with Docling, a Pydantic schema and structured outputs, plus a review file for every one that fails a check.

    Intermediate2 h 30 min7 steps

  • From business question to SQL dashboard with AI

    The assistant writes the SQL, you define the metrics and check every number before anyone acts.

    Intermediate3 h7 steps

Tools for this skill

  • AI SDK

    TypeScript toolkit for streaming, tool calls and agents across model providers.

    Agent frameworks and SDKsOpen sourceVercel

  • Docling

    Converts PDFs and office documents into structured output for LLM pipelines.

    Retrieval and vector searchOpen source

  • DSPy

    Write LLM programs as declarative modules and let optimisers tune the prompts.

    Agent frameworks and SDKsOpen source

  • Guardrails AI

    Python framework of validators that check and correct LLM inputs and outputs.

    Safety and securityOpen sourceGuardrails AI

  • Instructor

    Library for getting validated, typed structured outputs from LLMs using Pydantic models.

    Agent frameworks and SDKsOpen source

  • Outlines

    Python library for structured LLM outputs via constrained decoding.

    Models and local inferenceOpen source.txt

  • Pydantic AI

    Type-safe Python agent framework from the Pydantic team.

    Agent frameworks and SDKsOpen sourcePydantic

Key terms

Words you will meet while learning this, defined in the glossary.

Full glossary
  • Constrained decoding

    Masking out disallowed tokens during generation so a language model can only emit text matching a schema or grammar.

  • Structured outputs

    Constraining or validating model output so it matches a schema, usually JSON Schema, and can be parsed reliably by your code.