Skip to main content

MaskedProvider

Struct MaskedProvider 

Source
pub struct MaskedProvider { /* private fields */ }
Expand description

Wraps an AnyProvider so every outbound chat*/chat_with_tools* call masks message text via an OutboundMasker before delegating to the inner provider.

§Examples

use std::sync::Arc;
use zeph_llm::any::AnyProvider;
use zeph_llm::masking::OutboundMasker;
use zeph_llm::ollama::OllamaProvider;

#[derive(Debug)]
struct UppercaseMasker;
impl OutboundMasker for UppercaseMasker {
    fn mask(&self, text: &str) -> Option<String> {
        if text.contains("secret") { Some(text.replace("secret", "***")) } else { None }
    }
}

let inner = AnyProvider::Ollama(OllamaProvider::new("http://localhost:11434", "m".into(), "e".into()));
let masked = inner.masked(Arc::new(UppercaseMasker));
assert_eq!(masked.name(), "ollama"); // delegation still works transparently

Implementations§

Source§

impl MaskedProvider

Source

pub fn new(inner: AnyProvider, masker: Arc<dyn OutboundMasker>) -> Self

Wrap inner with masker.

Source

pub fn inner(&self) -> &AnyProvider

Return the wrapped provider, discarding the masking layer.

Source

pub fn applied_count(&self) -> u64

Number of outbound calls (across every clone of this wrapper) that had at least one secret masked. Exposed for the secret_mask_applied observability metric.

Trait Implementations§

Source§

impl Clone for MaskedProvider

Source§

fn clone(&self) -> MaskedProvider

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MaskedProvider

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl LlmProvider for MaskedProvider

Source§

fn context_window(&self) -> Option<usize>

Report the model’s context window size in tokens. Read more
Source§

async fn chat(&self, messages: &[Message]) -> Result<String, LlmError>

Send messages to the LLM and return the assistant response. Read more
Source§

async fn chat_with_extras( &self, messages: &[Message], ) -> Result<(String, ChatExtras), LlmError>

Send messages and return the assistant response together with per-call extras. Read more
Source§

async fn chat_stream( &self, messages: &[Message], ) -> Result<ChatStream, LlmError>

Send messages and return a stream of response chunks. Read more
Source§

fn supports_streaming(&self) -> bool

Whether this provider supports native streaming.
Source§

async fn embed(&self, text: &str) -> Result<Vec<f32>, LlmError>

Generate an embedding vector from text. Read more
Source§

async fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>, LlmError>

Embed multiple texts in a single API call. Read more
Source§

fn supports_embeddings(&self) -> bool

Whether this provider supports embedding generation.
Source§

fn name(&self) -> &str

Provider name for logging and identification.
Source§

fn model_identifier(&self) -> &str

Model identifier string (e.g. gpt-4o-mini, claude-sonnet-5). Used by cost-estimation heuristics. Returns "" when not applicable.
Source§

fn effective_model_identifier(&self) -> &str

Model identifier that actually served the most recent dispatch. Read more
Source§

fn supports_structured_output(&self) -> bool

Whether this provider supports native structured output.
Source§

fn supports_vision(&self) -> bool

Whether this provider supports image input (vision).
Source§

fn supports_tool_use(&self) -> bool

Whether this provider supports native tool_use / function calling. Read more
Source§

async fn chat_with_tools( &self, messages: &[Message], tools: &[ToolDefinition], ) -> Result<ChatResponse, LlmError>

Send messages with tool definitions, returning a structured response. Read more
Source§

fn last_cache_usage(&self) -> Option<(u64, u64)>

Return the cache usage from the last API call, if available. Returns (cache_creation_tokens, cache_read_tokens).
Source§

fn last_usage(&self) -> Option<(u64, u64)>

Return token counts from the last API call, if available. Returns (input_tokens, output_tokens).
Source§

fn last_reasoning_tokens(&self) -> Option<u64>

Return reasoning tokens from the last API call, if the provider reports them. Read more
Source§

fn last_ttft_ms(&self) -> Option<u64>

