#[non_exhaustive]pub enum OutputMode {
Auto,
Tool,
Native,
Prompted,
}Expand description
Controls how an agent’s output_schema is enforced.
§Strictness
Native is the only mode whose output is constrained
by the provider — the response is guaranteed to match the schema (on
providers that support it). Tool and
Prompted are best-effort: the schema is offered
to the model (as a tool or in the prompt) but the model is asked, not forced,
to honor it, so the agent re-prompts a bounded number of times and otherwise
validate the returned JSON before relying on it. The default
Auto is provider-aware: for a tool + schema agent it
routes to Tool only on providers whose native constraint would suppress
tool calls, and keeps guaranteed Native structured output on providers that
compose the two (e.g. OpenAI, Anthropic).
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Auto
Resolve at request time: OutputMode::Tool when the agent has an
output_schema and at least one function tool (and the tool choice
permits the output-tool call), otherwise OutputMode::Native. This is
the default and only changes behavior for the tool + schema case (which is
broken under Native on providers whose native constraint suppresses
tool calls).
Tool
Register the schema as a synthetic “output tool” the model calls to
finalize. No native structured-output constraint is sent, so the model can
freely call its other tools first. Best-effort: the model is instructed to
call the output tool but is not forced to, so validate the result.
(pydantic-ai ToolOutput.)
Native
Use the provider’s native structured output (format/response_format).
Constrains every turn, so the output is guaranteed to match the schema,
but may suppress tool calls on some providers (e.g. Ollama). (pydantic-ai
NativeOutput.)
Prompted
Inject the schema into the system prompt and return the model’s final text
verbatim. The caller parses it — the text is not guaranteed to be clean
JSON and may include prose or markdown fences, so extract/validate before
deserializing. Useful for weak/local models that lack reliable tool calling
or native structured output. (pydantic-ai PromptedOutput.)
Trait Implementations§
Source§impl Clone for OutputMode
impl Clone for OutputMode
Source§fn clone(&self) -> OutputMode
fn clone(&self) -> OutputMode
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OutputMode
impl Debug for OutputMode
Source§impl Default for OutputMode
impl Default for OutputMode
Source§fn default() -> OutputMode
fn default() -> OutputMode
Source§impl<'de> Deserialize<'de> for OutputMode
impl<'de> Deserialize<'de> for OutputMode
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for OutputMode
Source§impl PartialEq for OutputMode
impl PartialEq for OutputMode
Source§impl Serialize for OutputMode
impl Serialize for OutputMode
impl StructuralPartialEq for OutputMode
Auto Trait Implementations§
impl Freeze for OutputMode
impl RefUnwindSafe for OutputMode
impl Send for OutputMode
impl Sync for OutputMode
impl Unpin for OutputMode
impl UnsafeUnpin for OutputMode
impl UnwindSafe for OutputMode
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
fn clone_storage(&self) -> Box<dyn CloneDebuggableStorage>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
impl<T> DebuggableStorage for T
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more