1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! How an agent enforces its `output_schema` (see issue #1928).
//!
//! Mirrors pydantic-ai's output modes. When an agent has both tools and an
//! `output_schema`, applying the provider's native structured-output constraint
//! (`format`/`response_format`) on every turn suppresses tool calls — the model
//! is forced to emit schema JSON instead of using its tools. `OutputMode` lets
//! the structured output be produced as a *tool call* the model makes after
//! using its tools, which composes correctly.
use ;
/// Controls how an agent's `output_schema` is enforced.
///
/// # Strictness
///
/// [`Native`](OutputMode::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`](OutputMode::Tool) and
/// [`Prompted`](OutputMode::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`](OutputMode::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).