#[non_exhaustive]pub enum ResponseFormat {
Free,
JsonObject,
JsonSchema {
name: String,
schema: Value,
},
}Expand description
Constrain the model’s terminal (non-tool-call) reply shape. Default = Free.
Each model adapter translates this to the provider’s native format on the wire:
- OpenAI / DeepSeek:
response_format: {type: "json_object"}forJsonObject;{type: "json_schema", json_schema: {name, schema, strict}}forJsonSchema. Providers that only supportjson_object(DeepSeek as of Dec 2025) degrade gracefully by injecting the schema into the system prompt instead. - Gemini:
generationConfig.responseMimeType = "application/json"plusgenerationConfig.responseSchema = <schema>forJsonSchema. - Anthropic: no native field — adapters synthesise a “structured_output”
tool with the schema, force
tool_choiceto it, and surface the tool’s args as the assistant text on response.
JsonSchema.schema is a serde_json::Value so callers can build it
however they like — hand-rolled, via schemars::schema_for!(T), or pulled
from a harness_loop::AgentLoop::run_typed<T>() derivation.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Free
Free-form text. The framework adds nothing to the request body.
JsonObject
“Reply with valid JSON of any shape.” Useful when the caller will run its own validation and doesn’t want to commit to a schema yet.
JsonSchema
“Reply with JSON matching this schema.” Adapters may need to sanitise
dialect-specific keys before emitting (Gemini rejects $ref, OpenAI
strict mode demands additionalProperties: false everywhere, …).
Trait Implementations§
Source§impl Clone for ResponseFormat
impl Clone for ResponseFormat
Source§fn clone(&self) -> ResponseFormat
fn clone(&self) -> ResponseFormat
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ResponseFormat
impl Debug for ResponseFormat
Source§impl Default for ResponseFormat
impl Default for ResponseFormat
Source§fn default() -> ResponseFormat
fn default() -> ResponseFormat
Returns the “default value” for a type. Read more
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>,
Deserialize this value from the given Serde deserializer. Read more
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,
Serialize this value into the given Serde serializer. Read more
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
Mutably borrows from an owned value. Read more