Instructor
Instructor enables structured output generation with SambaNova models. It allows large language models (LLMs) to produce responses in predefined formats—such as JSON, XML, or custom data schemas—ensuring consistency and making the output easier to parse and integrate into downstream systems. This functionality is particularly valuable for APIs, automation pipelines, and AI-driven applications that require reliable and predictable outputs.
Installation
Basic usage
The following code demonstrates how to use the SambaNova Cloud API with Instructor to generate structured output from the Meta-Llama-3.1-405B-Instruct
model. A User
schema is defined using Pydantic, requiring the model to return a response with a name
(string) and age
(integer). Instructor handles the response validation and parsing, resulting in a structured Python object.
Async usage
This code also uses SambaNova Cloud API with Instructor to enforce structured output. The result is fetched asynchronously and printed, outputting User(name='Ivan', age=28')
.
Explore an example notebook explaining how to create an email classification tool.