Symptoms
InvalidArgumentExceptionwith “No preset directory found” or “Invalid configuration”- Unexpected driver or model being used
- Type errors mentioning
maxTokens,dimensions, ormaxInputs
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/.
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:| Field | Type | Description |
|---|---|---|
driver | string | The driver name (e.g. openai, anthropic, gemini, ollama) |
apiUrl | string | Base URL of the provider API |
apiKey | string | API key, usually referencing an env var via ${VAR_NAME} |
endpoint | string | API endpoint path (e.g. /chat/completions, /messages) |
model | string | Default model identifier |
maxTokens | integer | Maximum tokens for the response |
contextLength | integer | Maximum context window size |
maxOutputLength | integer | Maximum output length in tokens |
metadata (an associative array for provider-specific values like organization or apiVersion), queryParams, options, and pricing.
Integer Field Validation
The fieldsmaxTokens, contextLength, and maxOutputLength must be valid integers. If these values are provided as strings in YAML (e.g. "1024" instead of 1024), Polyglot coerces them automatically. However, non-numeric strings or floats will cause an InvalidArgumentException.
For embeddings presets, the same rule applies to dimensions and maxInputs.
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.