pub struct ResponseFormat {
pub json_schema: JsonSchemaSpec,
pub strict: bool,
pub strategy: OutputStrategy,
}Expand description
Structured-output directive attached to a ModelRequest.
strict requests the vendor’s strict-mode interpretation when
available (OpenAI). Codecs that cannot enforce strict mode
natively emit a LossyEncode warning.
strategy selects the dispatch shape (vendor-native channel /
forced tool call / prompted). Auto (the default) lets each
codec pick its preferred shape per auto_output_strategy(model)
at codec-construction time — see OutputStrategy.
Fields§
§json_schema: JsonSchemaSpecSchema the response must conform to.
strict: boolRequest strict-mode validation. Defaults to true —
callers explicitly opt out with false when they want
best-effort schema adherence (some Anthropic shim flows).
strategy: OutputStrategyDispatch shape — vendor-native, forced-tool, or prompted.
Defaults to OutputStrategy::Auto which lets the codec
pick per-vendor at construction time.
Implementations§
Source§impl ResponseFormat
impl ResponseFormat
Sourcepub fn strict(schema: JsonSchemaSpec) -> Self
pub fn strict(schema: JsonSchemaSpec) -> Self
Build a strict response format from the supplied schema.
strategy defaults to Auto; chain
Self::with_strategy to override.
Sourcepub fn best_effort(schema: JsonSchemaSpec) -> Self
pub fn best_effort(schema: JsonSchemaSpec) -> Self
Build a best-effort response format (no strict-mode
validation requested). strategy defaults to Auto.
Sourcepub const fn with_strategy(self, strategy: OutputStrategy) -> Self
pub const fn with_strategy(self, strategy: OutputStrategy) -> Self
Override the dispatch OutputStrategy. Auto means
“codec picks at construction time”; explicit Native /
Tool / Prompted overrides per-codec defaulting.
Sourcepub fn strict_preflight(&self) -> Result<(), StrictSchemaError>
pub fn strict_preflight(&self) -> Result<(), StrictSchemaError>
Validate the schema against the strict-mode constraints
shared across OpenAI (Chat + Responses) and Anthropic
native structured outputs. Returns the offending
field path on failure so codecs can attach an actionable
LossyEncode warning.
Constraints checked:
- every object schema declares
additionalProperties: false - every object schema’s
requiredlist contains every property defined inproperties(OpenAIstrict-mode requirement)
The check is a no-op when self.strict == false.
Trait Implementations§
Source§impl Clone for ResponseFormat
impl Clone for ResponseFormat
Source§fn clone(&self) -> ResponseFormat
fn clone(&self) -> ResponseFormat
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 ResponseFormat
impl Debug for ResponseFormat
Source§impl<'de> Deserialize<'de> for ResponseFormat
impl<'de> Deserialize<'de> for ResponseFormat
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>,
Source§impl PartialEq for ResponseFormat
impl PartialEq for ResponseFormat
Source§fn eq(&self, other: &ResponseFormat) -> bool
fn eq(&self, other: &ResponseFormat) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for ResponseFormat
impl Serialize for ResponseFormat
impl Eq for ResponseFormat
impl StructuralPartialEq for ResponseFormat
Auto Trait Implementations§
impl Freeze for ResponseFormat
impl RefUnwindSafe for ResponseFormat
impl Send for ResponseFormat
impl Sync for ResponseFormat
impl Unpin for ResponseFormat
impl UnsafeUnpin for ResponseFormat
impl UnwindSafe for ResponseFormat
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.