AI agents · OpenClaw · self-hosting · automation

Quick Answer

Instructor vs Outlines vs BAML vs Pydantic AI (2026)

Published:

The short answer

All four give you typed output; they differ in where the guarantee comes from. As of November 16, 2026:

  • Instructor — validate-and-retry around any model API. Best default for extraction from hosted models.
  • Outlines — constrained decoding. Best for self-hosted open models where you control generation.
  • BAML — a typed prompt language that generates a client for each language. Best for teams sharing prompts across services.
  • Pydantic AI — an agent framework whose output_type makes structured results part of a tool-using agent.

The comparison

InstructorOutlinesBAMLPydantic AI
Latest release1.17.0 (Sep 9, 2026)1.3.3 (Aug 6, 2026)baml-py 0.226.3 (Oct 28, 2026)2.68.0 (Nov 12, 2026)
LicenceMITApache-2.0Apache-2.0MIT
GitHub stars (Nov 16, 2026)14,10016,0009,50021,200
How structure is guaranteedPydantic validation after generation, automatic re-ask with the errorToken masking during generation (JSON schema, regex, context-free grammar)Generated client parses and repairs model output against .baml typesOutput tools, native provider structured output or prompted output, validated by Pydantic
LanguagesPython, TypeScript, Go, Ruby, Elixir, RustPython.baml files → Python, TypeScript and other generated clientsPython
Model supportHosted APIs and local (Ollama, llama-cpp-python, vLLM)OpenAI, Anthropic, Gemini, Ollama, OpenRouter, vLLM, SGLang, TGI, Transformers, MLX, llama.cppAny provider configured in BAMLMost providers via model classes
Best forExtraction pipelinesOpen-model servingPolyglot teams, prompt testingAgents that return typed results

Instructor — the extraction default

Instructor patches your client so a call takes a response_model (a Pydantic class) and returns an instance of it. If validation fails — a missing field, a value outside a range you declared — it sends the error back to the model and retries. That is why it works with any provider and any custom validator: the guarantee is “valid or an exception after N retries”, not “valid by construction”. It also streams partial objects. The project itself frames the split clearly: Instructor for extraction, Pydantic AI for agents.

Outlines — structure during generation

Outlines guarantees the structure while tokens are produced, so the output always parses and there is nothing to retry. It supports JSON schemas, multiple choice, regex and context-free grammars, and it runs inside vLLM, SGLang, TGI, Transformers, MLX-LM and llama.cpp as well as wrapping hosted APIs (where it relies on their native structured modes). Choose it when you serve open models yourself, need formats JSON schema cannot express (a regex for IDs, a grammar for a DSL), or want zero retry cost at high volume. It is maintained by .txt, which also sells a hosted API.

BAML — prompts as typed code

BAML moves prompts out of Python strings into .baml files with declared input and output types. You test them in an editor playground, then generate a baml_client that handles the call, parses the output, fixes broken JSON and retries — and you call it from Python, TypeScript or another supported language with full type safety. It suits teams where several services in different languages use the same prompts, or where prompt engineers iterate without running the application.

Pydantic AI — structured output inside agents

Pydantic AI is an agent framework from the Pydantic team. Setting output_type makes the run end only when the model returns that type, through an output tool by default, the provider’s native structured output (NativeOutput) or prompted JSON (PromptedOutput). Output validators can raise ModelRetry to make the model try again, and each output tool can set its own retry limit. Pick it when the model also calls tools, needs dependency injection or will grow into a multi-step agent.

How to choose

  1. Extracting fields from documents or messages with a hosted model? Instructor — or the provider’s native JSON schema mode if you use one provider and only need schema conformance.
  2. Serving Llama-class or other open models on your own GPUs? Outlines.
  3. Same prompts used by a Python worker and a TypeScript API? BAML.
  4. The model also calls tools or runs several steps? Pydantic AI.

For provider-by-provider native modes and a step-by-step recipe, see how to get structured JSON output from LLMs.

Last verified: November 16, 2026.

Sources