Skip to main content
Configuration issues typically surface when Polyglot cannot find a preset file, when the file is missing required fields, or when field values have the wrong type. These problems usually produce clear error messages that point directly to the cause.

Symptoms

  • InvalidArgumentException with “No preset directory found” or “Invalid configuration”
  • Unexpected driver or model being used
  • Type errors mentioning maxTokens or an unknown configuration field

Preset File Location

When you call Inference::using('openai'), Polyglot searches for a file named openai.yaml in these directories (in order):
  1. config/llm/presets/ — relative to your project root
  2. packages/polyglot/resources/config/llm/presets/ — monorepo layout
  3. vendor/cognesy/instructor-php/packages/polyglot/resources/config/llm/presets/ — installed via Composer as part of instructor-php
  4. vendor/cognesy/instructor-polyglot/resources/config/llm/presets/ — installed via Composer as standalone package
For embeddings, the equivalent paths use config/embed/presets/ instead of config/llm/presets/. Structured Decision presets use config/sdm/presets/, and Decision::using('typesafe') resolves typesafe.yaml through the same application, monorepo, and Composer-package layouts. If none of these directories exist, Polyglot throws an InvalidArgumentException. To override the search path, pass a basePath argument:

Required Preset Fields

A minimal LLM preset YAML file must include:
The following fields are required or strongly recommended: Optional fields include metadata (an associative array for provider-specific values like organization or apiVersion), queryParams, and options. A minimal TypeSafe Decision preset contains only the shared connection fields:
The default Decision preset name belongs in config/sdm/default.yaml:

Integer Field Validation

The maxTokens field must be a valid integer. If it is provided as a numeric string in YAML, Polyglot coerces it automatically. Non-numeric strings and floats cause an InvalidArgumentException. Embedding dimensions, defaultDimensions, and maxInputs are no longer configuration fields. Remove them from presets and framework configuration. Use request options for a caller-selected dimension and an embedding model catalog for reviewed defaults and provider limits.

Building Configuration Programmatically

If your configuration is dynamic — for example, when the user selects a model at runtime — prefer building LLMConfig directly instead of relying on preset files:
You can also create a config from an associative array:

Overriding Preset Values

To start from a preset and change specific values, use withOverrides():

Verify a Configuration

To check that a preset loads correctly without making a request, instantiate the config and inspect it:

Common Pitfalls

  • Preset name does not match the filename. Inference::using('gpt4') looks for gpt4.yaml, not openai.yaml.
  • YAML indentation errors. Malformed YAML will cause the config loader to fail silently or return unexpected values.
  • Retry policy in options. Polyglot explicitly forbids placing retryPolicy inside the options array of LLMConfig. Use withRetryPolicy() on the inference builder instead.
  • Environment variable not expanded. If the apiKey field contains the literal string ${OPENAI_API_KEY} at runtime, the environment variable was not resolved. Ensure the variable is set before the preset is loaded.