Return the time-to-first-byte (milliseconds) of the last API call, if available. Read more
Source§

fn debug_request_json( &self, messages: &[Message], tools: &[ToolDefinition], stream: bool, ) -> Value

Return the request payload that will be sent to the provider, for debug dumps. Read more
Source§

fn take_compaction_summary(&self) -> Option<String>

Return the compaction summary from the most recent API call, if a server-side compaction occurred (Claude compact-2026-01-12 beta). Clears the stored value.
Source§

fn list_models(&self) -> Vec<String>

Return the list of model identifiers this provider can serve. Default: empty (provider does not advertise models).
Source§

async fn chat_typed<T>(&self, messages: &[Message]) -> Result<T, LlmError>
where T: DeserializeOwned + JsonSchema + 'static, Self: Sized,

Send messages and parse the response into a typed value T. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> LlmProviderDyn for T
where T: LlmProvider + Debug + Send + Sync + 'static,

Source§

fn context_window(&self) -> Option<usize>

Report the model’s context window size in tokens. None if unknown.
Source§

fn chat<'a>( &'a self, messages: &'a [Message], ) -> Pin<Box<dyn Future<Output = Result<String, LlmError>> + Send + 'a>>

Send messages to the LLM and return the assistant response. Read more
Source§

fn chat_stream<'a>( &'a self, messages: &'a [Message], ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamChunk, LlmError>> + Send>>, LlmError>> + Send + 'a>>

Send messages and return a stream of response chunks. Read more
Source§

fn supports_streaming(&self) -> bool

Whether this provider supports native streaming.
Source§

fn embed<'a>( &'a self, text: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, LlmError>> + Send + 'a>>

Generate an embedding vector from text. Read more
Source§

fn embed_batch<'a>( &'a self, texts: &'a [&'a str], ) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, LlmError>> + Send + 'a>>

Embed multiple texts in a single API call. Read more
Source§

fn supports_embeddings(&self) -> bool

Whether this provider supports embedding generation.
Source§

fn name(&self) -> &str

Provider name for logging and identification.
Source§

fn model_identifier(&self) -> &str

Model identifier string (e.g. gpt-4o-mini, claude-sonnet-5).
Source§

fn effective_model_identifier(&self) -> &str

Model identifier that actually served the most recent dispatch. See LlmProvider::effective_model_identifier for the full contract.
Source§

fn supports_vision(&self) -> bool

Whether this provider supports image input (vision).
Source§

fn supports_tool_use(&self) -> bool

Whether this provider supports native tool_use / function calling.
Source§

fn chat_with_tools<'a>( &'a self, messages: &'a [Message], tools: &'a [ToolDefinition], ) -> Pin<Box<dyn Future<Output = Result<ChatResponse, LlmError>> + Send + 'a>>

Send messages with tool definitions, returning a structured response. Read more
Source§

fn last_cache_usage(&self) -> Option<(u64, u64)>

Return the cache usage from the last API call, if available. Returns (cache_creation_tokens, cache_read_tokens).
Source§

fn last_usage(&self) -> Option<(u64, u64)>

Return token counts from the last API call, if available. Returns (input_tokens, output_tokens).
Source§

fn take_compaction_summary(&self) -> Option<String>

Return the compaction summary from the most recent API call, if available.
Source§

fn chat_with_extras<'a>( &'a self, messages: &'a [Message], ) -> Pin<Box<dyn Future<Output = Result<(String, ChatExtras), LlmError>> + Send + 'a>>

Send messages and return the assistant response together with per-call extras. Read more
Source§

fn debug_request_json( &self, messages: &[Message], tools: &[ToolDefinition], stream: bool, ) -> Value

Return the request payload that will be sent to the provider, for debug dumps.
Source§

fn list_models(&self) -> Vec<String>

Return the list of model identifiers this provider can serve.
Source§

fn supports_structured_output(&self) -> bool

Whether this provider supports native structured output.
Source§

fn last_reasoning_tokens(&self) -> Option<u64>

Return reasoning tokens from the last API call, if the provider reports them. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more