Structured Output
MagicAF makes it straightforward to get structured, typed responses from your RAG pipeline. Instead of working with raw text, define a struct and let the framework deserialize it automatically. Using JsonResultParser<T> The fastest way to get structured output: define a struct that derives Deserialize, then use JsonResultParser. 1. Define your result type use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] pub struct QAAnswer { pub answer: String, pub confidence: f32, pub sources: Vec<usize>, } 2. Tell the LLM to output JSON Use a PromptBuilder that instructs the LLM to respond in your expected format: ...