Expand description
§struct-llm
A lightweight, WASM-compatible Rust library for generating structured outputs from LLMs using a tool-based approach.
§Quick Start
ⓘ
use struct_llm::StructuredOutput;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, StructuredOutput)]
#[structured_output(
name = "sentiment_analysis",
description = "Analyzes the sentiment of the given text"
)]
struct SentimentAnalysis {
sentiment: String,
confidence: f32,
reasoning: String,
}
// Generate tool definition
let tool = SentimentAnalysis::tool_definition();
// Make API request with your HTTP client
let response = make_api_request_with_tools(&prompt, &[tool]).await?;
// Extract and validate structured response
let tool_calls = extract_tool_calls(&response, Provider::OpenAI)?;
let result: SentimentAnalysis = parse_tool_response(&tool_calls[0])?;Re-exports§
pub use error::Error;pub use error::Result;pub use provider::build_enforced_tool_request;pub use provider::build_request_with_tools;pub use provider::Provider;pub use schema::validate as validate_schema;pub use streaming::StreamParser;pub use streaming::ToolDelta;pub use tool::extract_tool_calls;pub use tool::parse_tool_response;pub use tool::ToolCall;pub use tool::ToolDefinition;
Modules§
- error
- Error types for struct-llm
- provider
- Provider-specific adapters for different LLM APIs
- schema
- JSON Schema generation and validation utilities
- streaming
- tool
- Tool definition and parsing utilities
Structs§
- Message
- Message in a conversation
Traits§
- Structured
Output - Core trait for types that can be used as structured LLM outputs.
Derive Macros§
- Structured
Output - Derive macro for
StructuredOutputtrait.