pub struct ResponseFormat {
pub name: String,
pub schema: Value,
pub strict: bool,
}Expand description
Requests that the model constrain its final answer to a JSON Schema.
This is the wire-level description of a structured-output request. The runtime maps it to each provider’s native capability:
OpenAI/ Gemini: native JSON-mode / structured-outputs (response_format/responseSchema).- Anthropic: tool-forcing fallback — the runtime injects a single
“respond” tool whose
input_schemaisschemaand forces the model to call it.
The runtime validates the model’s final output against schema
and, on mismatch, bounded-re-prompts before failing with a typed error.
Fields§
§name: StringStable identifier for the schema. Surfaced to providers that require a
name (OpenAI json_schema.name, the Anthropic fallback tool name).
schema: ValueThe JSON Schema the final assistant output must satisfy.
This is a raw JSON Schema document (an object), not a Rust type. Callers
that derive schemas from Rust types can plug in schemars upstream and
pass the resulting document here.
strict: boolWhether the provider should enforce strict schema adherence when it
supports a strict mode (OpenAI strict: true). Has no effect on
providers without a strict mode.
Implementations§
Source§impl ResponseFormat
impl ResponseFormat
Sourcepub fn new(name: impl Into<String>, schema: Value) -> ResponseFormat
pub fn new(name: impl Into<String>, schema: Value) -> ResponseFormat
Create a response format from a schema name and a JSON Schema document.
Defaults to strict = true so providers with a strict mode enforce the
schema rather than treating it as a hint.
Sourcepub const fn with_strict(self, strict: bool) -> ResponseFormat
pub const fn with_strict(self, strict: bool) -> ResponseFormat
Set whether strict schema adherence is requested.
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<ResponseFormat, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ResponseFormat, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for ResponseFormat
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
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.