Available Output Formats
intoArray()
Returns extracted data as a plain associative array instead of an object.intoInstanceOf()
Uses one class for the schema definition and a different class for the output object.UserProfile, ensuring thorough extraction. The output is then hydrated into the simpler UserDTO. This is valuable when you want to separate API contracts from internal models, simplify complex extraction results, or decouple domain models from presentation layers.
intoObject()
Provides a custom object that controls its own deserialization from the extracted array. The object must implement theCanDeserializeSelf interface.
Scalar adapter for extracting single values.
Streaming with Output Formats
Output formats work seamlessly with streaming. During streaming, partial updates are always returned as objects (for validation and deduplication). The final result respects the output format you specified.Comparison
| Feature | Default (Object) | intoArray() | intoInstanceOf() | intoObject() |
|---|---|---|---|---|
| Output type | Schema class | Array | Target class | Custom object |
| Validation | Yes | Skipped | Yes | Custom |
| Streaming partials | Object | Object | Object | Object |
| Streaming final | Object | Array | Target class | Custom object |
Common Patterns
Conditional Deserialization
Inspect data before choosing the target class.Multi-Layer Architecture
Use a rich domain model for extraction and a simplified DTO for your application layer.Pluggable Extraction
Instructor uses a pluggable extraction pipeline to convert raw LLM responses into canonical arrays. You can customize this pipeline on theStructuredOutputRuntime to support non-standard response formats. See JSON Extraction for details on the extraction pipeline and how to write custom extractors.