Module validated_llm

Source
Expand description

Validation wrapper for LLM providers with retry capabilities A module providing validation capabilities for LLM responses through a wrapper implementation.

This module enables adding custom validation logic to any LLM provider by wrapping it in a ValidatedLLM struct. The wrapper will validate responses and retry failed attempts with feedback to help guide the model toward producing valid output.

§Example

use llm::builder::{LLMBuilder, LLMBackend};

let llm = LLMBuilder::new()
    .backend(LLMBackend::OpenAI)
    .validator(|response| {
        if response.contains("unsafe content") {
            Err("Response contains unsafe content".to_string())
        } else {
            Ok(())
        }
    })
    .validator_attempts(3)
    .build()
    .unwrap();

Structs§

ValidatedLLM
A wrapper around an LLM provider that validates responses before returning them.