Show HN: rstructor, Pydantic+instructor for Rust (github.com)

🤖 AI Summary
rstructor is a new Rust library that brings Instructor- and Pydantic-style structured LLM outputs to the Rust ecosystem: you declare schemas as normal Rust structs/enums (using a derive macro), and rstructor auto-generates JSON Schema, queries LLMs, parses responses, and validates results. It supports multiple backends (OpenAI, Anthropic, Grok, Gemini) via an extensible, feature-flagged system, offers an async API and a builder pattern for client configuration, and includes a production-friendly generate_struct_with_retry that can retry with validation feedback. Technically, rstructor emphasizes schema fidelity (heuristic-free JSON Schema that preserves nested structs and enums, serializing enum variants as tagged unions), type-safe definitions, and both type checking plus custom business-rule validation via an automatically-detected validate() method. It handles complex nested data (arrays, deeply nested enums with associated data), and provides a CustomTypeSchema trait to describe non-JSON-native types (chrono DateTime, uuid, emails, URLs) including additional schema properties. The result: more reliable, auditable LLM integrations in Rust, reduced prompt-engineering and hallucinations through schema-guided generation, and easy extension to new providers or domain-specific types.
Loading comments...
loading comments...