Skip to main content
Instructor separates configuration into three layers: the LLM provider, the runtime, and the individual request. This keeps most applications simple — one runtime handles shared behavior, while each request stays focused on content.

Provider Configuration

Use LLMConfig to choose which provider and model to connect to. The simplest approach is a preset name that maps to your environment variables:
You can also create a StructuredOutput directly from a preset:
Provider configuration covers connection details: API keys, base URLs, default model names, and HTTP client settings.

Runtime Configuration

StructuredOutputRuntime holds behavior that is shared across many requests. Create one runtime and reuse it throughout your application:

Runtime Settings

Advanced Configuration With StructuredOutputConfig

For fine-grained control, build a StructuredOutputConfig directly:
StructuredOutputConfig includes settings for:
  • Output mode — which structured output strategy to use
  • Retry behavior — max retries and the prompt sent on validation failure
  • Tool metadata — tool name and description for OutputMode::Tools
  • Schema metadata — schema name and description
  • Mode prompts — per-mode prompt templates (e.g., how JSON Schema is embedded)
  • Chat structure — the ordering of prompt sections
  • Deserialization — error prompt template, stdClass fallback, object references

Request Configuration

StructuredOutput handles per-request concerns. These are the things that change from one call to the next:

Request Methods

Event Handling

The runtime exposes an event system for observing the processing pipeline:

Putting It Together

A typical application creates one runtime at bootstrap and passes it to each request:
This keeps configuration centralized and each request minimal.