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) -> Self
pub fn new(name: impl Into<String>, schema: Value) -> Self
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) -> Self
pub const fn with_strict(self, strict: bool) -> Self
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<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::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 ==.