Skip to main content

Overview

The cognesy/instructor-struct package works without any published configuration files. All structured-output behavior is controlled through typed configuration objects in code. When configuration files are present in a project, they typically serve the companion Polyglot package (provider presets) rather than the structured-output package itself.

Provider Presets

LLM provider connections are configured through YAML preset files managed by the cognesy/polyglot package. Each preset defines the API URL, driver, model, token limits, and other provider-specific settings:
packages/polyglot/resources/config/llm/presets/
    openai.yaml
    anthropic.yaml
    gemini.yaml
    groq.yaml
    ...
// @doctest id="650e"
You load a preset with LLMConfig::fromPreset():
use Cognesy\Polyglot\Inference\Config\LLMConfig;

$config = LLMConfig::fromPreset('openai');
// @doctest id="87ee"
The preset resolution searches several paths automatically (project config/ directory, monorepo paths, and Composer vendor paths), so presets work out of the box in most setups.

Configuration Groups

In the broader InstructorPHP ecosystem, configuration is organized into groups. Each group is stored in a separate file. The main groups are:
GroupPurpose
llmLLM provider connections and presets
structuredStructured output behavior (output mode, retries, prompts)
embedEmbedding provider connections
httpHTTP client configurations
promptPrompt libraries and settings
webWeb service providers (scrapers, etc.)
debugDebugging settings
The structured-output package only consumes the structured and llm groups. Other groups belong to companion packages.

Structured Output Configuration

Rather than reading from config files, the structured-output package uses the StructuredOutputConfig class directly:
use Cognesy\Instructor\Config\StructuredOutputConfig;
use Cognesy\Instructor\Enums\OutputMode;

$config = new StructuredOutputConfig(
    outputMode: OutputMode::Tools,
    maxRetries: 2,
    toolName: 'extract_data',
);
// @doctest id="4273"
This keeps the package independent from any file-based configuration system while still allowing integration with one when needed (via fromArray() or fromDsn()).