Skip to content

Knowledge base

Structured model output

Structured output means a model answers in a typed shape that code can validate, instead of free text that code has to parse. A schema-first layer declares the shape as a typed model, checks every response against it, and re-asks the model when validation fails.

Written by

Updated:

Tools 4

Our position. We put deterministic operations in scripts so the agent does not improvise them: the script owns the order, and the agents do the work inside each stage (opens in a new tab).

An agent’s output becomes input for code the moment it fills a form, calls an API or hands a result to the next step. Free text breaks that hand-off on every formatting slip, so the reliable route puts a schema between the model and the code that consumes its answer.

How does a schema-first extraction layer work?

You declare the shape you want as a typed class, and the library asks the model to fill it. Instructor, built on Pydantic, takes a BaseModel as the response_model of a call and returns a typed object rather than a string (Instructor (opens in a new tab)). Field validators run on every response. When one fails, Instructor re-asks the model automatically, so the retry loop lives in the library rather than in each caller. The same API streams partial objects while the model is still generating, and yields a list of objects one at a time (Instructor (opens in a new tab)).

Which providers and languages does Instructor cover?

Instructor reports over three million monthly downloads and supports 15+ providers, among them OpenAI, Anthropic, Google Gemini, Mistral and DeepSeek, plus open models served through Ollama, vLLM or llama.cpp. Ports exist for Python, TypeScript, Go, Ruby, Elixir and Rust. For agent workloads that need quality gates, observability or typed tools, its own documentation points to PydanticAI instead (Instructor (opens in a new tab)).

When does a dedicated language beat a library?

BAML moves the problem out of the host language. BoundaryML describes it as an open-source programming language for agents, with TypeScript-like syntax, types that stay meaningful at runtime, typed errors, and native LLM functions with tests and evaluations (BoundaryML (opens in a new tab)). Generated SDKs for Python and TypeScript let a team adopt it incrementally. BAML is pre-1.0, and its vendor warns that APIs and tooling may still change (BoundaryML (opens in a new tab)).

The trade-off follows from the two designs. Instructor wraps the SDK you already call and adds one parameter. BAML asks you to write your LLM functions in a new language, and in return carries types, tests and evaluations through the whole pipeline.

Resources

Posts

Tools and repositories

  • BoundaryML (opens in a new tab) - BoundaryML’s site for BAML, a pre-1.0 open-source programming language for typed LLM functions with tests and evaluations.
  • Instructor (opens in a new tab) - Documentation for Instructor, a Pydantic-based library that returns typed objects from LLM calls and re-asks the model when validation fails.