Instructor class final

Extracts typed, schema-validated data from an LLM.

The model is asked to call a tool whose parameters are your schema. The response is validated locally; if it does not conform, the violations are sent back to the model and it gets another try, up to maxRetries times.

Constructors

Instructor({required LlmAdapter adapter})

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() → void
Releases the adapter's resources by forwarding to LlmAdapter.close.
extract<T>({required List<Message> messages, required ObjectSchema schema, required T fromJson(Map<String, Object?> json), String toolName = 'extract', String? toolDescription, int maxRetries = 2, void onRetry(ExtractionAttempt attempt)?}) Future<T>
Extracts a T from the model.
extractRaw({required List<Message> messages, required ObjectSchema schema, String toolName = 'extract', String? toolDescription, int maxRetries = 2, void onRetry(ExtractionAttempt attempt)?}) Future<Map<String, Object?>>
Like extract, but returns the validated JSON object as-is.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited