Symptoms
InvalidArgumentExceptionwith “No preset directory found” or “Invalid configuration”- Unexpected driver or model being used
- Type errors mentioning
maxTokensor an unknown configuration field
Preset File Location
When you callInference::using('openai'), Polyglot searches for a file named openai.yaml in these directories (in order):
config/llm/presets/— relative to your project rootpackages/polyglot/resources/config/llm/presets/— monorepo layoutvendor/cognesy/instructor-php/packages/polyglot/resources/config/llm/presets/— installed via Composer as part of instructor-phpvendor/cognesy/instructor-polyglot/resources/config/llm/presets/— installed via Composer as standalone package
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:
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:
config/sdm/default.yaml:
Integer Field Validation
ThemaxTokens 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 buildingLLMConfig directly instead of relying on preset files:
Overriding Preset Values
To start from a preset and change specific values, usewithOverrides():
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 forgpt4.yaml, notopenai.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
retryPolicyinside theoptionsarray ofLLMConfig. UsewithRetryPolicy()on the inference builder instead. - Environment variable not expanded. If the
apiKeyfield 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.