NOTE: By default, Instructor looks for OPENAI_API_KEY environment variable to get your API key. You can also provide the API key explicitly when creating the Instructor instance.
Scalar
for simple values, Maybe
for optional data, Sequence
for arrays, and Structure
for dynamically defined schemas.
StructuredOutput
instance, you have several ways to execute the request and access different types of responses:
create()
create()
method returns a PendingStructuredOutput
instance, which acts as an execution handler that provides the same access methods:
get()
: Returns the parsed and validated structured result (e.g., Person
object)response()
: Returns the raw LLM response object with metadata like tokens, model info, etc.stream()
: Returns StructuredOutputStream
for real-time processing of streaming responsesPendingStructuredOutput
class serves as a flexible execution interface that lets you choose how to process the LLM response based on your specific needs.
input
field of Instructor’s with()
method
can be an object, but also an array or just a string.
Scalar
adapter class.
get()
: Returns the parsed and validated structured resultresponse()
: Returns the raw LLM response with metadatastream()
: Returns StructuredOutputStream
for real-time processingcreate()
: Returns PendingStructuredOutput
for flexible execution control