Provider Configuration
UseLLMConfig to choose which provider and model to connect to. The simplest approach
is a preset name that maps to your environment variables:
StructuredOutput directly from a preset:
Runtime Configuration
StructuredOutputRuntime holds behavior that is shared across many requests. Create one
runtime and reuse it throughout your application:
Runtime Settings
| Method | Purpose |
|---|---|
withMaxRetries($n) | Number of retry attempts after validation failure |
withOutputMode($mode) | How the model produces structured output (Tools, Json, etc.) |
withValidator($validator) | Override the validator (implements CanValidateObject) |
withTransformer($transformer) | Override the response transformer (implements CanTransformData) |
withDeserializer($deserializer) | Override the deserializer (implements CanDeserializeClass) |
withExtractor($extractor) | Override the response extractor (implements CanExtractResponse) |
withConfig($config) | Pass a full StructuredOutputConfig object |
withDefaultToStdClass($bool) | Fall back to stdClass for unknown types |
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,
stdClassfallback, object references
Request Configuration
StructuredOutput handles per-request concerns. These are the things that change from
one call to the next:
Request Methods
| Method | Purpose |
|---|---|
withMessages(...) | Set the chat messages |
withInput(...) | Input data (string, array, or object) |
withResponseModel(...) | Response model (class, instance, or schema) |
withSystem(...) | System prompt text (string|\Stringable) |
withPrompt(...) | Additional prompt text (string|\Stringable) |
withExamples(...) | Few-shot examples |
withModel(...) | Model name override |
withOptions(...) | Provider-specific options |
withStreaming(...) | Enable streaming |
withCachedContext(...) | Cached context for prompt caching |