pub enum ResponseFormat {
JsonSchema {
schema: Value,
strict: bool,
name: Option<String>,
},
JsonObject,
}Expand description
Constraint on the model’s response shape. Distinct from tools —
tools are a side-channel for action invocation; response_format
constrains the primary text output to be parseable JSON, optionally
against a caller-supplied schema.
Provider mapping (handled in protocol.rs):
- OpenAI / Azure / OpenAI-compatible:
response_format: {type: "json_schema", json_schema: {schema, strict, name}}(or{type: "json_object"}for the looser variant). Strict mode rejects any deviation from the schema. - Google (Gemini):
response_mime_type: "application/json"plus optionalresponse_schema. - Anthropic: no native field as of early 2026 — the schema is
logged at
warnlevel and dropped. Callers needing schema-validated output on Claude should fall back to thetools+tool_choice="required"coercion idiom (which is what worked before this field landed).
JsonObject is the looser variant — tells the provider “emit valid
JSON, no schema check required”. Use when the schema is too dynamic
to spell out but the parse contract still matters.
Variants§
JsonSchema
JSON output validated against the provided schema. strict: true
asks the provider to reject any deviation; false makes the
schema a best-effort hint. name is OpenAI-specific (the
json_schema.name field, max 64 chars, alphanumerics + -_);
other providers ignore it.
JsonObject
Plain JSON-mode output — the provider emits valid JSON without schema enforcement.
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 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<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