Turn an LLM response into a Rust value. Annotate your type with #[model] and call client.create(prompt). Instructor derives the schema and can ask the model to correct an invalid reply.
This CLI extracts an order ID and a queue from a customer message. With recent stable Rust, install the GitHub source release. The crates.io release predates these APIs.
cargo new ticket-router
cd ticket-router
cargo add instructor-ai --git https://github.com/567-labs/instructor-rs \
--tag rust-2026-12-01Replace src/main.rs with this program. The Ticket annotation sets the response type, and the match selects the action for each queue. Try it without a key
use instructor_ai::{model, Error};
#[model]
#[serde(rename_all = "snake_case")]
enum Queue {
Billing,
Shipping,
Other,
}
#[model]
struct Ticket {
queue: Queue,
order_id: String,
}
fn main() -> Result<(), Error> {
let client = instructor_ai::BlockingClient::from_provider("openai/gpt-6-luna")?;
let ticket: Ticket = client.create("Route this ticket: I was charged twice for order A17.")?;
let action = match ticket.queue {
Queue::Billing => "Review charges",
Queue::Shipping => "Check tracking",
Queue::Other => "Read the ticket",
};
println!("{action} for order {}", ticket.order_id);
Ok(())
}Set OPENAI_API_KEY and run the CLI. Expect Review charges for order A17.
cargo runReplace the client and ticket bindings in main with these lines.
let saved_reply = r#"{"queue":"billing","order_id":"A17"}"#;
let ticket: Ticket = instructor_ai::parse_response(saved_reply, &Default::default())?;Run cargo run. Try shipping to select another action, or sales to see the parser reject an unknown queue. For a full response saved with create_with_completion, use parse_completion. Parse a saved completion
Pass a model your account can access to BlockingClient::from_provider and set its key.
| Provider | Model argument | Environment variable |
|---|---|---|
| OpenAI | "openai/gpt-6-luna" |
OPENAI_API_KEY |
| Anthropic | "anthropic/claude-haiku-5-5" |
ANTHROPIC_API_KEY |
| OpenRouter | "openrouter/openai/gpt-6.2-sol" |
OPENROUTER_API_KEY |
You can also use Google Gemini, Cohere or Mistral. Provider setup and supported modes
- Use
Clientand awaitclient.create::<Ticket>(message)in a Tokio service. Async quickstart - Check the order ID against your records and retry with feedback. Response types · Validation and retries
- Preview one ticket with
create_partial::<Ticket>or process tickets as they arrive withcreate_iterable::<Ticket>. Streaming - Choose a queue and score urgency with OpenAI or Jev. Typed decisions
- Read a receipt, verify a quote or process a backlog. Media input · Source citations · Batch jobs
Porting a Python application? Supported workflows · Benchmarks