pub struct LlmOutcome {
pub ok: bool,
pub text: Option<String>,
pub failure: Option<LlmFailure>,
pub input_tokens: Option<u64>,
pub output_tokens: Option<u64>,
}Expand description
One element’s result, positionally matched to the prompt that produced it.
A struct rather than an enum because success and failure are not disjoint
here: a truncated or content-filtered completion is ok: false and still
carries usable text, and a caller that wants the partial answer should not
have to reach through an error arm to get it.
ok: true means the provider reported a natural stop — not merely that no
error was raised. A completion that returned cleanly but stopped on length
is ok: false with FailureReason::Truncated. That choice trades a class
of silent wrong-answer bugs for one honest data-loss risk, which is why the
failure arm keeps its text rather than discarding it.
The arms differ in more than a flag: text is always present on success and
nullable on failure, and the LlmFailure payload exists only on failure.
Fields§
§ok: boolThe provider reported a natural stop for this element.
text: Option<String>The completion text.
Always Some on the success arm. On the failure arm it is string | null:
Some — including Some("") — when the model produced text, and None
when it produced none at all. The two must not collapse, since telling
“empty because filtered” from “empty because the model said nothing” is
the distinction the ok rule exists to preserve.
failure: Option<LlmFailure>The failure payload. Some exactly when !ok.
input_tokens: Option<u64>Tokens the provider reported for the prompt. None means
indeterminate, not free — the provider reported nothing, or reported
something non-finite. Never Some(0) as a stand-in for “unknown”: a
throttled call may still have been billed, so a reconciler holds a
conservative reserve for None rather than releasing it.
Nullable on both arms: a provider can resolve successfully with no usage reported, so this cannot be confined to the failure arm.
output_tokens: Option<u64>Tokens the provider reported for the completion. Same
None-means-indeterminate rule as Self::input_tokens.
Implementations§
Source§impl LlmOutcome
impl LlmOutcome
Sourcepub fn success(text: impl Into<String>) -> Self
pub fn success(text: impl Into<String>) -> Self
A natural stop with the given text. Usage is left indeterminate; a provider that reports counts sets them explicitly.
Trait Implementations§
Source§impl Clone for LlmOutcome
impl Clone for LlmOutcome
Source§impl Debug for LlmOutcome
impl Debug for LlmOutcome
impl Eq for LlmOutcome
Source§impl PartialEq for LlmOutcome
impl PartialEq for LlmOutcome
impl StructuralPartialEq for LlmOutcome
Auto Trait Implementations§
impl Freeze for LlmOutcome
impl RefUnwindSafe for LlmOutcome
impl Send for LlmOutcome
impl Sync for LlmOutcome
impl Unpin for LlmOutcome
impl UnsafeUnpin for LlmOutcome
impl UnwindSafe for LlmOutcome
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.